Skip to content

Commit 17bf19d

Browse files
authored
Merge pull request #41 from boostcampwm-2022/feat/#20-B
Feat/#20-B: μ›Œν¬μŠ€νŽ˜μ΄μŠ€ 리슀트 API, UI 연동
2 parents 192e559 + 0d16acf commit 17bf19d

File tree

8 files changed

+55
-13
lines changed

8 files changed

+55
-13
lines changed

β€Žclient/package.jsonβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
"preview": "vite preview"
1010
},
1111
"dependencies": {
12-
"classnames": "^2.3.2",
1312
"@react-icons/all-files": "^4.1.0",
13+
"axios": "^1.1.3",
14+
"classnames": "^2.3.2",
1415
"react": "^18.2.0",
1516
"react-dom": "^18.2.0",
1617
"react-router-dom": "^6.4.3"

β€Žclient/src/App.tsxβ€Ž

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { BrowserRouter, Routes, Route } from "react-router-dom";
2-
import { LoginPage, WorkspacePage } from "./pages";
3-
import "style/reset.scss";
1+
import { BrowserRouter, Routes, Route } from 'react-router-dom';
2+
3+
import { LoginPage, WorkspacePage } from './pages';
4+
import 'style/reset.scss';
45

56
function App() {
67
return (

β€Žclient/src/apis/http.tsβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import axios from 'axios';
2+
3+
const SERVER_URL = 'http://localhost:8080';
4+
5+
export const http = axios.create({
6+
baseURL: SERVER_URL,
7+
});

β€Žclient/src/apis/user.tsβ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { http } from './http';
2+
3+
export const getWorkspaces = async (userId: number) => {
4+
try {
5+
const { data } = await http.get(`/user/${userId}/workspace`);
6+
7+
return data;
8+
} catch (e) {
9+
return;
10+
}
11+
};

β€Žclient/src/components/WorkspaceList/WorkspaceThumbnailList.tsxβ€Ž

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
import { Workspace } from 'src/types/workspace';
2+
13
import style from './style.module.scss';
24
import WorkspaceThumbnailItem from './WorkspaceThumbnailItem';
35

4-
const workspaces = [
5-
{ id: 1, name: 'μ™­' },
6-
{ id: 2, name: '넀이버' },
7-
{ id: 3, name: '카카였' },
8-
{ id: 4, name: 'ν† μŠ€' },
9-
];
6+
interface WorkspaceThumbnailListProps {
7+
workspaces: Workspace[];
8+
}
109

11-
function WorkspaceThumbnailList() {
10+
function WorkspaceThumbnailList({ workspaces }: WorkspaceThumbnailListProps) {
1211
return (
1312
<ul className={style.thumbnail__list}>
1413
{workspaces.map((workspace) => (

β€Žclient/src/components/WorkspaceList/index.tsxβ€Ž

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { memo } from 'react';
1+
import { memo, useEffect, useState } from 'react';
2+
import { getWorkspaces } from 'src/apis/user';
3+
import { Workspace } from 'src/types/workspace';
24

35
import AddButton from './AddButton';
46
import style from './style.module.scss';
@@ -9,9 +11,24 @@ interface WorkspaceListProps {
911
}
1012

1113
function WorkspaceList({ onSelectModalOpen }: WorkspaceListProps) {
14+
const [workspaces, setWorkspaces] = useState<Workspace[]>([]);
15+
/**
16+
* λ‚˜μ€‘μ— loginν•˜κ³  context생기면 λ°”κΏ” 끼우면 λΌμš”.
17+
*/
18+
const userId = 63814960;
19+
20+
const updateWorkspaces = async (userId: number) => {
21+
const { workspaces } = await getWorkspaces(userId);
22+
setWorkspaces(workspaces);
23+
};
24+
25+
useEffect(() => {
26+
updateWorkspaces(userId);
27+
}, []);
28+
1229
return (
1330
<div className={style.workspace__container}>
14-
<WorkspaceThumbnaliList />
31+
<WorkspaceThumbnaliList workspaces={workspaces} />
1532
<AddButton onClick={onSelectModalOpen} />
1633
</div>
1734
);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface Workspace {
2+
id: number;
3+
name: string;
4+
}

β€Žserver/apis/user/controller.tsβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ router.get(
1717
userId,
1818
);
1919

20+
res.setHeader('Access-Control-Allow-origin', '*');
21+
res.setHeader('Access-Control-Allow-Credentials', 'true');
2022
res.send({ workspaces });
2123
}),
2224
);

0 commit comments

Comments
Β (0)