Skip to content

Commit 973b51e

Browse files
committed
Merge branch 'dev' of https://github.com/boostcampwm-2022/web27-Wabinar into feat/#51-S
2 parents 9a9ed55 + a825027 commit 973b51e

File tree

21 files changed

+80
-44
lines changed

21 files changed

+80
-44
lines changed

client/src/App.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { useState, useEffect } from 'react';
22
import { Routes, Route, useNavigate } from 'react-router-dom';
33
import { getAuth } from 'src/apis/auth';
44
import UserContext, { User } from 'src/contexts/user';
5-
import { LoginPage, OAuthPage, WorkspacePage } from 'src/pages';
5+
import { LoadingPage, LoginPage, OAuthPage, WorkspacePage } from 'src/pages';
66
import 'styles/reset.scss';
77

88
function App() {
9-
const [user, setUser] = useState<User>({ id: -1, name: '', avatarUrl: '' });
9+
const [user, setUser] = useState<User | null>(null);
1010
const navigate = useNavigate();
1111

1212
const autoLogin = async () => {
@@ -22,14 +22,16 @@ function App() {
2222
autoLogin();
2323
}, []);
2424

25-
return (
25+
return user ? (
2626
<UserContext.Provider value={{ user, setUser }}>
2727
<Routes>
2828
<Route path="/" element={<LoginPage />} />
2929
<Route path="/oauth" element={<OAuthPage />} />
3030
<Route path="/workspace" element={<WorkspacePage />} />
3131
</Routes>
3232
</UserContext.Provider>
33+
) : (
34+
<LoadingPage />
3335
);
3436
}
3537

client/src/apis/auth.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { PostLoginParams } from 'params/auth';
2+
13
import { http } from './http';
24
import { OK, CREATED } from './http-status';
35

@@ -9,7 +11,7 @@ export const getAuth = async () => {
911
return res.data;
1012
};
1113

12-
export const postAuthLogin = async (code: string) => {
14+
export const postAuthLogin = async ({ code }: PostLoginParams) => {
1315
const res = await http.post(`/auth/login`, { code });
1416

1517
if (res.status !== CREATED) throw new Error();

client/src/apis/user.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { GetWorkspaceParams } from 'params/user';
2+
13
import { http } from './http';
24
import { OK } from './http-status';
35

4-
export const getWorkspaces = async (userId: number) => {
5-
const res = await http.get(`/user/${userId}/workspace`);
6+
export const getWorkspaces = async ({ id }: GetWorkspaceParams) => {
7+
const res = await http.get(`/user/${id}/workspace`);
68

79
if (res.status !== OK) throw new Error();
810

client/src/components/WorkspaceList/index.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { memo, useEffect, useState } from 'react';
1+
import { memo, useContext, useEffect, useState } from 'react';
22
import { getWorkspaces } from 'src/apis/user';
3+
import UserContext from 'src/contexts/user';
34
import { Workspace } from 'src/types/workspace';
45

56
import AddButton from './AddButton';
@@ -12,18 +13,18 @@ interface WorkspaceListProps {
1213

1314
function WorkspaceList({ onSelectModalOpen }: WorkspaceListProps) {
1415
const [workspaces, setWorkspaces] = useState<Workspace[]>([]);
15-
/**
16-
* 나중에 login하고 context생기면 바꿔 끼우면 돼요.
17-
*/
18-
const userId = 63814960;
16+
const userContext = useContext(UserContext);
1917

2018
const updateWorkspaces = async (userId: number) => {
21-
const { workspaces } = await getWorkspaces(userId);
19+
const { workspaces } = await getWorkspaces({ id: userId });
2220
setWorkspaces(workspaces);
2321
};
2422

2523
useEffect(() => {
26-
updateWorkspaces(userId);
24+
if (!userContext) {
25+
return;
26+
}
27+
updateWorkspaces(userContext.user.id);
2728
}, []);
2829

2930
return (

client/src/contexts/user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export interface User {
77
}
88

99
interface IUserContext {
10-
user?: User;
11-
setUser: Dispatch<SetStateAction<User>>;
10+
user: User;
11+
setUser: Dispatch<SetStateAction<User | null>>;
1212
}
1313

1414
const UserContext = createContext<IUserContext | null>(null);

client/src/pages/Loading/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import cx from 'classnames';
2+
import Loader from 'components/common/Loader';
3+
4+
import style from './style.module.scss';
5+
6+
function LoadingPage() {
7+
return (
8+
<div className={cx(style.container)}>
9+
<Loader size={100} />
10+
</div>
11+
);
12+
}
13+
14+
export default LoadingPage;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.container {
2+
display: flex;
3+
align-items: center;
4+
justify-content: center;
5+
width: 100vw;
6+
height: 100vh;
7+
}

client/src/pages/OAuth/index.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
1-
import cx from 'classnames';
2-
import Loader from 'components/common/Loader';
31
import { useContext, useEffect } from 'react';
42
import { useLocation, useNavigate } from 'react-router-dom';
53
import { postAuthLogin } from 'src/apis/auth';
64
import UserContext from 'src/contexts/user';
7-
8-
import style from './style.module.scss';
5+
import LoadingPage from 'src/pages/Loading';
96

107
function OAuthPage() {
118
const userContext = useContext(UserContext);
129

1310
if (userContext === null) {
1411
console.log('유저 컨텍스트를 찾을 수 없습니다.');
1512

16-
return (
17-
<div className={cx(style.container)}>
18-
<Loader size={100} />
19-
</div>
20-
);
13+
return <LoadingPage />;
2114
}
2215

2316
const location = useLocation();
2417
const navigate = useNavigate();
2518

2619
const login = async (code: string) => {
2720
try {
28-
const authorizedUser = await postAuthLogin(code);
21+
const authorizedUser = await postAuthLogin({ code });
2922

3023
userContext.setUser(authorizedUser);
3124

@@ -47,11 +40,7 @@ function OAuthPage() {
4740
login(code);
4841
}, []);
4942

50-
return (
51-
<div className={cx(style.container)}>
52-
<Loader size={100} />
53-
</div>
54-
);
43+
return <LoadingPage />;
5544
}
5645

5746
export default OAuthPage;

client/src/pages/Workspace/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState } from 'react';
2-
import SelcetModal from 'src/components/SelectModal';
2+
import SelectModal from 'src/components/SelectModal';
33
import WorkspaceList from 'src/components/WorkspaceList';
44
import WorkspaceModal from 'src/components/WorkspaceModal';
55
import { MENU, MENUS, MODAL_MENUS } from 'src/constants/workspace';
@@ -37,7 +37,7 @@ function WorkspacePage() {
3737
<div className={style.container}>
3838
<WorkspaceList onSelectModalOpen={() => setIsOpenSelectModal(true)} />
3939
{isOpenSelectModal && (
40-
<SelcetModal
40+
<SelectModal
4141
className={style['select-modal']}
4242
onClose={() => setIsOpenSelectModal(false)}
4343
>
@@ -48,7 +48,7 @@ function WorkspacePage() {
4848
</li>
4949
))}
5050
</ul>
51-
</SelcetModal>
51+
</SelectModal>
5252
)}
5353

5454
{MODAL_MENUS.map(({ id, props: { title, texts, btnText } }) => {

client/src/pages/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { default as LoadingPage } from './Loading';
12
export { default as WorkspacePage } from './Workspace';
23
export { default as LoginPage } from './Login';
34
export { default as OAuthPage } from './OAuth';

0 commit comments

Comments
 (0)