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
This commit is contained in:
Mitchell McCaffrey 2020-10-23 21:11:25 +11:00
parent 5df01973e5
commit 6c8833feae
2 changed files with 7 additions and 3 deletions

View File

@ -219,7 +219,6 @@ export function MapDataProvider({ children }) {
}
async function getMapFromDB(mapId) {
if (!database) return;
return await database.table("maps").get(mapId);
}

View File

@ -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