Skip to content

Commit

Permalink
Go to active game if available when leaving
Browse files Browse the repository at this point in the history
  • Loading branch information
lindlof committed Dec 13, 2020
1 parent 4c835a6 commit e09d089
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
/>
Expand Down Expand Up @@ -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;

0 comments on commit e09d089

Please sign in to comment.