|
| 1 | +import { createReducer } from '@reduxjs/toolkit'; |
1 | 2 | import { Reducer } from 'redux';
|
2 |
| - |
3 | 3 | import {
|
4 |
| - REMOTE_EXEC_UPDATE_DEVICES, |
5 |
| - REMOTE_EXEC_UPDATE_SESSION |
6 |
| -} from '../../../features/remoteExecution/RemoteExecutionTypes'; |
| 4 | + remoteExecUpdateDevices, |
| 5 | + remoteExecUpdateSession |
| 6 | +} from 'src/features/remoteExecution/RemoteExecutionActions'; |
| 7 | + |
7 | 8 | import { SourceActionType } from '../../utils/ActionsHelper';
|
8 |
| -import { defaultSession } from '../ApplicationTypes'; |
9 |
| -import { LOG_OUT } from '../types/CommonsTypes'; |
| 9 | +import { logOut } from '../actions/CommonsActions'; |
10 | 10 | import {
|
11 |
| - REMOVE_GITHUB_OCTOKIT_OBJECT_AND_ACCESS_TOKEN, |
12 |
| - SessionState, |
13 |
| - SET_ADMIN_PANEL_COURSE_REGISTRATIONS, |
14 |
| - SET_ASSESSMENT_CONFIGURATIONS, |
15 |
| - SET_CONFIGURABLE_NOTIFICATION_CONFIGS, |
16 |
| - SET_COURSE_CONFIGURATION, |
17 |
| - SET_COURSE_REGISTRATION, |
18 |
| - SET_GITHUB_ACCESS_TOKEN, |
19 |
| - SET_GITHUB_OCTOKIT_OBJECT, |
20 |
| - SET_GOOGLE_USER, |
21 |
| - SET_NOTIFICATION_CONFIGS, |
22 |
| - SET_TOKENS, |
23 |
| - SET_USER, |
24 |
| - UPDATE_ASSESSMENT, |
25 |
| - UPDATE_ASSESSMENT_OVERVIEWS, |
26 |
| - UPDATE_GRADING, |
27 |
| - UPDATE_GRADING_OVERVIEWS, |
28 |
| - UPDATE_NOTIFICATIONS, |
29 |
| - UPDATE_STUDENTS, |
30 |
| - UPDATE_TEAM_FORMATION_OVERVIEW, |
31 |
| - UPDATE_TEAM_FORMATION_OVERVIEWS, |
32 |
| - UPDATE_TOTAL_XP |
33 |
| -} from '../types/SessionTypes'; |
| 11 | + removeGitHubOctokitObjectAndAccessToken, |
| 12 | + setAdminPanelCourseRegistrations, |
| 13 | + setAssessmentConfigurations, |
| 14 | + setConfigurableNotificationConfigs, |
| 15 | + setCourseConfiguration, |
| 16 | + setCourseRegistration, |
| 17 | + setGitHubAccessToken, |
| 18 | + setGitHubOctokitObject, |
| 19 | + setGoogleUser, |
| 20 | + setNotificationConfigs, |
| 21 | + setTokens, |
| 22 | + setUser, |
| 23 | + updateAssessment, |
| 24 | + updateAssessmentOverviews, |
| 25 | + updateGrading, |
| 26 | + updateGradingOverviews, |
| 27 | + updateNotifications, |
| 28 | + updateStudents, |
| 29 | + updateTeamFormationOverview, |
| 30 | + updateTeamFormationOverviews, |
| 31 | + updateTotalXp |
| 32 | +} from '../actions/SessionActions'; |
| 33 | +import { defaultSession } from '../ApplicationTypes'; |
| 34 | +import { SessionState } from '../types/SessionTypes'; |
34 | 35 |
|
35 | 36 | export const SessionsReducer: Reducer<SessionState, SourceActionType> = (
|
36 | 37 | state = defaultSession,
|
37 | 38 | action
|
38 | 39 | ) => {
|
39 |
| - switch (action.type) { |
40 |
| - case LOG_OUT: |
41 |
| - return defaultSession; |
42 |
| - case SET_GITHUB_OCTOKIT_OBJECT: |
43 |
| - return { |
44 |
| - ...state, |
45 |
| - githubOctokitObject: { octokit: action.payload } |
46 |
| - }; |
47 |
| - case SET_GITHUB_ACCESS_TOKEN: |
48 |
| - return { |
49 |
| - ...state, |
50 |
| - githubAccessToken: action.payload |
51 |
| - }; |
52 |
| - case SET_GOOGLE_USER: |
53 |
| - return { |
54 |
| - ...state, |
55 |
| - googleUser: action.payload |
56 |
| - }; |
57 |
| - case SET_TOKENS: |
58 |
| - return { |
59 |
| - ...state, |
60 |
| - ...action.payload |
61 |
| - }; |
62 |
| - case SET_USER: |
63 |
| - return { |
64 |
| - ...state, |
65 |
| - ...action.payload |
66 |
| - }; |
67 |
| - case SET_COURSE_CONFIGURATION: |
68 |
| - return { |
69 |
| - ...state, |
70 |
| - ...action.payload |
71 |
| - }; |
72 |
| - case SET_COURSE_REGISTRATION: |
73 |
| - return { |
74 |
| - ...state, |
75 |
| - ...action.payload |
76 |
| - }; |
77 |
| - case SET_ASSESSMENT_CONFIGURATIONS: |
78 |
| - return { |
79 |
| - ...state, |
80 |
| - assessmentConfigurations: action.payload |
81 |
| - }; |
82 |
| - case SET_NOTIFICATION_CONFIGS: |
83 |
| - return { |
84 |
| - ...state, |
85 |
| - notificationConfigs: action.payload |
86 |
| - }; |
87 |
| - case SET_CONFIGURABLE_NOTIFICATION_CONFIGS: |
88 |
| - return { |
89 |
| - ...state, |
90 |
| - configurableNotificationConfigs: action.payload |
91 |
| - }; |
92 |
| - case SET_ADMIN_PANEL_COURSE_REGISTRATIONS: |
93 |
| - return { |
94 |
| - ...state, |
95 |
| - userCourseRegistrations: action.payload |
96 |
| - }; |
97 |
| - case UPDATE_ASSESSMENT: |
98 |
| - const newAssessments = new Map(state.assessments); |
99 |
| - newAssessments.set(action.payload.id, action.payload); |
100 |
| - return { |
101 |
| - ...state, |
102 |
| - assessments: newAssessments |
103 |
| - }; |
104 |
| - case UPDATE_ASSESSMENT_OVERVIEWS: |
105 |
| - return { |
106 |
| - ...state, |
107 |
| - assessmentOverviews: action.payload |
108 |
| - }; |
109 |
| - case UPDATE_TOTAL_XP: |
110 |
| - return { ...state, xp: action.payload }; |
111 |
| - case UPDATE_GRADING: |
112 |
| - const newGradings = new Map(state.gradings); |
113 |
| - newGradings.set(action.payload.submissionId, action.payload.grading); |
114 |
| - return { |
115 |
| - ...state, |
116 |
| - gradings: newGradings |
117 |
| - }; |
118 |
| - case UPDATE_GRADING_OVERVIEWS: |
119 |
| - return { |
120 |
| - ...state, |
121 |
| - gradingOverviews: action.payload |
122 |
| - }; |
123 |
| - case UPDATE_NOTIFICATIONS: |
124 |
| - return { |
125 |
| - ...state, |
126 |
| - notifications: action.payload |
127 |
| - }; |
128 |
| - case UPDATE_STUDENTS: |
129 |
| - return { |
130 |
| - ...state, |
131 |
| - students: action.payload |
132 |
| - }; |
133 |
| - case UPDATE_TEAM_FORMATION_OVERVIEWS: |
134 |
| - return { |
135 |
| - ...state, |
136 |
| - teamFormationOverviews: action.payload |
137 |
| - }; |
138 |
| - case UPDATE_TEAM_FORMATION_OVERVIEW: |
139 |
| - return { |
140 |
| - ...state, |
141 |
| - teamFormationOverview: action.payload |
142 |
| - }; |
143 |
| - case REMOTE_EXEC_UPDATE_DEVICES: |
144 |
| - return { |
145 |
| - ...state, |
146 |
| - remoteExecutionDevices: action.payload |
147 |
| - }; |
148 |
| - case REMOTE_EXEC_UPDATE_SESSION: |
149 |
| - return { |
150 |
| - ...state, |
151 |
| - remoteExecutionSession: action.payload |
152 |
| - }; |
153 |
| - case REMOVE_GITHUB_OCTOKIT_OBJECT_AND_ACCESS_TOKEN: |
154 |
| - return { |
155 |
| - ...state, |
156 |
| - githubOctokitObject: { octokit: undefined }, |
157 |
| - githubAccessToken: undefined |
158 |
| - }; |
159 |
| - default: |
160 |
| - return state; |
161 |
| - } |
| 40 | + state = newSessionsReducer(state, action); |
| 41 | + return state; |
162 | 42 | };
|
| 43 | + |
| 44 | +const newSessionsReducer = createReducer(defaultSession, builder => { |
| 45 | + builder |
| 46 | + .addCase(logOut, () => { |
| 47 | + return defaultSession; |
| 48 | + }) |
| 49 | + .addCase(setGitHubOctokitObject, (state, action) => { |
| 50 | + state.githubOctokitObject = { octokit: action.payload }; |
| 51 | + }) |
| 52 | + .addCase(setGitHubAccessToken, (state, action) => { |
| 53 | + state.githubAccessToken = action.payload; |
| 54 | + }) |
| 55 | + .addCase(setGoogleUser, (state, action) => { |
| 56 | + state.googleUser = action.payload; |
| 57 | + }) |
| 58 | + .addCase(setTokens, (state, action) => { |
| 59 | + return { ...state, ...action.payload }; |
| 60 | + }) |
| 61 | + .addCase(setUser, (state, action) => { |
| 62 | + return { ...state, ...action.payload }; |
| 63 | + }) |
| 64 | + .addCase(setCourseConfiguration, (state, action) => { |
| 65 | + return { ...state, ...action.payload }; |
| 66 | + }) |
| 67 | + .addCase(setCourseRegistration, (state, action) => { |
| 68 | + return { ...state, ...action.payload }; |
| 69 | + }) |
| 70 | + .addCase(setAssessmentConfigurations, (state, action) => { |
| 71 | + state.assessmentConfigurations = action.payload; |
| 72 | + }) |
| 73 | + .addCase(setNotificationConfigs, (state, action) => { |
| 74 | + state.notificationConfigs = action.payload; |
| 75 | + }) |
| 76 | + .addCase(setConfigurableNotificationConfigs, (state, action) => { |
| 77 | + state.configurableNotificationConfigs = action.payload; |
| 78 | + }) |
| 79 | + .addCase(setAdminPanelCourseRegistrations, (state, action) => { |
| 80 | + state.userCourseRegistrations = action.payload; |
| 81 | + }) |
| 82 | + .addCase(updateAssessment, (state, action) => { |
| 83 | + state.assessments[action.payload.id] = action.payload; |
| 84 | + }) |
| 85 | + .addCase(updateAssessmentOverviews, (state, action) => { |
| 86 | + state.assessmentOverviews = action.payload; |
| 87 | + }) |
| 88 | + .addCase(updateTotalXp, (state, action) => { |
| 89 | + state.xp = action.payload; |
| 90 | + }) |
| 91 | + .addCase(updateGrading, (state, action) => { |
| 92 | + state.gradings[action.payload.submissionId] = action.payload.grading; |
| 93 | + }) |
| 94 | + .addCase(updateGradingOverviews, (state, action) => { |
| 95 | + state.gradingOverviews = action.payload; |
| 96 | + }) |
| 97 | + .addCase(updateNotifications, (state, action) => { |
| 98 | + state.notifications = action.payload; |
| 99 | + }) |
| 100 | + .addCase(updateStudents, (state, action) => { |
| 101 | + state.students = action.payload; |
| 102 | + }) |
| 103 | + .addCase(updateTeamFormationOverviews, (state, action) => { |
| 104 | + state.teamFormationOverviews = action.payload; |
| 105 | + }) |
| 106 | + .addCase(updateTeamFormationOverview, (state, action) => { |
| 107 | + state.teamFormationOverview = action.payload; |
| 108 | + }) |
| 109 | + .addCase(remoteExecUpdateDevices, (state, action) => { |
| 110 | + state.remoteExecutionDevices = action.payload; |
| 111 | + }) |
| 112 | + .addCase(remoteExecUpdateSession, (state, action) => { |
| 113 | + state.remoteExecutionSession = action.payload; |
| 114 | + }) |
| 115 | + .addCase(removeGitHubOctokitObjectAndAccessToken, (state, action) => { |
| 116 | + state.githubOctokitObject = { octokit: undefined }; |
| 117 | + state.githubAccessToken = undefined; |
| 118 | + }); |
| 119 | +}); |
0 commit comments