Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
C_Team_KhuDrive
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
김재형
2020-06-17 16:08:38 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4027b449fd31312e9ba872ea4759640ad485033d
4027b449
1 parent
20c32532
Implement logout
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
11 deletions
frontend/src/App.tsx
frontend/src/auth/useAuth.ts
frontend/src/file/FileList.tsx
frontend/src/layout/Page.module.scss
frontend/src/layout/Page.tsx
frontend/src/App.tsx
View file @
4027b44
...
...
@@ -8,16 +8,16 @@ import { Page } from "layout/Page";
import { FileList } from "file/FileList";
export function App() {
const
{ token, login }
= useAuth();
const root = token?.user.rootFolder;
const
token
= useAuth();
const root = token?.
token?.
user.rootFolder;
return (
<Switch>
<Route path="/login">
<Login login={login} />
<Login login={
token.
login} />
</Route>
<Route>
{token !== null ? (
{token
.token
!== null ? (
<TokenContext.Provider value={token}>
<Page>
<Switch>
...
...
frontend/src/auth/useAuth.ts
View file @
4027b44
...
...
@@ -29,7 +29,9 @@ interface Token {
};
}
export
const
TokenContext
=
React
.
createContext
<
Token
>
({}
as
Token
);
export
const
TokenContext
=
React
.
createContext
<
ReturnType
<
typeof
useAuth
>>
(
{}
as
any
);
export
function
useAuth
()
{
const
[
token
,
setToken
]
=
useState
<
Token
|
null
>
(()
=>
{
...
...
@@ -75,5 +77,7 @@ export function useAuth() {
[]
);
return
{
token
,
login
};
const
logout
=
useCallback
(()
=>
setToken
(
null
),
[]);
return
{
token
,
login
,
logout
};
}
...
...
frontend/src/file/FileList.tsx
View file @
4027b44
...
...
@@ -21,8 +21,8 @@ export function FileList() {
const [upload, setUpload] = useState<boolean>(false);
const [createFolder, setCreateFolder] = useState<boolean>(false);
const
token
= useContext(TokenContext);
const userId = token
.user.id
;
const
{ token }
= useContext(TokenContext);
const userId = token
?.user.id || ""
;
const api = useApi();
...
...
frontend/src/layout/Page.module.scss
View file @
4027b44
...
...
@@ -2,6 +2,12 @@
height
:
100%
;
}
.header
{
display
:
flex
;
align-items
:
center
;
justify-content
:
space-between
;
}
.content
{
background
:
#fff
;
padding
:
25px
50px
;
...
...
@@ -20,6 +26,23 @@
font-weight
:
bold
;
}
.user
{
display
:
flex
;
align-items
:
center
;
color
:
white
;
svg
{
width
:
28px
;
height
:
28px
;
}
&
:hover
,
&
:active
,
&
:focus
{
color
:
rgba
(
255
,
255
,
255
,
0
.65
);
}
}
.footer
{
text-align
:
center
;
}
...
...
frontend/src/layout/Page.tsx
View file @
4027b44
import React from "react";
import { Layout } from "antd";
import React, { useContext } from "react";
import { Layout, Popover, Button } from "antd";
import { UserOutlined } from "@ant-design/icons";
import { TokenContext } from "auth/useAuth";
import styles from "./Page.module.scss";
export function Page({ children }: { children: React.ReactNode }) {
const { token, logout } = useContext(TokenContext);
return (
<Layout className={styles.layout}>
<Layout.Header>
<Layout.Header
className={styles.header}
>
<div className={styles.logo}>KHUDrive</div>
<Popover
content={
<div>
{token?.user.name}
<Button type="link" onClick={logout}>
로그아웃
</Button>
</div>
}
trigger="click"
>
<Button type="text" className={styles.user}>
<UserOutlined />
</Button>
</Popover>
</Layout.Header>
<Layout.Content className={styles.content}>{children}</Layout.Content>
<Layout.Footer className={styles.footer}>
...
...
Please
register
or
login
to post a comment