mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Fix stale prize ratings showing up on other pieces when they do not have ratings
This commit is contained in:
parent
39730ec637
commit
13937c9951
@ -10,7 +10,8 @@ class PrizeRatingActions {
|
|||||||
this.generateActions(
|
this.generateActions(
|
||||||
'updatePrizeRatings',
|
'updatePrizeRatings',
|
||||||
'updatePrizeRatingAverage',
|
'updatePrizeRatingAverage',
|
||||||
'updatePrizeRating'
|
'updatePrizeRating',
|
||||||
|
'resetPrizeRatings'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,31 +59,32 @@ let PrizePieceContainer = React.createClass({
|
|||||||
mixins: [ReactError],
|
mixins: [ReactError],
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return mergeOptions(
|
//FIXME: this component uses the PieceStore, but we avoid using the getState() here since it may contain stale data
|
||||||
PieceStore.getState(),
|
// It should instead use something like getInitialState() where that call also resets the state.
|
||||||
UserStore.getState()
|
return UserStore.getState();
|
||||||
);
|
},
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
// 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({});
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
PieceStore.listen(this.onChange);
|
PieceStore.listen(this.onChange);
|
||||||
UserStore.listen(this.onChange);
|
UserStore.listen(this.onChange);
|
||||||
|
|
||||||
// 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({});
|
|
||||||
|
|
||||||
this.loadPiece();
|
|
||||||
UserActions.fetchCurrentUser();
|
UserActions.fetchCurrentUser();
|
||||||
|
this.loadPiece();
|
||||||
},
|
},
|
||||||
|
|
||||||
// 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
|
||||||
// button to update the URL parameter (and therefore to switch pieces)
|
// button to update the URL parameter (and therefore to switch pieces)
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if(this.props.params.pieceId !== nextProps.params.pieceId) {
|
if (this.props.params.pieceId !== nextProps.params.pieceId) {
|
||||||
PieceActions.updatePiece({});
|
PieceActions.updatePiece({});
|
||||||
PieceActions.fetchOne(nextProps.params.pieceId);
|
this.loadPiece(nextProps.params.pieceId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -100,7 +101,6 @@ let PrizePieceContainer = React.createClass({
|
|||||||
UserStore.unlisten(this.onChange);
|
UserStore.unlisten(this.onChange);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
onChange(state) {
|
onChange(state) {
|
||||||
this.setState(state);
|
this.setState(state);
|
||||||
},
|
},
|
||||||
@ -118,8 +118,8 @@ let PrizePieceContainer = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
loadPiece() {
|
loadPiece(pieceId = this.props.params.pieceId) {
|
||||||
PieceActions.fetchOne(this.props.params.pieceId);
|
PieceActions.fetchOne(pieceId);
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -234,23 +234,19 @@ let PrizePieceRatings = React.createClass({
|
|||||||
getInitialState() {
|
getInitialState() {
|
||||||
return mergeOptions(
|
return mergeOptions(
|
||||||
PieceListStore.getState(),
|
PieceListStore.getState(),
|
||||||
PrizeRatingStore.getState()
|
PrizeRatingStore.getInitialState()
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
PrizeRatingStore.listen(this.onChange);
|
PrizeRatingStore.listen(this.onChange);
|
||||||
|
PieceListStore.listen(this.onChange);
|
||||||
|
|
||||||
PrizeRatingActions.fetchOne(this.props.piece.id);
|
PrizeRatingActions.fetchOne(this.props.piece.id);
|
||||||
PrizeRatingActions.fetchAverage(this.props.piece.id);
|
PrizeRatingActions.fetchAverage(this.props.piece.id);
|
||||||
PieceListStore.listen(this.onChange);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
// Every time we're leaving the piece detail page,
|
|
||||||
// just reset the piece that is saved in the piece store
|
|
||||||
// as it will otherwise display wrong/old data once the user loads
|
|
||||||
// the piece detail a second time
|
|
||||||
PrizeRatingActions.updateRating({});
|
|
||||||
PrizeRatingStore.unlisten(this.onChange);
|
PrizeRatingStore.unlisten(this.onChange);
|
||||||
PieceListStore.unlisten(this.onChange);
|
PieceListStore.unlisten(this.onChange);
|
||||||
},
|
},
|
||||||
@ -311,7 +307,7 @@ let PrizePieceRatings = React.createClass({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
render(){
|
render() {
|
||||||
if (this.props.piece && this.props.currentUser && this.props.currentUser.is_judge && this.state.average) {
|
if (this.props.piece && this.props.currentUser && this.props.currentUser.is_judge && this.state.average) {
|
||||||
// Judge sees shortlisting, average and per-jury notes
|
// Judge sees shortlisting, average and per-jury notes
|
||||||
return (
|
return (
|
||||||
@ -380,8 +376,7 @@ let PrizePieceRatings = React.createClass({
|
|||||||
<hr />
|
<hr />
|
||||||
</CollapsibleParagraph>
|
</CollapsibleParagraph>
|
||||||
</div>);
|
</div>);
|
||||||
}
|
} else if (this.props.currentUser && this.props.currentUser.is_jury) {
|
||||||
else if (this.props.currentUser && this.props.currentUser.is_jury) {
|
|
||||||
// Jury can set rating and note
|
// Jury can set rating and note
|
||||||
return (
|
return (
|
||||||
<CollapsibleParagraph
|
<CollapsibleParagraph
|
||||||
@ -408,8 +403,9 @@ let PrizePieceRatings = React.createClass({
|
|||||||
url={ApiUrls.notes}
|
url={ApiUrls.notes}
|
||||||
currentUser={this.props.currentUser}/>
|
currentUser={this.props.currentUser}/>
|
||||||
</CollapsibleParagraph>);
|
</CollapsibleParagraph>);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -6,10 +6,12 @@ import PrizeRatingActions from '../actions/prize_rating_actions';
|
|||||||
|
|
||||||
class PrizeRatingStore {
|
class PrizeRatingStore {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.ratings = [];
|
this.getInitialState();
|
||||||
this.currentRating = null;
|
|
||||||
this.average = null;
|
|
||||||
this.bindActions(PrizeRatingActions);
|
this.bindActions(PrizeRatingActions);
|
||||||
|
this.exportPublicMethods({
|
||||||
|
getInitialState: this.getInitialState.bind(this)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdatePrizeRatings(ratings) {
|
onUpdatePrizeRatings(ratings) {
|
||||||
@ -24,6 +26,22 @@ class PrizeRatingStore {
|
|||||||
this.average = data.average;
|
this.average = data.average;
|
||||||
this.ratings = data.ratings;
|
this.ratings = data.ratings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onResetPrizeRatings() {
|
||||||
|
this.getInitialState();
|
||||||
|
}
|
||||||
|
|
||||||
|
getInitialState() {
|
||||||
|
this.ratings = [];
|
||||||
|
this.currentRating = null;
|
||||||
|
this.average = null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
ratings: this.ratings,
|
||||||
|
currentRating: this.currentRating,
|
||||||
|
average: this.average
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default alt.createStore(PrizeRatingStore, 'PrizeRatingStore');
|
export default alt.createStore(PrizeRatingStore, 'PrizeRatingStore');
|
Loading…
Reference in New Issue
Block a user