@@ -141,7 +161,7 @@ export default function Home() {
diff --git a/pages/rooms/[roomId]/index.tsx b/pages/rooms/[roomId]/index.tsx
index ba8dfbbf..b0ae9c3f 100644
--- a/pages/rooms/[roomId]/index.tsx
+++ b/pages/rooms/[roomId]/index.tsx
@@ -22,6 +22,7 @@ import {
playerCancelReady,
startGame,
} from "@/requests/rooms";
+import useUser from "@/hooks/useUser";
type User = Omit;
@@ -38,6 +39,7 @@ export default function Room() {
} = useRoom();
const { socket } = useSocketCore();
const { currentUser, token } = useAuth();
+ const { updateRoomId } = useUser();
const { Popup, firePopup } = usePopup();
const { fetch } = useRequest();
const { query, replace } = useRouter();
@@ -70,6 +72,7 @@ export default function Room() {
socket.on(SOCKET_EVENT.USER_LEFT, ({ user }: { user: User }) => {
if (user.id === currentUser.id) {
+ updateRoomId();
firePopup({
title: `你已被踢出房間`,
onConfirm: () => replace("/"),
@@ -105,6 +108,7 @@ export default function Room() {
});
socket.on(SOCKET_EVENT.ROOM_CLOSED, () => {
+ updateRoomId();
firePopup({
title: `房間已關閉!`,
onConfirm: () => replace("/"),
@@ -149,6 +153,7 @@ export default function Room() {
try {
await fetch(closeRoom(roomId));
replace("/rooms");
+ updateRoomId();
} catch (err) {
firePopup({ title: "error!" });
}
@@ -167,6 +172,7 @@ export default function Room() {
try {
await fetch(leaveRoom(roomId));
replace("/rooms");
+ updateRoomId();
} catch (err) {
firePopup({ title: "error!" });
}