From e09d0892f051426d10118a2536df3b6e1fa4510b Mon Sep 17 00:00:00 2001 From: Mikael Lindlof Date: Sun, 13 Dec 2020 20:56:27 +0000 Subject: [PATCH] Go to active game if available when leaving --- web/src/App.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index c46ce42..4d40831 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -52,7 +52,7 @@ export const App: React.FC = () => { playHandsign={(handsign: Msg.Handsign) => playHandsign(client, game, handsign, setGame, enqueueSnackbar) } - leaveGame={() => setGame(undefined)} + leaveGame={() => leaveGame(setGame, loadGame)} claimInactivity={() => claimInactivity(client, game, setGame, enqueueSnackbar)} enqueueSnackbar={enqueueSnackbar} /> @@ -217,4 +217,13 @@ const claimInactivity = async ( } }; +const leaveGame = async (setGame: Function, loadGame: () => Game.Game | undefined) => { + const currentGame = loadGame(); + if (currentGame && currentGame.stage !== Game.Stage.Over) { + setGame(currentGame); + } else { + setGame(undefined); + } +}; + export default App;