Showing
1 changed file
with
11 additions
and
2 deletions
1 | import React, { useCallback, useContext } from 'react'; | 1 | import React, { useCallback, useContext } from 'react'; |
2 | -import { useHistory } from 'react-router'; | 2 | +import { useHistory, useLocation } from 'react-router'; |
3 | import SocketContext from '../../contexts/SocketContext'; | 3 | import SocketContext from '../../contexts/SocketContext'; |
4 | import { MessageResponse, MessageType, RawMessage } from '../common/types'; | 4 | import { MessageResponse, MessageType, RawMessage } from '../common/types'; |
5 | import { RoomData } from '../room/types'; | 5 | import { RoomData } from '../room/types'; |
6 | import { Room } from './types'; | 6 | import { Room } from './types'; |
7 | 7 | ||
8 | +interface RoomBlockLocation { | ||
9 | + state: { username: string } | ||
10 | +} | ||
11 | + | ||
8 | interface RoomBlockProps { | 12 | interface RoomBlockProps { |
9 | room: Room | 13 | room: Room |
10 | } | 14 | } |
... | @@ -12,6 +16,8 @@ interface RoomBlockProps { | ... | @@ -12,6 +16,8 @@ interface RoomBlockProps { |
12 | export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => { | 16 | export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => { |
13 | const history = useHistory(); | 17 | const history = useHistory(); |
14 | const socket = useContext(SocketContext); | 18 | const socket = useContext(SocketContext); |
19 | + const location: RoomBlockLocation = useLocation(); | ||
20 | + | ||
15 | const joinRoom = useCallback(() => { | 21 | const joinRoom = useCallback(() => { |
16 | if (room.currentUsers < room.maxUsers) { | 22 | if (room.currentUsers < room.maxUsers) { |
17 | const rawMessage: RawMessage = { | 23 | const rawMessage: RawMessage = { |
... | @@ -22,7 +28,10 @@ export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => { | ... | @@ -22,7 +28,10 @@ export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => { |
22 | if (response.ok) { | 28 | if (response.ok) { |
23 | history.push({ | 29 | history.push({ |
24 | pathname: '/' + room.uuid, | 30 | pathname: '/' + room.uuid, |
25 | - state: {roomData: response.result!} | 31 | + state: { |
32 | + username: location.state.username, | ||
33 | + roomData: response.result! | ||
34 | + } | ||
26 | }); | 35 | }); |
27 | } else { | 36 | } else { |
28 | //TODO: 에러 MODAL을 어케띄우지? 하위컴포넌트에서 훅을 쓰면 어떻게 되는지 확인 | 37 | //TODO: 에러 MODAL을 어케띄우지? 하위컴포넌트에서 훅을 쓰면 어떻게 되는지 확인 | ... | ... |
-
Please register or login to post a comment