-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathApp.tsx
More file actions
58 lines (51 loc) · 1.65 KB
/
Copy pathApp.tsx
File metadata and controls
58 lines (51 loc) · 1.65 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
import { useEffect, useState } from 'react';
import {
HashRouter as Router,
Route,
Routes
} from 'react-router-dom';
import Assignments from '../Assignments';
import Home from '../Home';
import Lectures from '../Lectures';
import Nav from '../Nav';
import NoMatch from '../NoMatch';
import Page from '../Page';
import getAssignmentData from './DataModel/AssignmentData';
import DataContext, { UniversalData } from './DataModel/DataContext';
import getLectureData from './DataModel/LectureData';
import getScheduleData from './DataModel/ScheduleData';
const App = () => {
if (!window.location.href.includes('#')) {
window.location.href = window.location.href + '#/';
}
const [allData, setAllData] = useState<UniversalData | null>(
localStorage.getItem('data') ? JSON.parse(localStorage.getItem('data')!) : null
);
useEffect(() => {
(async () => {
const schedule = await getScheduleData();
const lecture = await getLectureData();
const assignment = await getAssignmentData();
setAllData({ schedule, lecture, assignment })
localStorage.setItem(
'data',
JSON.stringify({ schedule, lecture, assignment })
);
})()
}, [setAllData])
return (
<Router>
<Nav />
<DataContext.Provider value={allData}>
<Routes>
<Route path='/' element={<Home />} />
<Route path='/lectures' element={<Lectures />} />
<Route path='/assignments' element={<Assignments />} />
<Route path='/page/*' element={<Page />} />
<Route path='*' element={<NoMatch />} />
</Routes>
</DataContext.Provider>
</Router>
);
}
export default App;