From d28ce08d042c063eeda4992fa1531c514180a73b Mon Sep 17 00:00:00 2001 From: Zhao Wei Liew Date: Fri, 4 Aug 2023 11:01:06 +0800 Subject: [PATCH] fix(timetable): initialize default objects and arrays if undefined --- website/src/reducers/timetables.ts | 5 ++++- website/src/views/timetable/TimetableContent.tsx | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/website/src/reducers/timetables.ts b/website/src/reducers/timetables.ts index d56be22b665..350c1de94e8 100644 --- a/website/src/reducers/timetables.ts +++ b/website/src/reducers/timetables.ts @@ -289,8 +289,11 @@ function timetables( draft.lessons[semester] = semTimetable(draft.lessons[semester], action); draft.colors[semester] = semColors(state.colors[semester], action); draft.hidden[semester] = semHiddenModules(state.hidden[semester], action); + if (!draft.customisedModules) { + draft.customisedModules = {}; + } draft.customisedModules[semester] = customisedModules( - state.customisedModules[semester], + state.customisedModules?.[semester], action, ); }); diff --git a/website/src/views/timetable/TimetableContent.tsx b/website/src/views/timetable/TimetableContent.tsx index f6284db9635..a74b7d29c25 100644 --- a/website/src/views/timetable/TimetableContent.tsx +++ b/website/src/views/timetable/TimetableContent.tsx @@ -517,7 +517,7 @@ function mapStateToProps(state: StoreState, ownProps: OwnProps) { modules, activeLesson: state.app.activeLesson, customiseModule: state.app.customiseModule, - customisedModules: state.timetables.customisedModules[semester], + customisedModules: state.timetables.customisedModules?.[semester] ?? [], timetableOrientation: state.theme.timetableOrientation, showTitle: state.theme.showTitle, hiddenInTimetable,