From de69dcb2647ce2ccac02ec9672f27c8daf8c1b0f Mon Sep 17 00:00:00 2001 From: Takumi Hara <69781798+takumihara@users.noreply.github.com> Date: Mon, 4 Mar 2024 23:17:07 -0600 Subject: [PATCH] Add toast for game log (#296) --- frontend/app/lib/hooks/game/useGameSocket.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/app/lib/hooks/game/useGameSocket.ts b/frontend/app/lib/hooks/game/useGameSocket.ts index d822002d..02d52ae4 100644 --- a/frontend/app/lib/hooks/game/useGameSocket.ts +++ b/frontend/app/lib/hooks/game/useGameSocket.ts @@ -4,6 +4,7 @@ import { Socket, io } from "socket.io-client"; import { UserMode } from "../useUserMode"; import { UserEntity } from "../../dtos"; import { POINT_TO_WIN } from "@/app/pong/[id]/const"; +import { useToast } from "@/components/ui/use-toast"; type Status = | "too-many-players" @@ -59,6 +60,7 @@ export default function useGameSocket( currentUser?: UserEntity, ) { const socketRef = useRef(null); // updated on `id` change + const { toast } = useToast(); const start = useCallback(() => { if (!userMode) return; @@ -151,6 +153,10 @@ export default function useGameSocket( runSideEffectForStatusUpdate(status, payload); const log = getLogFromStatus(status); setLogs((logs) => [...logs, log]); + toast({ + title: "Game Log", + description: log, + }); }; const handleConnect = () => { console.log(`Connected: ${socketRef.current?.id}`);