Skip to content

Commit 4221747

Browse files
authored
Merge pull request #8 from SWM-FIRE/FIRE-170-개발-fe-방번호로-해당-방에-입장할-수-있게-라우팅-설정
FIRE-170 - FIRE-170-개발-fe-방번호로-해당-방에-입장할-수-있게-라우팅-설정
2 parents c22fa8a + 5f8a000 commit 4221747

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function Router() {
1616
<Route index element={<Lobby />} />
1717
</Route>
1818
<Route path="/room" element={<Layout />}>
19-
<Route index element={<Room />} />
19+
<Route path=":roomId" element={<Room />} />
2020
</Route>
2121
</Routes>
2222
</BrowserRouter>

src/components/lobby/Room.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ import roomInterface from '../../room.interface';
55
export default function Room() {
66
return (
77
<>
8-
{roomAPI.map(({ name, total, current }: roomInterface) => {
8+
{roomAPI.map(({ name, total, current, id }: roomInterface) => {
99
return (
10-
<RoomBlock key={name} name={name} total={total} current={current} />
10+
<RoomBlock
11+
key={id}
12+
name={name}
13+
total={total}
14+
current={current}
15+
id={id}
16+
/>
1117
);
1218
})}
1319
</>

src/components/lobby/RoomBlock.tsx

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
import styled from 'styled-components';
2-
import oc from '../../styles/openColor';
2+
import React from 'react';
3+
import { useNavigate } from 'react-router-dom';
34
import roomInterface from '../../room.interface';
5+
import oc from '../../styles/openColor';
46

5-
export default function RoomBlock({ name, total, current }: roomInterface) {
7+
export default function RoomBlock({ name, total, current, id }: roomInterface) {
8+
/*
9+
socket.emit('ENTER_ROOM', payload, (confirmRoomId) => {
10+
navigate(`room/${confirmRoomId}`);
11+
});
12+
*/
13+
const navigate = useNavigate();
14+
const onSubmit = (event: React.MouseEvent<HTMLButtonElement>) => {
15+
event.preventDefault();
16+
console.log('test');
17+
navigate(`/room/${id}`);
18+
};
619
return (
7-
<Container>
20+
<Button onClick={onSubmit}>
821
<RoomName>{name}</RoomName>
922
<div>
1023
{current} / {total}
1124
</div>
12-
</Container>
25+
</Button>
1326
);
1427
}
1528

1629
const RoomName = styled.div`
1730
font-size: 5rem;
1831
`;
1932

20-
const Container = styled.div`
33+
const Button = styled.button`
2134
text-align: center;
2235
width: 20rem;
2336
height: 10rem;

src/room.interface.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export default interface roomInterface {
22
name: string;
33
total: number;
44
current: number;
5+
id: string;
56
}

src/rooms.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
{
33
"name": "room1",
44
"total": 4,
5-
"current": 0
5+
"current": 0,
6+
"id": "1"
67
},
78
{
89
"name": "room2",
910
"total": 4,
10-
"current": 0
11+
"current": 0,
12+
"id": "2"
1113
},
1214
{
1315
"name": "room3",
1416
"total": 4,
15-
"current": 0
17+
"current": 0,
18+
"id": "3"
1619
}
1720
]

0 commit comments

Comments
 (0)