From 3286ef77bf89feb57e3ddaa3afc81417c1971f03 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Mon, 14 Dec 2015 11:57:14 +0100 Subject: [PATCH] Add 404 handling to prizes' piece container --- .../ascribe_detail/piece_container.js | 3 +- .../ascribe_detail/prize_piece_container.js | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/js/components/ascribe_detail/piece_container.js b/js/components/ascribe_detail/piece_container.js index 74584ba3..7dfc9570 100644 --- a/js/components/ascribe_detail/piece_container.js +++ b/js/components/ascribe_detail/piece_container.js @@ -85,6 +85,7 @@ let PieceContainer = React.createClass({ // store as it will otherwise display wrong/old data once the user loads // the piece detail a second time PieceActions.updatePiece({}); + this.loadPiece(); UserActions.fetchCurrentUser(); }, @@ -92,7 +93,7 @@ let PieceContainer = React.createClass({ componentDidUpdate() { const { pieceError } = this.state; - if(pieceError && pieceError.status === 404) { + if (pieceError && pieceError.status === 404) { this.throws(new ResourceNotFoundError(getLangText("Oops, the piece you're looking for doesn't exist."))); } }, diff --git a/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js b/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js index 982af7b0..81f14077 100644 --- a/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js +++ b/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js @@ -6,6 +6,9 @@ import Moment from 'moment'; import StarRating from 'react-star-rating'; +import ReactError from '../../../../../../mixins/react_error'; +import { ResourceNotFoundError } from '../../../../../../models/errors'; + import PieceActions from '../../../../../../actions/piece_actions'; import PieceStore from '../../../../../../stores/piece_store'; @@ -54,6 +57,8 @@ let PieceContainer = React.createClass({ params: React.PropTypes.object }, + mixins: [ReactError], + getInitialState() { return mergeOptions( PieceStore.getState(), @@ -63,14 +68,15 @@ let PieceContainer = React.createClass({ componentDidMount() { PieceStore.listen(this.onChange); - PieceActions.fetchOne(this.props.params.pieceId); UserStore.listen(this.onChange); - UserActions.fetchCurrentUser(); // Every time we enter the piece detail page, just reset the piece // store as it will otherwise display wrong/old data once the user loads // the piece detail a second time PieceActions.updatePiece({}); + + PieceActions.fetchOne(this.props.params.pieceId); + UserActions.fetchCurrentUser(); }, // This is done to update the container when the user clicks on the prev or next @@ -82,6 +88,14 @@ let PieceContainer = React.createClass({ } }, + componentDidUpdate() { + const { pieceError } = this.state; + + if (pieceError && pieceError.status === 404) { + this.throws(new ResourceNotFoundError(getLangText("Oops, the piece you're looking for doesn't exist."))); + } + }, + componentWillUnmount() { PieceStore.unlisten(this.onChange); UserStore.unlisten(this.onChange); @@ -92,10 +106,6 @@ let PieceContainer = React.createClass({ this.setState(state); }, - loadPiece() { - PieceActions.fetchOne(this.props.params.pieceId); - }, - getActions() { if (this.state.piece && this.state.piece.notifications && @@ -112,7 +122,7 @@ let PieceContainer = React.createClass({ render() { if(this.state.piece && this.state.piece.id) { /* - + This really needs a refactor! - Tim @@ -122,7 +132,7 @@ let PieceContainer = React.createClass({ let artistName = ((this.state.currentUser.is_jury && !this.state.currentUser.is_judge) || (this.state.currentUser.is_judge && !this.state.piece.selected )) ? null : this.state.piece.artist_name; - + // Only show the artist email if you are a judge and the piece is shortlisted let artistEmail = (this.state.currentUser.is_judge && this.state.piece.selected ) ? : null; @@ -146,7 +156,7 @@ let PieceContainer = React.createClass({ - +

{this.state.piece.title}