Showing
2 changed files
with
39 additions
and
1 deletions
... | @@ -2,6 +2,7 @@ import React from 'react'; | ... | @@ -2,6 +2,7 @@ import React from 'react'; |
2 | import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'; | 2 | import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'; |
3 | import { socket, SocketProvider } from './SocketContext'; | 3 | import { socket, SocketProvider } from './SocketContext'; |
4 | import { Login } from './Login'; | 4 | import { Login } from './Login'; |
5 | +import { Rooms } from './Rooms'; | ||
5 | 6 | ||
6 | const App: React.FC = () => { | 7 | const App: React.FC = () => { |
7 | return ( | 8 | return ( |
... | @@ -9,7 +10,7 @@ const App: React.FC = () => { | ... | @@ -9,7 +10,7 @@ const App: React.FC = () => { |
9 | <Router> | 10 | <Router> |
10 | <Switch> | 11 | <Switch> |
11 | <Route exact path='/' component={Login}/> | 12 | <Route exact path='/' component={Login}/> |
12 | - <Route path='/rooms'></Route> | 13 | + <Route path='/rooms' component={Rooms}></Route> |
13 | <Route path='/:roomId'></Route> | 14 | <Route path='/:roomId'></Route> |
14 | </Switch> | 15 | </Switch> |
15 | </Router> | 16 | </Router> | ... | ... |
web/src/Rooms.tsx
0 → 100644
1 | +import React, { useContext, useEffect, useState } from 'react'; | ||
2 | +import { RouteComponentProps } from 'react-router'; | ||
3 | +import SocketContext from './SocketContext'; | ||
4 | + | ||
5 | +interface room { | ||
6 | + uuid: string; | ||
7 | + name: string; | ||
8 | + currentUsers: number; | ||
9 | + maxUsers: number; | ||
10 | +} | ||
11 | + | ||
12 | +export const Rooms: React.FC<RouteComponentProps> = ({ history }) => { | ||
13 | + const socket = useContext(SocketContext); | ||
14 | + const [ rooms, setRooms ] = useState<room[]>([]); | ||
15 | + | ||
16 | + useEffect(() => { | ||
17 | + socket.emit('room_list', ({ ok } : { ok: boolean }) => { | ||
18 | + if (ok) { | ||
19 | + history.push('/rooms'); | ||
20 | + } else { | ||
21 | + console.error('login error!'); // TODO: 팝업 에러? | ||
22 | + } | ||
23 | + }); // TODO: interval마다 emit하거나 새로고침 버튼을 만들자 | ||
24 | + | ||
25 | + // socket.on('') | ||
26 | + }, []); | ||
27 | + | ||
28 | + return ( | ||
29 | + <div> | ||
30 | + <header>header header</header> | ||
31 | + <div className='flex items-center'> | ||
32 | + <div>room test</div> | ||
33 | + </div> | ||
34 | + <footer>footer footer</footer> | ||
35 | + </div> | ||
36 | + ) | ||
37 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment