From 6c8833feaeb55dd0600d3bd6ce4043f8ab18a255 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Fri, 23 Oct 2020 21:11:25 +1100 Subject: [PATCH] Added check that database is available before joining a game Fixes issue with joining a game already in progress on a browser with indexedDB disabled --- src/contexts/MapDataContext.js | 1 - src/routes/Game.js | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/contexts/MapDataContext.js b/src/contexts/MapDataContext.js index db92328..92488de 100644 --- a/src/contexts/MapDataContext.js +++ b/src/contexts/MapDataContext.js @@ -219,7 +219,6 @@ export function MapDataProvider({ children }) { } async function getMapFromDB(mapId) { - if (!database) return; return await database.table("maps").get(mapId); } diff --git a/src/routes/Game.js b/src/routes/Game.js index 54fa351..1e979c1 100644 --- a/src/routes/Game.js +++ b/src/routes/Game.js @@ -10,6 +10,7 @@ import AuthModal from "../modals/AuthModal"; import AuthContext from "../contexts/AuthContext"; import { MapStageProvider } from "../contexts/MapStageContext"; +import DatabaseContext from "../contexts/DatabaseContext"; import NetworkedMapAndTokens from "../network/NetworkedMapAndTokens"; import NetworkedParty from "../network/NetworkedParty"; @@ -25,6 +26,7 @@ function Game() { password, setAuthenticationStatus, } = useContext(AuthContext); + const { databaseStatus } = useContext(DatabaseContext); // Handle authentication status useEffect(() => { @@ -82,8 +84,11 @@ function Game() { // Join game useEffect(() => { - session.joinParty(gameId, password); - }, [gameId, password]); + if (databaseStatus !== "loading") { + console.log("join"); + session.joinParty(gameId, password); + } + }, [gameId, password, databaseStatus]); // A ref to the Konva stage // the ref will be assigned in the MapInteraction component