|
@@ -1,6 +1,7 @@
|
|
|
import { PRE_GAME, PRE_ROUND, IN_ROUND, POST_ROUND, POST_GAME } from "./GameState";
|
|
|
import { createStore } from "../store";
|
|
|
import { joinGame, sendGuess } from "./apiMethods";
|
|
|
+import { saveGameInfoToLocalStorage, clearGameInfoFromLocalStorage } from "./localStorageMethods";
|
|
|
|
|
|
export const [
|
|
|
{
|
|
@@ -37,7 +38,14 @@ export const [
|
|
|
const name = get.playerName();
|
|
|
const { playerId } = await joinGame(gameId, name);
|
|
|
set({ playerId });
|
|
|
+ saveGameInfoToLocalStorage(gameId, name, playerId);
|
|
|
},
|
|
|
+ rejoinGame: ([set], gameId, playerName, playerId) => set({
|
|
|
+ gameId,
|
|
|
+ playerName,
|
|
|
+ playerId,
|
|
|
+ gameState: IN_ROUND,
|
|
|
+ }),
|
|
|
startRound: ([set]) => set({ gameState: IN_ROUND }),
|
|
|
submitGuess: async ([set, get], selectedPoint, roundNum, targetPoint) => {
|
|
|
const { score, totalScore } = await sendGuess(
|
|
@@ -56,8 +64,11 @@ export const [
|
|
|
gameState: POST_ROUND,
|
|
|
});
|
|
|
},
|
|
|
- goToSummary: ([set, get], gameId) => set({
|
|
|
- gameId: gameId || get.gameId(),
|
|
|
- gameState: POST_GAME,
|
|
|
- }),
|
|
|
+ goToSummary: ([set, get], gameId) => {
|
|
|
+ clearGameInfoFromLocalStorage();
|
|
|
+ set({
|
|
|
+ gameId: gameId || get.gameId(),
|
|
|
+ gameState: POST_GAME,
|
|
|
+ });
|
|
|
+ },
|
|
|
});
|