Skip to content

Commit 20164e9

Browse files
committed
refactor: make some vars non-nullable
1 parent 2e9a608 commit 20164e9

File tree

12 files changed

+21
-21
lines changed

12 files changed

+21
-21
lines changed

website/src/views/components/module-info/LessonTimetable.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const SemesterLessonTimetable: FC<{ semesterData?: SemesterData }> = ({ semester
3232
<Timetable
3333
lessons={arrangedLessons}
3434
onModifyCell={(lesson: Lesson) => history.push(venuePage(lesson.venue))}
35+
customisedModules={[]}
3536
/>
3637
);
3738
};

website/src/views/settings/SettingsContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const SettingsContainer: React.FC<Props> = ({
129129
</p>
130130

131131
<div className={styles.preview}>
132-
<Timetable lessons={previewTimetable} />
132+
<Timetable lessons={previewTimetable} customisedModules={[]} />
133133
</div>
134134

135135
<div>

website/src/views/tetris/TetrisGame.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function renderPiece(tiles: Board) {
101101
hoverLesson={null}
102102
onModifyCell={noop}
103103
onCellHover={noop}
104+
customisedModules={[]}
104105
/>
105106
);
106107
}
@@ -407,7 +408,7 @@ export default class TetrisGame extends PureComponent<Props, State> {
407408

408409
<div className={styles.game}>
409410
{this.renderOverlay()}
410-
<Timetable lessons={lessons} isVerticalOrientation />
411+
<Timetable lessons={lessons} isVerticalOrientation customisedModules={[]} />
411412
</div>
412413

413414
<div className={styles.sidebar}>

website/src/views/timetable/Timetable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Props = TimerData & {
3030
showTitle?: boolean;
3131
onModifyCell?: OnModifyCell;
3232
highlightPeriod?: TimePeriod;
33-
customisedModules?: ModuleCode[];
33+
customisedModules: ModuleCode[];
3434
};
3535

3636
type State = {

website/src/views/timetable/TimetableCell.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ function make(additionalProps: Partial<Props> = {}) {
3838
return {
3939
onClick,
4040
onHover: props.onHover,
41-
wrapper: shallow(<TimetableCell onClick={onClick} lesson={DEFAULT_LESSON} {...props} />),
41+
wrapper: shallow(
42+
<TimetableCell onClick={onClick} lesson={DEFAULT_LESSON} {...props} customisedModules={[]} />,
43+
),
4244
};
4345
}
4446

website/src/views/timetable/TimetableCell.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Props = {
2626
onClick?: (position: ClientRect) => void;
2727
hoverLesson?: HoverLesson | null;
2828
transparent: boolean;
29-
customisedModules?: ModuleCode[];
29+
customisedModules: ModuleCode[];
3030
};
3131

3232
const lessonDateFormat = 'MMM dd';
@@ -87,7 +87,8 @@ function formatWeekRange(weekRange: WeekRange) {
8787
* might explore other representations e.g. grouped lessons
8888
*/
8989
const TimetableCell: React.FC<Props> = (props) => {
90-
const { lesson, showTitle, onClick, onHover, hoverLesson, transparent } = props;
90+
const { lesson, showTitle, onClick, onHover, hoverLesson, transparent, customisedModules } =
91+
props;
9192

9293
const moduleName = showTitle ? `${lesson.moduleCode} ${lesson.title}` : lesson.moduleCode;
9394
const Cell = props.onClick ? 'button' : 'div';
@@ -134,9 +135,7 @@ const TimetableCell: React.FC<Props> = (props) => {
134135
<div className={styles.cellContainer}>
135136
<div className={styles.moduleName}>
136137
{moduleName}
137-
{props.customisedModules && props.customisedModules.includes(lesson.moduleCode)
138-
? '*'
139-
: null}
138+
{customisedModules.includes(lesson.moduleCode) && '*'}
140139
</div>
141140
<div>
142141
{LESSON_TYPE_ABBREV[lesson.lessonType]} [{lesson.classNo}]

website/src/views/timetable/TimetableContent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ class TimetableContent extends React.Component<Props, State> {
258258
readOnly={this.props.readOnly}
259259
tombstone={tombstone}
260260
resetTombstone={this.resetTombstone}
261+
customisedModules={this.props.customisedModules}
261262
/>
262263
);
263264

@@ -339,7 +340,7 @@ class TimetableContent extends React.Component<Props, State> {
339340
timetableLesson.classNo === lesson.classNo &&
340341
timetableLesson.lessonType === lesson.lessonType,
341342
).length > 0;
342-
const modifiableLesson: Lesson & { isActive?: boolean; isAvailable?: boolean } = {
343+
const modifiableLesson: Lesson & { isActive: boolean; isAvailable: boolean } = {
343344
...lesson,
344345
// Inject module code in
345346
moduleCode: this.props.customiseModule,

website/src/views/timetable/TimetableDay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Props = {
2626
onCellHover: OnHoverCell;
2727
onModifyCell?: OnModifyCell;
2828
highlightPeriod?: TimePeriod;
29-
customisedModules?: ModuleCode[];
29+
customisedModules: ModuleCode[];
3030
};
3131

3232
// Height of timetable per hour in vertical mode

website/src/views/timetable/TimetableModuleTable.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function make(props: Partial<Props> = {}) {
3535
resetTombstone={resetTombstone}
3636
customiseLesson={customiseLesson}
3737
customiseModule=""
38+
customisedModules={[]}
3839
addCustomModule={addCustomModule}
3940
removeCustomModule={removeCustomModule}
4041
{...props}

website/src/views/timetable/TimetableModulesTable.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ export const TimetableModulesTableComponent: React.FC<Props> = (props) => {
7070
type="button"
7171
className={classnames('btn btn-outline-secondary btn-svg', styles.moduleAction)}
7272
aria-label={removeBtnLabel}
73-
onClick={() => {
74-
props.customiseLesson(semester, '');
75-
}}
73+
onClick={() => props.customiseLesson(semester, '')}
7674
>
7775
<Check className={styles.actionIcon} />
7876
</button>
@@ -118,12 +116,8 @@ export const TimetableModulesTableComponent: React.FC<Props> = (props) => {
118116
type="button"
119117
className={classnames('btn btn-outline-secondary btn-svg', styles.moduleAction)}
120118
aria-label={customBtnLabel}
121-
disabled={
122-
props.customiseModule !== '' && props.customiseModule !== module.moduleCode
123-
}
124-
hidden={
125-
props.customiseModule !== '' && props.customiseModule !== module.moduleCode
126-
}
119+
disabled={!!props.customiseModule && props.customiseModule !== module.moduleCode}
120+
hidden={!!props.customiseModule && props.customiseModule !== module.moduleCode}
127121
onClick={() => {
128122
// TODO: add modal for warning
129123
props.addCustomModule(semester, module.moduleCode);

0 commit comments

Comments
 (0)