From 02d0d57453842bce9c022d30775efac988ff6118 Mon Sep 17 00:00:00 2001 From: Jon Eugster Date: Tue, 11 Jun 2024 01:05:43 +0200 Subject: [PATCH] fail gracefully on bad gameId #150 --- client/src/components/chat.tsx | 5 +++++ client/src/state/progress.ts | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/client/src/components/chat.tsx b/client/src/components/chat.tsx index 7f53431..da879de 100644 --- a/client/src/components/chat.tsx +++ b/client/src/components/chat.tsx @@ -367,6 +367,11 @@ export function ChatPanel ({visible = true}) { return
+ { gameInfo.error && +
+ Could not find the game! +
+ } {/* {proof?.steps.map((step, i) => diff --git a/client/src/state/progress.ts b/client/src/state/progress.ts index 191244f..ac23a74 100644 --- a/client/src/state/progress.ts +++ b/client/src/state/progress.ts @@ -148,9 +148,9 @@ export const progressSlice = createSlice({ export function selectLevel(game: string, world: string, level: number) { return (state) => { if (!state.progress.games[game?.toLowerCase()]) { return initalLevelProgressState } - if (!state.progress.games[game?.toLowerCase()].data[world]) { return initalLevelProgressState } - if (!state.progress.games[game?.toLowerCase()].data[world][level]) { return initalLevelProgressState } - return state.progress.games[game?.toLowerCase()].data[world][level] + if (!state.progress.games[game?.toLowerCase()]?.data[world]) { return initalLevelProgressState } + if (!state.progress.games[game?.toLowerCase()]?.data[world][level]) { return initalLevelProgressState } + return state.progress.games[game?.toLowerCase()]?.data[world][level] } } @@ -165,7 +165,7 @@ export function selectCode(game: string, world: string, level: number) { export function selectInventory(game: string) { return (state) => { if (!state.progress.games[game?.toLowerCase()]) { return [] } - return state.progress.games[game?.toLowerCase()].inventory + return state.progress.games[game?.toLowerCase()]?.inventory } } @@ -208,7 +208,7 @@ export function selectDifficulty(game: string) { export function selectReadIntro(game: string, worldId: string) { return (state) => { if (worldId) { - return state.progress.games[game?.toLowerCase()].data[worldId]?.readIntro + return state.progress.games[game?.toLowerCase()]?.data[worldId]?.readIntro } return state.progress.games[game?.toLowerCase()]?.readIntro }