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-08 05:01:44 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9505f11acd86137ac6f02f2889ee61e3e9a975f4
9505f11a
1 parent
0e48b198
Builds for 1 pipeline
failed
in 1 minute 33 seconds
handleUpdateRoomUser가 실시간 반영되도록 수정
Changes
1
Builds
3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
11 deletions
web/src/components/room/RoomInfo.tsx
web/src/components/room/RoomInfo.tsx
View file @
9505f11
...
...
@@ -23,12 +23,8 @@ export const RoomInfo: React.FC = () => {
const handleUpdateRoomUser = useCallback((rawMessage: RawMessage) => {
if (rawMessage.type == MessageType.ROOM_USER_UPDATE) {
const data = rawMessage.message as UpdateRoomUser;
if (data.state == 'added') {
setRoomData({
...roomData,
users: [data.user, ...roomData.users] // TODO: immutable.js로 바꾸면 좋을 듯
});
} else if (data.state == 'removed') {
console.log(data);
if (data.state == 'removed') {
const newUsers = roomData.users;
const index = newUsers.indexOf(data.user);
if (index < 0) {
...
...
@@ -40,24 +36,34 @@ export const RoomInfo: React.FC = () => {
...roomData,
users: newUsers
});
} else if (data.state == 'added') {
setRoomData({
...roomData,
users: [data.user, ...roomData.users]
});
}
}
}, []);
}, [
roomData
]);
useEffect(() => {
setRoomData(location.state.roomData);
socket.on('msg', handleUpdateRoomUser);
return () => {
socket.off('msg', handleUpdateRoomUser);
}
}, [roomData]);
useEffect(() => {
setRoomData(location.state.roomData);
return () => {
const rawMessage: RawMessage = {
type: MessageType.ROOM_LEAVE,
message: ''
}
socket.emit('msg', rawMessage, (response : MessageResponse<undefined>) => {});
}
}, [])
;
}, [])
return (
<div className='m-3 w-5/6 flex items-center place-content-between'>
...
...
Please
register
or
login
to post a comment