|
@@ -1,3 +1,4 @@
|
|
|
+import { getCurrentRound } from "./apiMethods";
|
|
|
|
|
|
const localStorageGameId = "terrassumptions:gameId";
|
|
|
const localStoragePlayerName = "terrassumptions:playerName";
|
|
@@ -11,11 +12,27 @@ const localStoragePanoLng = "terrassumptions:pano:lng";
|
|
|
const localStoragePanoHeading = "terrassumptions:pano:heading";
|
|
|
const localStoragePanoPitch = "terrassumptions:pano:pitch";
|
|
|
|
|
|
-export const hasSavedGameInfo = () => (
|
|
|
- localStorage.getItem(localStorageGameId) !== null &&
|
|
|
- localStorage.getItem(localStoragePlayerName) !== null &&
|
|
|
- localStorage.getItem(localStoragePlayerId) !== null
|
|
|
-)
|
|
|
+export const hasSavedGameInfo = async () => {
|
|
|
+ const gameId = localStorage.getItem(localStorageGameId);
|
|
|
+ if (gameId === null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const playerName = localStorage.getItem(localStoragePlayerName);
|
|
|
+ if (playerName === null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const playerId = localStorage.getItem(localStoragePlayerId);
|
|
|
+ if (playerId === null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ await getCurrentRound(gameId, playerId);
|
|
|
+ return true;
|
|
|
+ } catch (_) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
export const saveGameInfoToLocalStorage = (gameId, playerName, playerId) => {
|
|
|
localStorage.setItem(localStorageGameId, gameId);
|