Skip to content

Commit 2bd8d93

Browse files
shanwpftaneliang
authored andcommitted
Display module title in timetable cell (#709)
* Add option to display module titles in timetable cells * Use btn-outline-secondary when title button is disabled * Use text icon for title button * Fix first theme colour not displaying on timetable * Hide title button in vertical mode
1 parent 174627e commit 2bd8d93

File tree

14 files changed

+100
-16
lines changed

14 files changed

+100
-16
lines changed

www/src/js/actions/theme.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ export function toggleTimetableOrientation(): FSA {
2424
payload: null,
2525
};
2626
}
27+
28+
export const TOGGLE_TITLE_DISPLAY: string = 'TOGGLE_TITLE_DISPLAY';
29+
export function toggleTitleDisplay(): FSA {
30+
return {
31+
type: TOGGLE_TITLE_DISPLAY,
32+
payload: null,
33+
};
34+
}

www/src/js/reducers/index.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const exportData: ExportData = {
3232
theme: {
3333
id: 'google',
3434
timetableOrientation: VERTICAL,
35+
showTitle: true,
3536
},
3637
settings: {
3738
mode: 'DARK',
@@ -78,5 +79,6 @@ test('reducers should set export data state', () => {
7879
expect(state.theme).toEqual({
7980
id: 'google',
8081
timetableOrientation: VERTICAL,
82+
showTitle: true,
8183
});
8284
});

www/src/js/reducers/theme.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import type { ColorMapping, ThemeState } from 'types/reducers';
44
import type { Theme } from 'types/settings';
55

66
import { SET_EXPORTED_DATA } from 'actions/export';
7-
import { SELECT_THEME, CYCLE_THEME, TOGGLE_TIMETABLE_ORIENTATION } from 'actions/theme';
7+
import {
8+
SELECT_THEME,
9+
CYCLE_THEME,
10+
TOGGLE_TIMETABLE_ORIENTATION,
11+
TOGGLE_TITLE_DISPLAY,
12+
} from 'actions/theme';
813
import themes from 'data/themes.json';
914
import { VERTICAL, HORIZONTAL } from 'types/reducers';
1015

@@ -14,6 +19,7 @@ export const defaultThemeState: ThemeState = {
1419
id: 'eighties',
1520
colors: defaultColorsState,
1621
timetableOrientation: HORIZONTAL,
22+
showTitle: false,
1723
};
1824
export const themeIds = themes.map((obj: Theme) => obj.id);
1925

@@ -39,6 +45,11 @@ function theme(state: ThemeState = defaultThemeState, action: FSA): ThemeState {
3945
};
4046
case SET_EXPORTED_DATA:
4147
return action.payload.theme;
48+
case TOGGLE_TITLE_DISPLAY:
49+
return {
50+
...state,
51+
showTitle: !state.showTitle,
52+
};
4253
default:
4354
return state;
4455
}

www/src/js/types/reducers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const HORIZONTAL: TimetableOrientation = 'HORIZONTAL';
7373
export type ThemeState = {
7474
+id: string,
7575
+timetableOrientation: TimetableOrientation,
76+
+showTitle: boolean,
7677
};
7778

7879
/* settings */

www/src/js/views/components/icons/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Search from 'react-feather/dist/icons/search';
3131
import Sidebar from 'react-feather/dist/icons/sidebar';
3232
import Twitter from 'react-feather/dist/icons/twitter';
3333
import Trash2 from 'react-feather/dist/icons/trash-2';
34+
import Type from 'react-feather/dist/icons/type';
3435

3536
export {
3637
AlertTriangle,
@@ -64,4 +65,5 @@ export {
6465
Sidebar,
6566
Twitter,
6667
Trash2,
68+
Type,
6769
};

www/src/js/views/timetable/Timetable.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Props = {
2121
lessons: TimetableArrangement,
2222
isVerticalOrientation: boolean,
2323
isScrolledHorizontally: boolean,
24+
showTitle: boolean,
2425
onModifyCell: Function,
2526
};
2627

@@ -31,6 +32,7 @@ class Timetable extends PureComponent<Props> {
3132
static defaultProps = {
3233
isVerticalOrientation: false,
3334
isScrolledHorizontally: false,
35+
showTitle: false,
3436
onModifyCell: noop,
3537
};
3638

@@ -93,6 +95,7 @@ class Timetable extends PureComponent<Props> {
9395
endingIndex={endingIndex}
9496
onModifyCell={this.props.onModifyCell}
9597
verticalMode={this.props.isVerticalOrientation}
98+
showTitle={this.props.showTitle}
9699
dayLessonRows={this.props.lessons[day] || [[]]}
97100
isScrolledHorizontally={this.props.isScrolledHorizontally}
98101
isCurrentDay={index === currentDayIndex}

www/src/js/views/timetable/TimetableActions.jsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// @flow
22
import type { Semester } from 'types/modules';
33
import type { SemTimetableConfig } from 'types/timetables';
4+
import classnames from 'classnames';
45

56
import React from 'react';
6-
import { Sidebar } from 'views/components/icons';
7+
import { Sidebar, Type } from 'views/components/icons';
78
import ShareTimetable from './ShareTimetable';
89
import ExportMenu from './ExportMenu';
910

@@ -13,11 +14,14 @@ type Props = {
1314
semester: Semester,
1415
timetable: SemTimetableConfig,
1516
isVerticalOrientation: boolean,
17+
showTitle: boolean,
1618
toggleTimetableOrientation: Function,
19+
toggleTitleDisplay: Function,
1720
};
1821

1922
function TimetableActions(props: Props) {
20-
const { isVerticalOrientation } = props;
23+
const { isVerticalOrientation, showTitle } = props;
24+
2125
return (
2226
<div
2327
className="btn-toolbar justify-content-between"
@@ -27,12 +31,22 @@ function TimetableActions(props: Props) {
2731
<div className={styles.leftButtonGroup} role="group" aria-label="Timetable manipulation">
2832
<button
2933
type="button"
30-
className="btn btn-outline-primary btn-svg"
34+
className={classnames(styles.orientationBtn, 'btn btn-outline-primary btn-svg')}
3135
onClick={props.toggleTimetableOrientation}
3236
>
3337
<Sidebar className={styles.sidebarIcon} />
3438
{isVerticalOrientation ? 'Horizontal Mode' : 'Vertical Mode'}
3539
</button>
40+
41+
<button
42+
type="button"
43+
className={classnames(styles.titleBtn, 'btn-outline-primary btn btn-svg')}
44+
onClick={props.toggleTitleDisplay}
45+
disabled={isVerticalOrientation}
46+
>
47+
<Type className={styles.titleIcon} />
48+
{showTitle ? 'Hide Titles' : 'Show Titles'}
49+
</button>
3650
</div>
3751

3852
<div className={styles.rightButtonGroup} role="group" aria-label="Timetable exporting">

www/src/js/views/timetable/TimetableActions.scss

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99
}
1010
}
1111

12+
.titleIcon {
13+
composes: svg svg-small from global;
14+
}
15+
16+
.orientationBtn {
17+
@include vertical-mode {
18+
flex: 1;
19+
}
20+
}
21+
22+
.titleBtn {
23+
@include vertical-mode {
24+
display: none;
25+
}
26+
}
27+
1228
.leftButtonGroup,
1329
.rightButtonGroup {
1430
display: flex;
@@ -42,12 +58,9 @@
4258
}
4359

4460
@mixin layout-2 {
61+
.rightButtonGroup,
4562
.leftButtonGroup {
46-
width: 33%;
47-
}
48-
49-
.rightButtonGroup {
50-
width: 66%;
63+
width: 100%;
5164
}
5265
}
5366

@@ -61,13 +74,17 @@
6174
}
6275

6376
.leftButtonGroup {
64-
:global(.btn) {
65-
width: 100%;
77+
justify-content: space-between;
78+
min-width: 19rem;
79+
80+
> * {
81+
width: calc(50% - 0.25rem);
6682
}
6783
}
6884

6985
:global(.verticalMode) {
70-
.rightButtonGroup {
86+
.rightButtonGroup,
87+
.leftButtonGroup {
7188
min-width: 0;
7289
}
7390

www/src/js/views/timetable/TimetableCell.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ type Props = {
1212
lesson: Lesson,
1313
style: Object,
1414
isScrolledHorizontally: boolean,
15+
showTitle: boolean,
1516
onModifyCell?: Function,
1617
};
1718

1819
function TimetableCell(props: Props) {
1920
const lesson = props.lesson;
21+
const moduleName = props.showTitle
22+
? `${lesson.ModuleCode} ${lesson.ModuleTitle}`
23+
: lesson.ModuleCode;
24+
2025
return (
2126
<button
2227
// $FlowFixMe When object spread type actually works
@@ -39,7 +44,7 @@ function TimetableCell(props: Props) {
3944
style={props.style}
4045
>
4146
<div className={styles.cellContainer}>
42-
<div className={styles.moduleCode}>{lesson.ModuleCode}</div>
47+
<div className={styles.moduleName}>{moduleName}</div>
4348
<div>
4449
{LESSON_TYPE_ABBREV[lesson.LessonType]} [{lesson.ClassNo}]
4550
</div>

www/src/js/views/timetable/TimetableCell.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ $cell-border-radius: 6px;
6969
z-index: $timetable-selected-cell-scrolled-z-index;
7070
}
7171

72-
.moduleCode {
72+
.moduleName {
7373
font-weight: 600;
7474
font-size: $font-size-xs;
7575
}

0 commit comments

Comments
 (0)