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 { IconButton } from "@mui/material";
import { useAtomValue } from "jotai"; import { useAtomValue } from "jotai";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { gameAtom } from "../states"; import { gameAtom, gameEvalAtom } from "../states";
export default function SaveButton() { export default function SaveButton() {
const game = useAtomValue(gameAtom); const game = useAtomValue(gameAtom);
const { addGame } = useGameDatabase(); const gameEval = useAtomValue(gameEvalAtom);
const { addGame, setGameEval } = useGameDatabase();
const router = useRouter(); const router = useRouter();
const { gameId } = router.query; const { gameId } = router.query;
const isButtonEnabled = router.isReady && typeof gameId === undefined; const isButtonEnabled = router.isReady && typeof gameId === undefined;
return ( const handleSave = async () => {
<IconButton
onClick={async () => {
if (!isButtonEnabled) return; if (!isButtonEnabled) return;
const gameId = await addGame(game); const gameId = await addGame(game);
if (gameEval) {
await setGameEval(gameId, gameEval);
}
router.replace( router.replace(
{ {
query: { gameId: gameId }, query: { gameId: gameId },
@@ -27,9 +31,10 @@ export default function SaveButton() {
undefined, undefined,
{ shallow: true, scroll: false } { shallow: true, scroll: false }
); );
}} };
disabled={!isButtonEnabled}
> return (
<IconButton onClick={handleSave} disabled={!isButtonEnabled}>
<Icon icon="ri:save-3-line" /> <Icon icon="ri:save-3-line" />
</IconButton> </IconButton>
); );