Showing
5 changed files
with
56 additions
and
11 deletions
... | @@ -8,16 +8,16 @@ import { Page } from "layout/Page"; | ... | @@ -8,16 +8,16 @@ import { Page } from "layout/Page"; |
8 | import { FileList } from "file/FileList"; | 8 | import { FileList } from "file/FileList"; |
9 | 9 | ||
10 | export function App() { | 10 | export function App() { |
11 | - const { token, login } = useAuth(); | 11 | + const token = useAuth(); |
12 | - const root = token?.user.rootFolder; | 12 | + const root = token?.token?.user.rootFolder; |
13 | 13 | ||
14 | return ( | 14 | return ( |
15 | <Switch> | 15 | <Switch> |
16 | <Route path="/login"> | 16 | <Route path="/login"> |
17 | - <Login login={login} /> | 17 | + <Login login={token.login} /> |
18 | </Route> | 18 | </Route> |
19 | <Route> | 19 | <Route> |
20 | - {token !== null ? ( | 20 | + {token.token !== null ? ( |
21 | <TokenContext.Provider value={token}> | 21 | <TokenContext.Provider value={token}> |
22 | <Page> | 22 | <Page> |
23 | <Switch> | 23 | <Switch> | ... | ... |
... | @@ -29,7 +29,9 @@ interface Token { | ... | @@ -29,7 +29,9 @@ interface Token { |
29 | }; | 29 | }; |
30 | } | 30 | } |
31 | 31 | ||
32 | -export const TokenContext = React.createContext<Token>({} as Token); | 32 | +export const TokenContext = React.createContext<ReturnType<typeof useAuth>>( |
33 | + {} as any | ||
34 | +); | ||
33 | 35 | ||
34 | export function useAuth() { | 36 | export function useAuth() { |
35 | const [token, setToken] = useState<Token | null>(() => { | 37 | const [token, setToken] = useState<Token | null>(() => { |
... | @@ -75,5 +77,7 @@ export function useAuth() { | ... | @@ -75,5 +77,7 @@ export function useAuth() { |
75 | [] | 77 | [] |
76 | ); | 78 | ); |
77 | 79 | ||
78 | - return { token, login }; | 80 | + const logout = useCallback(() => setToken(null), []); |
81 | + | ||
82 | + return { token, login, logout }; | ||
79 | } | 83 | } | ... | ... |
... | @@ -21,8 +21,8 @@ export function FileList() { | ... | @@ -21,8 +21,8 @@ export function FileList() { |
21 | const [upload, setUpload] = useState<boolean>(false); | 21 | const [upload, setUpload] = useState<boolean>(false); |
22 | const [createFolder, setCreateFolder] = useState<boolean>(false); | 22 | const [createFolder, setCreateFolder] = useState<boolean>(false); |
23 | 23 | ||
24 | - const token = useContext(TokenContext); | 24 | + const { token } = useContext(TokenContext); |
25 | - const userId = token.user.id; | 25 | + const userId = token?.user.id || ""; |
26 | 26 | ||
27 | const api = useApi(); | 27 | const api = useApi(); |
28 | 28 | ... | ... |
... | @@ -2,6 +2,12 @@ | ... | @@ -2,6 +2,12 @@ |
2 | height: 100%; | 2 | height: 100%; |
3 | } | 3 | } |
4 | 4 | ||
5 | +.header { | ||
6 | + display: flex; | ||
7 | + align-items: center; | ||
8 | + justify-content: space-between; | ||
9 | +} | ||
10 | + | ||
5 | .content { | 11 | .content { |
6 | background: #fff; | 12 | background: #fff; |
7 | padding: 25px 50px; | 13 | padding: 25px 50px; |
... | @@ -20,6 +26,23 @@ | ... | @@ -20,6 +26,23 @@ |
20 | font-weight: bold; | 26 | font-weight: bold; |
21 | } | 27 | } |
22 | 28 | ||
29 | +.user { | ||
30 | + display: flex; | ||
31 | + align-items: center; | ||
32 | + color: white; | ||
33 | + | ||
34 | + svg { | ||
35 | + width: 28px; | ||
36 | + height: 28px; | ||
37 | + } | ||
38 | + | ||
39 | + &:hover, | ||
40 | + &:active, | ||
41 | + &:focus { | ||
42 | + color: rgba(255, 255, 255, 0.65); | ||
43 | + } | ||
44 | +} | ||
45 | + | ||
23 | .footer { | 46 | .footer { |
24 | text-align: center; | 47 | text-align: center; |
25 | } | 48 | } | ... | ... |
1 | -import React from "react"; | 1 | +import React, { useContext } from "react"; |
2 | -import { Layout } from "antd"; | 2 | +import { Layout, Popover, Button } from "antd"; |
3 | +import { UserOutlined } from "@ant-design/icons"; | ||
4 | +import { TokenContext } from "auth/useAuth"; | ||
3 | 5 | ||
4 | import styles from "./Page.module.scss"; | 6 | import styles from "./Page.module.scss"; |
5 | 7 | ||
6 | export function Page({ children }: { children: React.ReactNode }) { | 8 | export function Page({ children }: { children: React.ReactNode }) { |
9 | + const { token, logout } = useContext(TokenContext); | ||
7 | return ( | 10 | return ( |
8 | <Layout className={styles.layout}> | 11 | <Layout className={styles.layout}> |
9 | - <Layout.Header> | 12 | + <Layout.Header className={styles.header}> |
10 | <div className={styles.logo}>KHUDrive</div> | 13 | <div className={styles.logo}>KHUDrive</div> |
14 | + <Popover | ||
15 | + content={ | ||
16 | + <div> | ||
17 | + {token?.user.name} | ||
18 | + <Button type="link" onClick={logout}> | ||
19 | + 로그아웃 | ||
20 | + </Button> | ||
21 | + </div> | ||
22 | + } | ||
23 | + trigger="click" | ||
24 | + > | ||
25 | + <Button type="text" className={styles.user}> | ||
26 | + <UserOutlined /> | ||
27 | + </Button> | ||
28 | + </Popover> | ||
11 | </Layout.Header> | 29 | </Layout.Header> |
12 | <Layout.Content className={styles.content}>{children}</Layout.Content> | 30 | <Layout.Content className={styles.content}>{children}</Layout.Content> |
13 | <Layout.Footer className={styles.footer}> | 31 | <Layout.Footer className={styles.footer}> | ... | ... |
-
Please register or login to post a comment