-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.tsx
More file actions
84 lines (78 loc) · 2.67 KB
/
index.tsx
File metadata and controls
84 lines (78 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { useEffect } from 'react';
import Link from 'next/link';
import { isValidTimetableFrameId } from 'api/timetable/queries';
import ErrorBoundary from 'components/boundary/ErrorBoundary';
import Timetable from 'components/TimetablePage/components/Timetable';
import TimetableGridPlaceholder from 'components/TimetablePage/components/TimetableGridPlaceholder';
import useSemesterOptionList from 'components/TimetablePage/hooks/useSemesterOptionList';
import useTimetableFrameList from 'components/TimetablePage/hooks/useTimetableFrameList';
import ROUTES from 'static/routes';
import useLogger from 'utils/hooks/analytics/useLogger';
import useMount from 'utils/hooks/state/useMount';
import useTokenState from 'utils/hooks/state/useTokenState';
import { useSemester, useSemesterAction } from 'utils/zustand/semester';
import styles from './IndexTimetable.module.scss';
export default function IndexTimeTable() {
const { updateSemester } = useSemesterAction();
const semesterOptionList = useSemesterOptionList();
const logger = useLogger();
const semester = useSemester();
const token = useTokenState();
const { data: timetableFrameList } = useTimetableFrameList(token, semester);
const currentFrameId = timetableFrameList?.find((frame) => frame.is_main)?.id;
const hasValidCurrentFrameId = isValidTimetableFrameId(currentFrameId);
const isClient = useMount();
useEffect(() => {
if (semesterOptionList.length > 0) updateSemester(semesterOptionList[0].value);
}, [semesterOptionList, updateSemester]);
const renderPlaceholder = (
<TimetableGridPlaceholder
columnWidth={44}
firstColumnWidth={29}
rowHeight={17.3}
totalHeight={369}
/>
);
const renderTimetable = hasValidCurrentFrameId ? (
<Timetable
timetableFrameId={currentFrameId}
columnWidth={44}
firstColumnWidth={29}
rowHeight={17.3}
totalHeight={369}
/>
) : (
renderPlaceholder
);
return (
<div className={styles.template}>
<Link
href={ROUTES.Timetable()}
className={styles.title}
onClick={() => {
logger.actionEventClick({
team: 'USER',
event_label: 'main_timetable',
value: 'text',
});
}}
>
시간표
</Link>
<ErrorBoundary fallbackClassName="loading">
<Link
href={ROUTES.Timetable()}
onClick={() => {
logger.actionEventClick({
team: 'USER',
event_label: 'main_timetable',
value: 'table',
});
}}
>
{isClient ? renderTimetable : renderPlaceholder}
</Link>
</ErrorBoundary>
</div>
);
}