From 4aac061ec2dd0991cad229c2d7e9581debeb7b93 Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Sun, 10 Nov 2024 19:59:01 +0800 Subject: [PATCH] fix: sonar cloud issue and build error --- components/rooms/RoomButtonGroup.tsx | 2 -- components/shared/Breadcrumb/index.tsx | 2 +- components/shared/Button/Button.tsx | 2 +- features/game/contexts/index.ts | 4 ++-- features/room/components/JoinLockRoomForm.tsx | 12 +++++++++--- features/room/components/RoomCard.tsx | 2 +- features/room/hooks/useJoinRoom.ts | 2 +- features/user/components/UserCard.tsx | 2 +- pages/auth/login.tsx | 2 +- pages/auth/token/[token].tsx | 2 +- pages/index.tsx | 2 +- pages/rooms/[roomId]/index.tsx | 2 -- pages/rooms/index.tsx | 2 +- pages/without-layout.tsx | 3 +-- 14 files changed, 21 insertions(+), 20 deletions(-) diff --git a/components/rooms/RoomButtonGroup.tsx b/components/rooms/RoomButtonGroup.tsx index 40b470f0..33ff1416 100644 --- a/components/rooms/RoomButtonGroup.tsx +++ b/components/rooms/RoomButtonGroup.tsx @@ -3,8 +3,6 @@ import Icon from "../shared/Icon"; type RoomButtonGroupProps = { isHost: boolean; - isReady: boolean; - onToggleReady: () => void; onClickLeave: () => void; onClickClose: () => void; onClickStart: () => void; diff --git a/components/shared/Breadcrumb/index.tsx b/components/shared/Breadcrumb/index.tsx index 40f2f8fd..45936ce3 100644 --- a/components/shared/Breadcrumb/index.tsx +++ b/components/shared/Breadcrumb/index.tsx @@ -1,2 +1,2 @@ -export { default as Breadcrumb } from "./Breadcrumb"; +export { default } from "./Breadcrumb"; export * from "./Breadcrumb"; diff --git a/components/shared/Button/Button.tsx b/components/shared/Button/Button.tsx index 30041fc4..06ff21d0 100644 --- a/components/shared/Button/Button.tsx +++ b/components/shared/Button/Button.tsx @@ -116,7 +116,7 @@ const InteralButton = ( "relative px-4 py-1.5 inline-flex items-center gap-1.5 rounded-lg shadow-md text-white/90 focus:outline-8 transition-[box-shadow,background,opacity] ease-in", buttonVariants[variant], (disabled || loading) && - "opacity-70 pointer-events-none select-none text-gray-200", + "opacity-70 pointer-events-none select-none text-grey-200", active && buttonVariants[`${variant}_active`], className ); diff --git a/features/game/contexts/index.ts b/features/game/contexts/index.ts index e0219f75..90198f7d 100644 --- a/features/game/contexts/index.ts +++ b/features/game/contexts/index.ts @@ -1,2 +1,2 @@ -export { default as GameListProvider } from "./gameList"; -export * from "./gameList"; +export { default as GameListProvider } from "./GameList"; +export * from "./GameList"; diff --git a/features/room/components/JoinLockRoomForm.tsx b/features/room/components/JoinLockRoomForm.tsx index fb7953f5..4f9f1136 100644 --- a/features/room/components/JoinLockRoomForm.tsx +++ b/features/room/components/JoinLockRoomForm.tsx @@ -1,4 +1,6 @@ +import { AxiosError } from "axios"; import { FormEvent, PropsWithChildren, useState } from "react"; +import { useTranslation } from "react-i18next"; import { Button } from "@/components/shared/Button/v2"; import Icon from "@/components/shared/Icon"; import InputOTP from "@/components/shared/InputOTP"; @@ -8,7 +10,8 @@ interface JoinLockRoomFormProps extends PropsWithChildren { id: string; } -function JoinLockRoomForm({ id, children }: JoinLockRoomFormProps) { +function JoinLockRoomForm({ id, children }: Readonly) { + const { t } = useTranslation("rooms"); const { handleJoinRoom } = useJoinRoom(id); const [password, setPassword] = useState(""); const [errorMessage, setErrorMessage] = useState(""); @@ -24,8 +27,11 @@ function JoinLockRoomForm({ id, children }: JoinLockRoomFormProps) { try { await handleJoinRoom(password); } catch (error) { - if (typeof error === "string") { - setErrorMessage(error); + /// 待調整重構 + if (error instanceof AxiosError) { + const msg = error.response?.data.message.replaceAll(" ", "_"); + if (!msg) return; + setErrorMessage(t(msg)); } } }; diff --git a/features/room/components/RoomCard.tsx b/features/room/components/RoomCard.tsx index 40a1894b..0557e59d 100644 --- a/features/room/components/RoomCard.tsx +++ b/features/room/components/RoomCard.tsx @@ -9,7 +9,7 @@ interface RoomsCardProps { onClick: () => void; } -function RoomCard({ room, onClick }: RoomsCardProps) { +function RoomCard({ room, onClick }: Readonly) { const { handleJoinRoom } = useJoinRoom(room.id); const lackTotalPlayers = room.maxPlayers - room.currentPlayers; diff --git a/features/room/hooks/useJoinRoom.ts b/features/room/hooks/useJoinRoom.ts index 4019447a..4da7503b 100644 --- a/features/room/hooks/useJoinRoom.ts +++ b/features/room/hooks/useJoinRoom.ts @@ -38,7 +38,7 @@ function useJoinRoom(id: string) { const msg = err.response?.data.message.replaceAll(" ", "_"); if (!msg) return toast({ children: "error!", state: "error" }); toast({ children: t(msg), state: "error" }); - return Promise.reject(t(msg)); + throw err; } } finally { setIsLoading(false); diff --git a/features/user/components/UserCard.tsx b/features/user/components/UserCard.tsx index aefadc2c..b2590606 100644 --- a/features/user/components/UserCard.tsx +++ b/features/user/components/UserCard.tsx @@ -14,7 +14,7 @@ interface IUserRole { text: string; } -function UserCard({ id, nickname, isSelf, isHost }: UserCardProps) { +function UserCard({ id, nickname, isSelf, isHost }: Readonly) { if (!id) { return ; } diff --git a/pages/auth/login.tsx b/pages/auth/login.tsx index e0a9329a..de6d18a9 100644 --- a/pages/auth/login.tsx +++ b/pages/auth/login.tsx @@ -1,4 +1,4 @@ -import { ReactElement, useEffect } from "react"; +import { useEffect } from "react"; import { useRouter } from "next/router"; import { GetStaticProps } from "next"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; diff --git a/pages/auth/token/[token].tsx b/pages/auth/token/[token].tsx index 3bab0053..dd0f99b1 100644 --- a/pages/auth/token/[token].tsx +++ b/pages/auth/token/[token].tsx @@ -1,4 +1,4 @@ -import { ReactElement, useEffect } from "react"; +import { useEffect } from "react"; import { useRouter } from "next/router"; import { GetStaticProps, GetStaticPaths } from "next"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; diff --git a/pages/index.tsx b/pages/index.tsx index e9b0e9f1..9bd84dec 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -29,7 +29,7 @@ function CarouselCard({ ); } -function TabPaneContent({ tabKey }: TabItemType) { +function TabPaneContent({ tabKey }: Readonly>) { const gameList = useGameList(); if ([TabKey.HOT, TabKey.NEW].includes(tabKey)) { diff --git a/pages/rooms/[roomId]/index.tsx b/pages/rooms/[roomId]/index.tsx index 09527c58..05a276d2 100644 --- a/pages/rooms/[roomId]/index.tsx +++ b/pages/rooms/[roomId]/index.tsx @@ -273,12 +273,10 @@ export default function Room() {
diff --git a/pages/rooms/index.tsx b/pages/rooms/index.tsx index e783c1ef..4ef2bc59 100644 --- a/pages/rooms/index.tsx +++ b/pages/rooms/index.tsx @@ -11,7 +11,7 @@ import usePagination from "@/hooks/usePagination"; import useRequest from "@/hooks/useRequest"; import { Room, RoomType, getRooms } from "@/requests/rooms"; -function TabPaneContent({ tabKey }: TabItemType) { +function TabPaneContent({ tabKey }: Readonly>) { const { fetch } = useRequest(); const gameList = useGameList(); const [room, setRoom] = useState(null); diff --git a/pages/without-layout.tsx b/pages/without-layout.tsx index 9eaa6745..4d2a5ab5 100644 --- a/pages/without-layout.tsx +++ b/pages/without-layout.tsx @@ -1,4 +1,3 @@ -import { ReactElement } from "react"; import { NextPageWithProps } from "./_app"; import Button from "@/components/shared/Button"; import Link from "next/link"; @@ -14,7 +13,7 @@ const WithoutLayout: NextPageWithProps = () => { ); }; -WithoutLayout.getLayout = (page: ReactElement) => page; +WithoutLayout.getLayout = ({ children }) => children; WithoutLayout.Anonymous = true; export default WithoutLayout;