Skip to content

Commit

Permalink
Add toast for game log (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
takumihara authored Mar 5, 2024
1 parent f3fb2d3 commit de69dcb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/app/lib/hooks/game/useGameSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -59,6 +60,7 @@ export default function useGameSocket(
currentUser?: UserEntity,
) {
const socketRef = useRef<Socket | null>(null); // updated on `id` change
const { toast } = useToast();

const start = useCallback(() => {
if (!userMode) return;
Expand Down Expand Up @@ -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}`);
Expand Down

0 comments on commit de69dcb

Please sign in to comment.