Overnap

handleUpdateRoomUser에 state가 updated인 경우 추가

......@@ -31,7 +31,6 @@ export const Room: React.FC = () => {
const handleUpdateRoomUser = useCallback((rawMessage: RawMessage) => {
if (rawMessage.type == MessageType.ROOM_USER_UPDATE) {
const data = rawMessage.message as UpdateRoomUser;
console.log(data);
if (data.state == 'removed') {
const newUsers = roomData.users;
const index = newUsers.indexOf(data.user);
......@@ -44,7 +43,19 @@ export const Room: React.FC = () => {
...roomData,
users: newUsers
});
} else if (data.state == 'added') {
} else if (data.state === 'updated') {
const newUsers = roomData.users;
const index = newUsers.findIndex(x => x.username === data.user.username);
if (index < 0) {
console.log('존재하지 않는 유저를 업데이트 시도');
} else {
newUsers[index] = data.user;
}
setRoomData({
...roomData,
users: newUsers
})
} else {
setRoomData({
...roomData,
users: [data.user, ...roomData.users]
......