Skip to content

Commit c75a549

Browse files
Lobby.tsx에 화면 전환 훅 추가
1 parent 9f1f689 commit c75a549

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/app/Lobby/Lobby.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ export default function Lobby() {
2222
const userRef = ref(db, 'rooms/' + invitationCode + '/players/' + myUserId);
2323
void onDisconnect(userRef).remove();
2424
}, []);
25+
useEffect(() => {
26+
if (!invitationCode) return;
27+
const roomRef = ref(db, 'rooms/' + invitationCode);
28+
const unsubscribe = onValue(roomRef, (snapshot) => {
29+
const roomData = snapshot.val();
30+
if (roomData && roomData.status === 'playing')
31+
router.push(`/game/${invitationCode}`);
32+
});
33+
return () => {
34+
unsubscribe();
35+
};
36+
}, [invitationCode, router]);
2537
return (
2638
<Container component="main" maxWidth="xs">
2739
<Box

0 commit comments

Comments
 (0)