App.tsx
1 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
import React, { useEffect } from "react";
import { Switch, Route, Redirect, useHistory } from "react-router-dom";
import { Login } from "auth/Login";
import { useAuth, TokenContext } from "auth/useAuth";
import { Page } from "layout/Page";
import { FileList } from "file/FileList";
export function App() {
const { token, login } = useAuth();
const root = token?.user.rootFolder;
const history = useHistory();
useEffect(() => {
if (root) {
history.push(`/folder/${root}`);
}
}, [history, root]);
return (
<Switch>
<Route path="/login">
<Login login={login} />
</Route>
<Route>
{token !== null ? (
<TokenContext.Provider value={token}>
<Page>
<Switch>
<Route path="/folder/:id">
<FileList />
</Route>
</Switch>
</Page>
</TokenContext.Provider>
) : (
<Redirect to="/login" />
)}
</Route>
</Switch>
);
}