diff --git a/src/AppRoutes.tsx b/src/AppRoutes.tsx index 26085ee..4a758d6 100644 --- a/src/AppRoutes.tsx +++ b/src/AppRoutes.tsx @@ -5,11 +5,9 @@ import { Route, Routes } from 'react-router-dom'; import { useSetRecoilState } from 'recoil'; import { nextStepLoadingState } from './atoms/nextStepLoadingState'; import SkipAutoInterceptor from './interceptors/SkipAutoInterceptor'; -import GameSaveScreen from './screens/GameSaveScreen'; import HistoryScreen from './screens/HistoryScreen'; import LoadingScreen from './screens/LoadingScreen'; import MainMenu from './screens/MainMenu'; -import SaveLoadAlert from './screens/modals/SaveLoadAlert'; import TextInput from './screens/modals/TextInput'; import NarrationScreen from './screens/NarrationScreen'; import QuickTools from './screens/QuickTools'; @@ -50,8 +48,6 @@ export default function AppRoutes() { - - + + ) diff --git a/src/screens/GameSaveScreen.tsx b/src/screens/GameSaveScreen.tsx index c874e41..f93b955 100644 --- a/src/screens/GameSaveScreen.tsx +++ b/src/screens/GameSaveScreen.tsx @@ -8,6 +8,7 @@ import { Pagination, Tooltip, useMediaQuery } from '@mui/material'; import { useQueryClient } from '@tanstack/react-query'; import { useSnackbar } from 'notistack'; import { useTranslation } from 'react-i18next'; +import { useLocation } from 'react-router-dom'; import { useRecoilState, useSetRecoilState } from 'recoil'; import { openGameSaveScreenState } from '../atoms/openGameSaveScreenState'; import { saveLoadAlertState } from '../atoms/saveLoadAlertState'; @@ -29,6 +30,7 @@ export default function GameSaveScreen() { const navigate = useMyNavigate(); const { enqueueSnackbar } = useSnackbar(); const queryClient = useQueryClient() + let location = useLocation(); return ( { downloadGameSave() }} + disabled={location.pathname == "/"} > @@ -131,6 +134,7 @@ function GameSaveSlot({ saveId, onDelete, onLoad, onOverwriteSave, onSave }: { data: saveData, isError, } = useQuerySaves({ id: saveId }) + let location = useLocation(); if (isLoading) { return ( @@ -160,6 +164,7 @@ function GameSaveSlot({ saveId, onDelete, onLoad, onOverwriteSave, onSave }: { width: "100%", }} onClick={onSave} + disabled={location.pathname == "/"} > diff --git a/src/screens/MainMenu.tsx b/src/screens/MainMenu.tsx index a0ed236..5ac366a 100644 --- a/src/screens/MainMenu.tsx +++ b/src/screens/MainMenu.tsx @@ -7,20 +7,24 @@ import { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { useSetRecoilState } from 'recoil'; import { hideInterfaceState } from '../atoms/hideInterfaceState'; +import { openGameSaveScreenState } from '../atoms/openGameSaveScreenState'; import { openSettingsState } from '../atoms/openSettingsState'; import MenuButton from '../components/MenuButton'; import { INTERFACE_DATA_USE_QUEY_KEY } from '../use_query/useQueryInterface'; +import useQueryLastSave from '../use_query/useQueryLastSave'; import { useMyNavigate } from '../utilities/navigate-utility'; -import { loadGameSaveFromFile } from '../utilities/save-utility'; +import { loadSave } from '../utilities/save-utility'; export default function MainMenu() { const navigate = useMyNavigate(); const setOpenSettings = useSetRecoilState(openSettingsState); const setHideInterface = useSetRecoilState(hideInterfaceState); + const setGameSaveScreen = useSetRecoilState(openGameSaveScreenState); const { enqueueSnackbar } = useSnackbar(); const { t } = useTranslation(["interface"]); const { t: tNarration } = useTranslation(["narration"]); const queryClient = useQueryClient() + const { data: lastSave = null, isLoading } = useQueryLastSave() useEffect(() => { setHideInterface(false) @@ -45,6 +49,24 @@ export default function MainMenu() { animate={"open"} exit="closed" > + { + if (!lastSave) { + return + } + loadSave(lastSave, navigate) + .then(() => queryClient.invalidateQueries({ queryKey: [INTERFACE_DATA_USE_QUEY_KEY] })) + .catch((e) => { + enqueueSnackbar(t("fail_load"), { variant: 'error' }) + console.error(e) + }) + }} + transitionDelay={0.1} + loading={isLoading} + disabled={!isLoading && !lastSave} + > + {t("continue")} + { canvas.removeAll() @@ -55,21 +77,19 @@ export default function MainMenu() { notify: (message, variant) => enqueueSnackbar(message, { variant }), }).then(() => queryClient.invalidateQueries({ queryKey: [INTERFACE_DATA_USE_QUEY_KEY] })) }} - transitionDelay={0.1} + transitionDelay={0.2} > {t("start")} { - loadGameSaveFromFile(navigate, () => queryClient.invalidateQueries({ queryKey: [INTERFACE_DATA_USE_QUEY_KEY] })) - }} - transitionDelay={0.2} + onClick={() => setGameSaveScreen(true)} + transitionDelay={0.3} > {t("load")} { setOpenSettings(true) }} - transitionDelay={0.3} + onClick={() => setOpenSettings(true)} + transitionDelay={0.4} > {t("settings")} diff --git a/src/screens/modals/SaveLoadAlert.tsx b/src/screens/modals/SaveLoadAlert.tsx index 2d0bbf0..923a294 100644 --- a/src/screens/modals/SaveLoadAlert.tsx +++ b/src/screens/modals/SaveLoadAlert.tsx @@ -86,8 +86,9 @@ export default function SaveLoadAlert() { openGameSaveScreen(false) return true }) - .catch(() => { + .catch((e) => { enqueueSnackbar(t("fail_load"), { variant: 'error' }) + console.error(e) return false }) case "delete": @@ -98,8 +99,9 @@ export default function SaveLoadAlert() { enqueueSnackbar(t("success_delete"), { variant: 'success' }) return true }) - .catch(() => { + .catch((e) => { enqueueSnackbar(t("fail_delete"), { variant: 'error' }) + console.error(e) return false }) case "save": @@ -111,8 +113,9 @@ export default function SaveLoadAlert() { enqueueSnackbar(t("success_save"), { variant: 'success' }) return true }) - .catch(() => { + .catch((e) => { enqueueSnackbar(t("fail_save"), { variant: 'error' }) + console.error(e) return false }) } diff --git a/src/values/translations/strings_en.json b/src/values/translations/strings_en.json index fbc3262..487b38f 100644 --- a/src/values/translations/strings_en.json +++ b/src/values/translations/strings_en.json @@ -8,6 +8,7 @@ "back": "Back", "cancel": "Cancel", "confirm": "Confirm", + "continue": "Continue", "delete": "Delete", "dialogues": "Dialogues", "display": "Display",