From 8edc6a48a377faaef72fe77b66f06d058fd0bea8 Mon Sep 17 00:00:00 2001 From: Jas Laferriere Date: Fri, 3 Jul 2020 17:53:37 -0700 Subject: [PATCH] add error state to profile page --- app/actions/game.js | 12 +++++++++--- app/components/stats/GameProfile.js | 27 ++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/actions/game.js b/app/actions/game.js index b7408f51b..977be5889 100644 --- a/app/actions/game.js +++ b/app/actions/game.js @@ -34,10 +34,16 @@ async function loadGame(gameOrPath) { gameToLoad = new SlippiGame(gameOrPath); } + let settings, stats; + // Generate data here so that maybe we can add a loading state - const settings = gameToLoad.getSettings(); - const stats = gameToLoad.getStats(); - gameToLoad.getMetadata(); + try { + settings = gameToLoad.getSettings(); + stats = gameToLoad.getStats(); + gameToLoad.getMetadata(); + } catch { + return null; + } // This is jank and I shouldn't do this... but the rest of the app kind of relies on these being // set on the object which was legacy behavior. Preferably all of the places where this is used diff --git a/app/components/stats/GameProfile.js b/app/components/stats/GameProfile.js index 62b62b87f..7619f2c74 100644 --- a/app/components/stats/GameProfile.js +++ b/app/components/stats/GameProfile.js @@ -75,6 +75,11 @@ export default class GameProfile extends Component { return this.renderLoading(); } + const game = _.get(this.props, ['store', 'game']) || null; + if (!game) { + return this.renderError(); + } + const gameSettings = _.get(this.props.store, ['game', 'settings']) || {}; const players = gameSettings.players || []; if (players.length !== 2) { @@ -116,12 +121,32 @@ export default class GameProfile extends Component { ); } + renderError() { + return ( +
+ + Error loading file +
+ ); + } + renderGameProfileHeader() { const isLoading = _.get(this.props.store, 'isLoading') || false; if (isLoading) { return null; } + const game = _.get(this.props, ['store', 'game']) || null; + if (!game) { + return null; + } + return (
{this.renderMatchupDisplay()} @@ -174,7 +199,7 @@ export default class GameProfile extends Component { - ) : null } + ) : null}
{playerNamesByIndex[player.playerIndex]}