MCPcopy Create free account
hub / github.com/codecombat/codecombat / fetchData

Function fetchData

app/core/store/modules/schoolAdminDashboard.js:180–210  ·  view source on GitHub ↗
({ state, dispatch, commit }, { componentName, options = {} })

Source from the content-addressed store, hash-verified

178 // options = { data: {} }
179 // options.data = {} -> contains specific properties to fetch (or `project`) for an object as a string, eg: {users: 'firstName,lastName,email', levelSessions: 'state.complete,level,creator,changed'}
180 async fetchData ({ state, dispatch, commit }, { componentName, options = {} }) {
181 if (!state.schoolAdminId) {
182 console.error('Error in fetching data: schoolAdminId is not set')
183 noty({ text: 'Error in fetching data', type: 'error', layout: 'center', timeout: 2000 })
184 return
185 }
186
187 commit('startLoading')
188 commit('setComponentName', componentName)
189 try {
190 dispatch('fetchDataCurriculumGuide') // loaded async (doesnt block loading bar)
191 if (componentName === COMPONENT_NAMES.SCHOOL_ADMIN_LICENSES) {
192 // SchoolAdmin licenses page
193 await dispatch('fetchDataMyLicenses', options)
194 } else if (componentName === COMPONENT_NAMES.MY_SCHOOLS) {
195 // My Schools page
196 await dispatch('fetchDataMySchools', options)
197 } else {
198 // Administrated teachers' pages
199 await dispatch('fetchDataAdministratedTeachers', options)
200 }
201 } catch (err) {
202 console.error('Error in fetching data:', err)
203 noty({ text: 'Error in fetching data', type: 'error', layout: 'topCenter', timeout: 2000 })
204 } finally {
205 commit('stopLoading')
206 if (options.loadedEventName) { // should be set for tracking the loaded event for dashboard pages
207 window.tracker?.trackEvent(options.loadedEventName, { category: 'SchoolAdmin' })
208 }
209 }
210 },
211
212 // My Schools page
213 async fetchDataMySchools ({ state, dispatch, getters }, options = {}) {

Callers

nothing calls this directly

Calls 3

dispatchFunction · 0.85
errorMethod · 0.45
trackEventMethod · 0.45

Tested by

no test coverage detected