Showing
5 changed files
with
8 additions
and
12 deletions
1 | import React, { useCallback, useContext } from 'react'; | 1 | import React, { useCallback, useContext } from 'react'; |
2 | -import { IndexType } from 'typescript'; | ||
3 | import SocketContext from '../../contexts/SocketContext'; | 2 | import SocketContext from '../../contexts/SocketContext'; |
4 | import { MessageResponse, MessageType, RawMessage } from '../common/types'; | 3 | import { MessageResponse, MessageType, RawMessage } from '../common/types'; |
5 | 4 | ||
... | @@ -24,7 +23,7 @@ export const Word: React.FC<WordProps> = (props) => { | ... | @@ -24,7 +23,7 @@ export const Word: React.FC<WordProps> = (props) => { |
24 | props.setWordChosen(props.word); | 23 | props.setWordChosen(props.word); |
25 | } | 24 | } |
26 | }); | 25 | }); |
27 | - }, [props.setWordChosen]); | 26 | + }, [props.word, props.setWords, props.setWordChosen]); |
28 | 27 | ||
29 | return ( | 28 | return ( |
30 | <button className={`bg-green-500 active:bg-green-600 fixed | 29 | <button className={`bg-green-500 active:bg-green-600 fixed | ... | ... |
... | @@ -3,7 +3,6 @@ import { useHistory, useLocation } from 'react-router-dom'; | ... | @@ -3,7 +3,6 @@ import { useHistory, useLocation } from 'react-router-dom'; |
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'; | ||
7 | 6 | ||
8 | interface CreateLocation { | 7 | interface CreateLocation { |
9 | state: { username: string } | 8 | state: { username: string } |
... | @@ -33,7 +32,7 @@ export const Create: React.FC = () => { | ... | @@ -33,7 +32,7 @@ export const Create: React.FC = () => { |
33 | console.log('방 생성 오류'); | 32 | console.log('방 생성 오류'); |
34 | } | 33 | } |
35 | }); | 34 | }); |
36 | - }, [roomName]); | 35 | + }, [roomName, location.state.username]); |
37 | 36 | ||
38 | return ( | 37 | return ( |
39 | <div className="flex items-center"> | 38 | <div className="flex items-center"> | ... | ... |
... | @@ -40,7 +40,7 @@ export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => { | ... | @@ -40,7 +40,7 @@ export const RoomBlock: React.FC<RoomBlockProps> = ({ room }) => { |
40 | } else { | 40 | } else { |
41 | //TODO: 자리 꽉찼다는 MODAL | 41 | //TODO: 자리 꽉찼다는 MODAL |
42 | } | 42 | } |
43 | - }, []); | 43 | + }, [location.state.username, room]); |
44 | 44 | ||
45 | return ( | 45 | return ( |
46 | <button className={`flex items-center place-content-between m-2 w-5/6 | 46 | <button className={`flex items-center place-content-between m-2 w-5/6 | ... | ... |
... | @@ -29,7 +29,7 @@ export const Login: React.FC = () => { | ... | @@ -29,7 +29,7 @@ export const Login: React.FC = () => { |
29 | return ( | 29 | return ( |
30 | <Main> | 30 | <Main> |
31 | <div className="mt-auto flex flex-col items-center"> | 31 | <div className="mt-auto flex flex-col items-center"> |
32 | - <img className="m-7" src="./logo192.png"/> | 32 | + <img className="m-7" src="./logo192.png" alt='logo img' /> |
33 | <div> | 33 | <div> |
34 | <input type="text" | 34 | <input type="text" |
35 | placeholder="Username" | 35 | placeholder="Username" | ... | ... |
... | @@ -2,7 +2,6 @@ import React, { useCallback, useContext, useEffect, useState } from 'react'; | ... | @@ -2,7 +2,6 @@ import React, { useCallback, useContext, useEffect, useState } from 'react'; |
2 | import { useHistory, useLocation } from 'react-router'; | 2 | import { useHistory, useLocation } from 'react-router'; |
3 | import { Main } from '../components/common/Main'; | 3 | import { Main } from '../components/common/Main'; |
4 | import { MessageResponse, MessageType, RawMessage } from '../components/common/types'; | 4 | import { MessageResponse, MessageType, RawMessage } from '../components/common/types'; |
5 | -import { Canvas } from '../components/room/Canvas'; | ||
6 | import { Chat } from '../components/room/Chat'; | 5 | import { Chat } from '../components/room/Chat'; |
7 | import { GameBoard } from '../components/room/GameBoard'; | 6 | import { GameBoard } from '../components/room/GameBoard'; |
8 | import { Ready } from '../components/room/Ready'; | 7 | import { Ready } from '../components/room/Ready'; |
... | @@ -10,7 +9,6 @@ import { RoomInfo } from '../components/room/RoomInfo'; | ... | @@ -10,7 +9,6 @@ import { RoomInfo } from '../components/room/RoomInfo'; |
10 | import { RoomData, UpdateRoomUser } from '../components/room/types'; | 9 | import { RoomData, UpdateRoomUser } from '../components/room/types'; |
11 | import { UserInfo } from '../components/room/UserInfo'; | 10 | import { UserInfo } from '../components/room/UserInfo'; |
12 | import { UserRole } from '../components/room/UserRole'; | 11 | import { UserRole } from '../components/room/UserRole'; |
13 | -import { UserStatus } from '../components/room/UserStatus'; | ||
14 | import SocketContext from '../contexts/SocketContext'; | 12 | import SocketContext from '../contexts/SocketContext'; |
15 | 13 | ||
16 | interface RoomLocation { | 14 | interface RoomLocation { |
... | @@ -40,9 +38,9 @@ export const Room: React.FC = () => { | ... | @@ -40,9 +38,9 @@ export const Room: React.FC = () => { |
40 | }, []); | 38 | }, []); |
41 | 39 | ||
42 | const handleUpdateRoomUser = useCallback((rawMessage: RawMessage) => { | 40 | const handleUpdateRoomUser = useCallback((rawMessage: RawMessage) => { |
43 | - if (rawMessage.type == MessageType.ROOM_USER_UPDATE) { | 41 | + if (rawMessage.type === MessageType.ROOM_USER_UPDATE) { |
44 | const data = rawMessage.message as UpdateRoomUser; | 42 | const data = rawMessage.message as UpdateRoomUser; |
45 | - if (data.state == 'removed') { | 43 | + if (data.state === 'removed') { |
46 | const newUsers = roomData.users; | 44 | const newUsers = roomData.users; |
47 | const index = newUsers.findIndex(x => x.username === data.user.username); | 45 | const index = newUsers.findIndex(x => x.username === data.user.username); |
48 | if (index < 0) { | 46 | if (index < 0) { |
... | @@ -81,7 +79,7 @@ export const Room: React.FC = () => { | ... | @@ -81,7 +79,7 @@ export const Room: React.FC = () => { |
81 | return () => { | 79 | return () => { |
82 | socket.off('msg', handleUpdateRoomUser); | 80 | socket.off('msg', handleUpdateRoomUser); |
83 | } | 81 | } |
84 | - }, [roomData]); | 82 | + }, [handleUpdateRoomUser]); |
85 | 83 | ||
86 | useEffect(() => { | 84 | useEffect(() => { |
87 | // 비정상적인 루트로 방을 들어오면 로그인 화면으로 푸시 | 85 | // 비정상적인 루트로 방을 들어오면 로그인 화면으로 푸시 |
... | @@ -102,7 +100,7 @@ export const Room: React.FC = () => { | ... | @@ -102,7 +100,7 @@ export const Room: React.FC = () => { |
102 | } | 100 | } |
103 | socket.emit('msg', rawMessage, (response : MessageResponse<undefined>) => {}); | 101 | socket.emit('msg', rawMessage, (response : MessageResponse<undefined>) => {}); |
104 | } | 102 | } |
105 | - }, []) | 103 | + }, [location.state]); |
106 | 104 | ||
107 | return ( | 105 | return ( |
108 | <Main> | 106 | <Main> | ... | ... |
-
Please register or login to post a comment