1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 13:41:57 +02:00

Add 404 handling to prizes' piece container

This commit is contained in:
Brett Sun 2015-12-14 11:57:14 +01:00
parent bee420a919
commit 3286ef77bf
2 changed files with 21 additions and 10 deletions

View File

@ -85,6 +85,7 @@ let PieceContainer = React.createClass({
// store as it will otherwise display wrong/old data once the user loads // store as it will otherwise display wrong/old data once the user loads
// the piece detail a second time // the piece detail a second time
PieceActions.updatePiece({}); PieceActions.updatePiece({});
this.loadPiece(); this.loadPiece();
UserActions.fetchCurrentUser(); UserActions.fetchCurrentUser();
}, },
@ -92,7 +93,7 @@ let PieceContainer = React.createClass({
componentDidUpdate() { componentDidUpdate() {
const { pieceError } = this.state; 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."))); this.throws(new ResourceNotFoundError(getLangText("Oops, the piece you're looking for doesn't exist.")));
} }
}, },

View File

@ -6,6 +6,9 @@ import Moment from 'moment';
import StarRating from 'react-star-rating'; import StarRating from 'react-star-rating';
import ReactError from '../../../../../../mixins/react_error';
import { ResourceNotFoundError } from '../../../../../../models/errors';
import PieceActions from '../../../../../../actions/piece_actions'; import PieceActions from '../../../../../../actions/piece_actions';
import PieceStore from '../../../../../../stores/piece_store'; import PieceStore from '../../../../../../stores/piece_store';
@ -54,6 +57,8 @@ let PieceContainer = React.createClass({
params: React.PropTypes.object params: React.PropTypes.object
}, },
mixins: [ReactError],
getInitialState() { getInitialState() {
return mergeOptions( return mergeOptions(
PieceStore.getState(), PieceStore.getState(),
@ -63,14 +68,15 @@ let PieceContainer = React.createClass({
componentDidMount() { componentDidMount() {
PieceStore.listen(this.onChange); PieceStore.listen(this.onChange);
PieceActions.fetchOne(this.props.params.pieceId);
UserStore.listen(this.onChange); UserStore.listen(this.onChange);
UserActions.fetchCurrentUser();
// Every time we enter the piece detail page, just reset the piece // 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 // store as it will otherwise display wrong/old data once the user loads
// the piece detail a second time // the piece detail a second time
PieceActions.updatePiece({}); 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 // 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() { componentWillUnmount() {
PieceStore.unlisten(this.onChange); PieceStore.unlisten(this.onChange);
UserStore.unlisten(this.onChange); UserStore.unlisten(this.onChange);
@ -92,10 +106,6 @@ let PieceContainer = React.createClass({
this.setState(state); this.setState(state);
}, },
loadPiece() {
PieceActions.fetchOne(this.props.params.pieceId);
},
getActions() { getActions() {
if (this.state.piece && if (this.state.piece &&
this.state.piece.notifications && this.state.piece.notifications &&
@ -112,7 +122,7 @@ let PieceContainer = React.createClass({
render() { render() {
if(this.state.piece && this.state.piece.id) { if(this.state.piece && this.state.piece.id) {
/* /*
This really needs a refactor! This really needs a refactor!
- Tim - Tim
@ -122,7 +132,7 @@ let PieceContainer = React.createClass({
let artistName = ((this.state.currentUser.is_jury && !this.state.currentUser.is_judge) || let artistName = ((this.state.currentUser.is_jury && !this.state.currentUser.is_judge) ||
(this.state.currentUser.is_judge && !this.state.piece.selected )) ? (this.state.currentUser.is_judge && !this.state.piece.selected )) ?
null : this.state.piece.artist_name; null : this.state.piece.artist_name;
// Only show the artist email if you are a judge and the piece is shortlisted // 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 ) ? let artistEmail = (this.state.currentUser.is_judge && this.state.piece.selected ) ?
<DetailProperty label={getLangText('REGISTREE')} value={ this.state.piece.user_registered } /> : null; <DetailProperty label={getLangText('REGISTREE')} value={ this.state.piece.user_registered } /> : null;
@ -146,7 +156,7 @@ let PieceContainer = React.createClass({
<NavigationHeader <NavigationHeader
piece={this.state.piece} piece={this.state.piece}
currentUser={this.state.currentUser}/> currentUser={this.state.currentUser}/>
<h1 className="ascribe-detail-title">{this.state.piece.title}</h1> <h1 className="ascribe-detail-title">{this.state.piece.title}</h1>
<DetailProperty label={getLangText('BY')} value={artistName} /> <DetailProperty label={getLangText('BY')} value={artistName} />
<DetailProperty label={getLangText('DATE')} value={Moment(this.state.piece.date_created, 'YYYY-MM-DD').year()} /> <DetailProperty label={getLangText('DATE')} value={Moment(this.state.piece.date_created, 'YYYY-MM-DD').year()} />