diff --git a/src/sections/analysis/reviewPanelToolbar/saveButton.tsx b/src/sections/analysis/reviewPanelToolbar/saveButton.tsx index eafacf2..33c98ef 100644 --- a/src/sections/analysis/reviewPanelToolbar/saveButton.tsx +++ b/src/sections/analysis/reviewPanelToolbar/saveButton.tsx @@ -3,33 +3,38 @@ import { Icon } from "@iconify/react"; import { IconButton } from "@mui/material"; import { useAtomValue } from "jotai"; import { useRouter } from "next/router"; -import { gameAtom } from "../states"; +import { gameAtom, gameEvalAtom } from "../states"; export default function SaveButton() { const game = useAtomValue(gameAtom); - const { addGame } = useGameDatabase(); + const gameEval = useAtomValue(gameEvalAtom); + const { addGame, setGameEval } = useGameDatabase(); const router = useRouter(); const { gameId } = router.query; const isButtonEnabled = router.isReady && typeof gameId === undefined; + const handleSave = async () => { + if (!isButtonEnabled) return; + + const gameId = await addGame(game); + if (gameEval) { + await setGameEval(gameId, gameEval); + } + + router.replace( + { + query: { gameId: gameId }, + pathname: router.pathname, + }, + undefined, + { shallow: true, scroll: false } + ); + }; + return ( - { - if (!isButtonEnabled) return; - const gameId = await addGame(game); - router.replace( - { - query: { gameId: gameId }, - pathname: router.pathname, - }, - undefined, - { shallow: true, scroll: false } - ); - }} - disabled={!isButtonEnabled} - > + );