From 7f1dc831265e0ba4f7f13a0e307daf28d91f8a90 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Fri, 6 Jul 2018 21:01:51 +0200 Subject: client/schedule: Properly handle errors --- src/client/react/components/container/View.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/client/react/components/container') diff --git a/src/client/react/components/container/View.js b/src/client/react/components/container/View.js index a601226..68bdde9 100644 --- a/src/client/react/components/container/View.js +++ b/src/client/react/components/container/View.js @@ -26,6 +26,7 @@ import extractSchedule from '../../lib/extractSchedule'; import Schedule from '../presentational/Schedule'; import Loading from '../presentational/Loading'; +import ScheduleErrorDisplay from '../presentational/ScheduleErrorDisplay'; import * as actions from '../../store/actions'; class View extends React.Component { @@ -45,6 +46,14 @@ class View extends React.Component { fetchScheduleIfNeeded(user, week); } + componentDidUpdate(prevProps) { + const { fetchScheduleIfNeeded, user, week } = this.props; + + if (prevProps.user !== user || prevProps.week !== week) { + fetchScheduleIfNeeded(user, week); + } + } + render() { const { user, @@ -60,6 +69,8 @@ class View extends React.Component { return ; case 'FINISHED': return ; + case 'ERROR': + return ; default: throw new Error(`${schedule.state} is not a valid schedule state.`); } @@ -70,7 +81,6 @@ const mapStateToProps = (state) => { const user = selectUser(state); const week = selectWeek(state); return { - key: `${user}:${week}`, user, week, schedules: state.schedules, -- cgit v1.1