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

Function fetchDataByComponent

app/core/store/modules/teacherDashboard.js:13–73  ·  view source on GitHub ↗
({ dispatch, state, commit }, { componentName, options })

Source from the content-addressed store, hash-verified

11}
12
13async function fetchDataByComponent ({ dispatch, state, commit }, { componentName, options }) {
14 try {
15 const componentActionMap = {
16 [COMPONENT_NAMES.MY_CLASSES_ALL]: {
17 preFetch: async () => dispatch('fetchDataAllClasses', options),
18 lazy: () => dispatch('fetchDataAllClassesAsync', options),
19 },
20 [COMPONENT_NAMES.MY_CLASSES_SINGLE]: {
21 preFetch: async () => dispatch('fetchDataSingleClass', options),
22 lazy: () => dispatch('fetchDataSingleClassAsync', options),
23 },
24 [COMPONENT_NAMES.STUDENT_PROJECTS]: {
25 preFetch: async () => dispatch('fetchDataStudentProjects', options),
26 lazy: () => dispatch('fetchDataStudentProjectsAsync', options),
27 },
28 [COMPONENT_NAMES.MY_LICENSES]: {
29 preFetch: async () => dispatch('fetchDataMyLicenses', options),
30 lazy: () => dispatch('fetchDataMyLicensesAsync', options),
31 },
32 [COMPONENT_NAMES.RESOURCE_HUB]: {
33 lazy: () => dispatch('fetchDataResourceHubAsync', options),
34 },
35 [COMPONENT_NAMES.PD]: {
36 preFetch: async () => dispatch('fetchDataPDAsync', options),
37 },
38 [COMPONENT_NAMES.CURRICULUM_GUIDE]: {
39 preFetch: async () => dispatch('fetchDataCurriculumGuideAsync', options),
40 },
41 [COMPONENT_NAMES.STUDENT_ASSESSMENTS]: {
42 preFetch: async () => dispatch('fetchDataStudentAssessments', options),
43 lazy: () => dispatch('fetchDataStudentAssessmentsAsync', options),
44 },
45 [COMPONENT_NAMES.APCSP]: {
46 // nothing to fetch for APCSP page for now
47 },
48 }
49 const methods = componentActionMap[componentName]
50 if (methods) {
51 const fetchPromises = []
52 fetchPromises.push(dispatch('classrooms/fetchClassroomsForTeacher', { teacherId: state.teacherId }, { root: true }))
53 if (methods.preFetch) {
54 fetchPromises.push(methods.preFetch())
55 }
56 await Promise.all(fetchPromises)
57 if (methods.lazy) {
58 methods.lazy().catch(console.error)
59 }
60 } else {
61 console.error(`Unknown componentName: ${componentName}`)
62 }
63 } catch (err) {
64 console.error('Error in fetching data:', err)
65 noty({ text: 'Error in fetching data', type: 'error', layout: 'topCenter', timeout: 2000 })
66 } finally {
67 commit('stopLoading')
68 dispatch('classrooms/setMostRecentClassroomId', state.classroomId, { root: true })
69 if (options.loadedEventName) { // should be set for tracking the loaded event for dashboard pages
70 window.tracker?.trackEvent(options.loadedEventName, { category: state.trackCategory })

Callers 1

fetchDataFunction · 0.85

Calls 3

dispatchFunction · 0.85
errorMethod · 0.45
trackEventMethod · 0.45

Tested by

no test coverage detected