Skip to content

Commit 6aae1ec

Browse files
committed
timetables: add customisedModules prop when migrating to V2 schema
1 parent 4ce23c1 commit 6aae1ec

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

website/src/reducers/timetables.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ describe('redux schema migration', () => {
260260
hidden: {},
261261
academicYear: '2022/2023',
262262
archive: {},
263-
customisedModules: {},
264263
_persist: {
265264
version: 1,
266265
rehydrated: false,
@@ -285,7 +284,10 @@ describe('redux schema migration', () => {
285284
hidden: {},
286285
academicYear: '2022/2023',
287286
archive: {},
288-
customisedModules: {},
287+
customisedModules: {
288+
[1]: [],
289+
[2]: [],
290+
},
289291
_persist: {
290292
version: 1, // version kept the same because the framework does not support it in unit tests
291293
rehydrated: false,

website/src/reducers/timetables.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createMigrate, PersistedState } from 'redux-persist';
55
import { PersistConfig } from 'storage/persistReducer';
66
import { ModuleCode } from 'types/modules';
77
import { ModuleLessonConfig, SemTimetableConfig, TimetableConfig } from 'types/timetables';
8-
import { ColorMapping, TimetablesState } from 'types/reducers';
8+
import { ColorMapping, CustomisedModulesMap, TimetablesState } from 'types/reducers';
99

1010
import config from 'config';
1111
import {
@@ -35,8 +35,11 @@ export function migrateV1toV2(
3535
): TimetablesState & PersistedState {
3636
const newLessons: TimetableConfig = {};
3737
const oldLessons = oldState.lessons;
38+
const newCustomisedModules: CustomisedModulesMap = {};
3839

3940
Object.entries(oldLessons).forEach(([semester, modules]) => {
41+
newCustomisedModules[semester] = [];
42+
4043
Object.entries(modules).forEach(([moduleCode, lessons]) => {
4144
const newSemester: { [moduleCode: string]: { [lessonType: string]: string[] } } = {
4245
[moduleCode]: {},
@@ -56,6 +59,7 @@ export function migrateV1toV2(
5659
return {
5760
...oldState,
5861
lessons: newLessons,
62+
customisedModules: newCustomisedModules,
5963
};
6064
}
6165

0 commit comments

Comments
 (0)