+
diff --git a/hooks/useChat.ts b/hooks/useChat.ts
index 7770dc1f..1e4614a9 100644
--- a/hooks/useChat.ts
+++ b/hooks/useChat.ts
@@ -1,4 +1,4 @@
-import { useEffect, useState } from "react";
+import { useCallback, useEffect, useState } from "react";
import type { MessageType } from "@/components/shared/Chat/v2/ChatMessages";
import useChatroom from "./context/useChatroom";
import useSocketCore from "./context/useSocketCore";
@@ -17,6 +17,10 @@ export default function useChat() {
setIsChatVisible((prev) => !prev);
};
+ const openChat = useCallback(() => {
+ setIsChatVisible(true);
+ }, []);
+
// join chatroom by roomId
useEffect(() => {
if (!roomId) return;
@@ -48,6 +52,7 @@ export default function useChat() {
roomId,
messageList,
isChatVisible,
+ openChat,
sendChatMessage,
toggleChatVisibility,
handleSubmitText,
diff --git a/hooks/useUser.ts b/hooks/useUser.ts
index 6fca55d4..5c654828 100644
--- a/hooks/useUser.ts
+++ b/hooks/useUser.ts
@@ -58,13 +58,16 @@ const useUser = () => {
return roomIdOperator.get();
};
- const updateRoomId = (roomId?: string) => {
- if (roomId) {
- roomIdOperator.set(roomId);
- } else {
- roomIdOperator.remove();
- }
- };
+ const updateRoomId = useCallback(
+ (roomId?: string) => {
+ if (roomId) {
+ roomIdOperator.set(roomId);
+ } else {
+ roomIdOperator.remove();
+ }
+ },
+ [roomIdOperator]
+ );
return {
getLoginEndpoint,
diff --git a/pages/_document.tsx b/pages/_document.tsx
index 22632ceb..ed031e8b 100644
--- a/pages/_document.tsx
+++ b/pages/_document.tsx
@@ -12,7 +12,7 @@ export default function Document() {
-
+
diff --git a/pages/auth/token/[token].tsx b/pages/auth/token/[token].tsx
index 75531572..837e1b70 100644
--- a/pages/auth/token/[token].tsx
+++ b/pages/auth/token/[token].tsx
@@ -18,7 +18,7 @@ const Token: NextPageWithProps = () => {
}
}, [token, login, push]);
- return
{token}
;
+ return <>>;
};
Token.getLayout = (page: ReactElement) => page;
diff --git a/pages/index.tsx b/pages/index.tsx
index 5f67e110..91ae05fb 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -71,7 +71,7 @@ function CarouselCard({
draggable={false}
priority
fill
- objectFit="cover"
+ className="object-cover"
onError={onImageError}
/>
@@ -106,7 +106,7 @@ function CarouselCard({
draggable={false}
priority
fill
- objectFit="cover"
+ className="object-cover"
onError={onImageError}
/>
)}
@@ -181,12 +181,12 @@ const TabPaneContent = ({
>
diff --git a/pages/rooms/[roomId]/index.tsx b/pages/rooms/[roomId]/index.tsx
index b0ae9c3f..f859f768 100644
--- a/pages/rooms/[roomId]/index.tsx
+++ b/pages/rooms/[roomId]/index.tsx
@@ -1,6 +1,7 @@
-import { useEffect, useState } from "react";
-import { useRouter } from "next/router";
+import { ReactEventHandler, useEffect, useState } from "react";
import { GetStaticProps, GetStaticPaths } from "next";
+import { useRouter } from "next/router";
+import Image from "next/image";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import RoomUserCardList from "@/components/rooms/RoomUserCardList";
import RoomButtonGroup from "@/components/rooms/RoomButtonGroup";
@@ -22,10 +23,18 @@ import {
playerCancelReady,
startGame,
} from "@/requests/rooms";
+import { GameType, getAllGamesEndpoint } from "@/requests/games";
import useUser from "@/hooks/useUser";
+import gameDefaultCoverImg from "@/public/images/game-default-cover.png";
type User = Omit
;
+const onImageError: ReactEventHandler = (e) => {
+ if (e.target instanceof HTMLImageElement) {
+ e.target.src = gameDefaultCoverImg.src;
+ }
+};
+
export default function Room() {
const {
roomInfo,
@@ -44,16 +53,27 @@ export default function Room() {
const { fetch } = useRequest();
const { query, replace } = useRouter();
const [gameUrl, setGameUrl] = useState("");
+ const [gameList, setGameList] = useState([]);
const roomId = query.roomId as string;
const player = roomInfo.players.find(
(player) => player.id === currentUser?.id
);
const isHost = roomInfo.host.id === currentUser?.id;
+ const gameInfo = gameList.find((game) => game.id === roomInfo.game.id);
+
+ useEffect(() => {
+ fetch(getAllGamesEndpoint()).then(setGameList);
+ }, [fetch]);
useEffect(() => {
async function getRoomInfo() {
- const roomInfo = await fetch(getRoomInfoEndpoint(roomId));
- initializeRoom(roomInfo);
+ try {
+ const roomInfo = await fetch(getRoomInfoEndpoint(roomId));
+ initializeRoom(roomInfo);
+ } catch (err) {
+ updateRoomId();
+ replace("/rooms");
+ }
}
getRoomInfo();
@@ -119,6 +139,7 @@ export default function Room() {
socket,
currentUser?.id,
roomId,
+ updateRoomId,
addPlayer,
removePlayer,
updateUserReadyStatus,
@@ -211,40 +232,54 @@ export default function Room() {
};
return (
-
-
-
+ {gameUrl ? (
+
-
-
-
-
-
- {roomInfo.isLocked ? "非公開" : "公開"}
-
-
- {roomInfo.currentPlayers} / {roomInfo.maxPlayers} 人
-
-
-
+
+ {roomInfo.currentPlayers && (
+
+ )}
+
+
+
+
+
+ {roomInfo.isLocked ? "非公開" : "公開"}
+
+
+ {roomInfo.currentPlayers} / {roomInfo.maxPlayers} 人
+
+
+
+
+
+
-
-
-
- {gameUrl && }
+ >
+ )}
);
diff --git a/styles/global.css b/styles/global.css
index b5c61c95..83cb701b 100644
--- a/styles/global.css
+++ b/styles/global.css
@@ -1,3 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
+
+html {
+ color-scheme: dark;
+}