Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강동현
/
nodejs-game
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Overnap
2021-06-10 07:18:32 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d71b490f49ec73f50cbe7bbe2b4f0cc971a84500
d71b490f
1 parent
f0c04847
정답을 맞춘 효과 추가
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
web/src/components/room/Chat.tsx
web/src/components/room/GameBoard.tsx
web/src/components/room/Chat.tsx
View file @
d71b490
...
...
@@ -23,9 +23,11 @@ export const Chat: React.FC<ChatProps> = (props) => {
}
socket.on('msg', handleChatData);
socket.on('msg', handleAcceptMessage);
return () => {
socket.off('msg', handleChatData);
socket.off('msg', handleAcceptMessage);
}
}, []);
...
...
@@ -47,6 +49,16 @@ export const Chat: React.FC<ChatProps> = (props) => {
}
}, [input]);
const handleAcceptMessage = useCallback((rawMessage: RawMessage) => {
if (rawMessage.type === MessageType.GAME_ACCEPT) {
const message: ChatData = {
sender: 'SYSTEM',
message: 'That\'s correct!'
};
setChatLines(oldChatLines => [...oldChatLines, message]);
}
}, []);
return (
<div className={props.w}>
<div className={`${props.h} w-full py-2 rounded shadow flex flex-col overflow-y-scroll`}>
...
...
web/src/components/room/GameBoard.tsx
View file @
d71b490
...
...
@@ -55,15 +55,24 @@ export const GameBoard: React.FC<GameBoardProps> = ({ isInGame }) => {
}
}, [wordChosen]);
const handleAnswer = useCallback((rawMessage: RawMessage) => {
if (rawMessage.type === MessageType.GAME_ACCEPT) {
const { answer } = rawMessage.message as { answer: string };
setWordChosen(answer);
}
}, []);
useEffect(() => {
socket.on('msg', handleStart);
socket.on('msg', handleGetWordLength);
socket.on('msg', handleWordSet);
socket.on('msg', handleAnswer);
return () => {
socket.off('msg', handleStart);
socket.off('msg', handleGetWordLength);
socket.off('msg', handleWordSet);
socket.off('msg', handleAnswer);
}
}, []);
...
...
Please
register
or
login
to post a comment