File tree Expand file tree Collapse file tree 8 files changed +55
-13
lines changed Expand file tree Collapse file tree 8 files changed +55
-13
lines changed Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff line change 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
56function App ( ) {
67 return (
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 1+ import { Workspace } from 'src/types/workspace' ;
2+
13import style from './style.module.scss' ;
24import 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 ) => (
Original file line number Diff line number Diff line change 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
35import AddButton from './AddButton' ;
46import style from './style.module.scss' ;
@@ -9,9 +11,24 @@ interface WorkspaceListProps {
911}
1012
1113function 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 ) ;
Original file line number Diff line number Diff line change 1+ export interface Workspace {
2+ id : number ;
3+ name : string ;
4+ }
Original file line number Diff line number Diff 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) ;
You canβt perform that action at this time.
0 commit comments