fix : save eval on game save

This commit is contained in:
GuillaumeSD
2024-02-23 04:06:07 +01:00
parent 814d3ecf09
commit f77a425067

View File

@@ -3,22 +3,26 @@ 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;
return (
<IconButton
onClick={async () => {
const handleSave = async () => {
if (!isButtonEnabled) return;
const gameId = await addGame(game);
if (gameEval) {
await setGameEval(gameId, gameEval);
}
router.replace(
{
query: { gameId: gameId },
@@ -27,9 +31,10 @@ export default function SaveButton() {
undefined,
{ shallow: true, scroll: false }
);
}}
disabled={!isButtonEnabled}
>
};
return (
<IconButton onClick={handleSave} disabled={!isButtonEnabled}>
<Icon icon="ri:save-3-line" />
</IconButton>
);