From 871428b6baeb28daf2f29e5b5a29ad3d30e1275c Mon Sep 17 00:00:00 2001 From: Hurhaj Date: Sun, 22 Oct 2023 14:15:41 +0200 Subject: [PATCH] Added callback for clearing the input after game was saved aswell as adjusting the existing onCloseModal to not clear the name after modal was canceled. --- client/components/AddGameInput.tsx | 9 ++++++++- client/components/AddGameModal.tsx | 11 +++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/client/components/AddGameInput.tsx b/client/components/AddGameInput.tsx index cfd4272e..512d6d9b 100644 --- a/client/components/AddGameInput.tsx +++ b/client/components/AddGameInput.tsx @@ -7,6 +7,7 @@ import { useGamesContext } from '../providers/GamesProvider'; import { useNotificationContext } from '../providers/NotificationProvider'; import { useAction } from '../util/useAction'; import { AddGameModal } from './AddGameModal'; +import { clear } from 'console'; export const AddGameInput: React.FC = () => { const { removeNotificationsForInfoSource } = useNotificationContext(); @@ -37,11 +38,17 @@ export const AddGameInput: React.FC = () => { }, [searchGame, name]); const onCloseModal = useCallback(() => { + setGameId(null); + onClose(); + }, [onClose]); + + const onSaveModal = useCallback(() => { setGameId(null); setName(''); onClose(); }, [onClose]); + const currentGame = useMemo(() => games.find(game => game.id === gameId), [games, gameId]); return ( @@ -75,7 +82,7 @@ export const AddGameInput: React.FC = () => { removeGame={removeGame} removeNotificationsForInfoSource={removeNotificationsForInfoSource} > - + } diff --git a/client/components/AddGameModal.tsx b/client/components/AddGameModal.tsx index 4fb550c4..0ef2776e 100644 --- a/client/components/AddGameModal.tsx +++ b/client/components/AddGameModal.tsx @@ -25,7 +25,7 @@ import { AddInfoSource } from './InfoSource/AddInfoSource'; import { InfoSourcePreview } from './InfoSource/InfoSourcePreview'; import { LoadingSpinner } from './LoadingSpinner'; -export const AddGameModal: React.FC = ({ show, onClose }) => { +export const AddGameModal: React.FC void}> = ({ show, onClose , onSave}) => { const { game, } = useGameContext(); return ( @@ -56,7 +56,7 @@ export const AddGameModal: React.FC = ({ show, onClose }) => { { game.syncing ? - : + : } @@ -115,7 +115,7 @@ const AddGameLoadingScreen: React.FC<{ onClose: () => void }> = ({ onClose }) => ); }; -const SetupGameForm: React.FC<{ onClose: () => void }> = ({ onClose }) => { +const SetupGameForm: React.FC<{ onClose: () => void; onSave: () => void }> = ({ onClose, onSave }) => { const { user: { interestedInSources } } = useUserContext(); const { game, @@ -228,7 +228,10 @@ const SetupGameForm: React.FC<{ onClose: () => void }> = ({ onClose }) => { colorScheme="teal" isLoading={loading} disabled={loading || game.syncing} - onClick={() => onAdd({ name, continueSearching })} + onClick={() => { + onAdd({ name, continueSearching }); + onSave(); + }} > Save