mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Add round
parameter to prize ratings
This commit is contained in:
parent
c4730dbae5
commit
0ce1633294
@ -15,10 +15,10 @@ class PrizeRatingActions {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchAverage(pieceId) {
|
fetchAverage(pieceId, round) {
|
||||||
return Q.Promise((resolve, reject) => {
|
return Q.Promise((resolve, reject) => {
|
||||||
PrizeRatingFetcher
|
PrizeRatingFetcher
|
||||||
.fetchAverage(pieceId)
|
.fetchAverage(pieceId, round)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.actions.updatePrizeRatingAverage(res.data);
|
this.actions.updatePrizeRatingAverage(res.data);
|
||||||
resolve(res);
|
resolve(res);
|
||||||
@ -30,10 +30,10 @@ class PrizeRatingActions {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchOne(pieceId) {
|
fetchOne(pieceId, round) {
|
||||||
return Q.Promise((resolve, reject) => {
|
return Q.Promise((resolve, reject) => {
|
||||||
PrizeRatingFetcher
|
PrizeRatingFetcher
|
||||||
.fetchOne(pieceId)
|
.fetchOne(pieceId, round)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.actions.updatePrizeRating(res.rating.rating);
|
this.actions.updatePrizeRating(res.rating.rating);
|
||||||
resolve(res);
|
resolve(res);
|
||||||
@ -44,10 +44,10 @@ class PrizeRatingActions {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createRating(pieceId, rating) {
|
createRating(pieceId, rating, round) {
|
||||||
return Q.Promise((resolve, reject) => {
|
return Q.Promise((resolve, reject) => {
|
||||||
PrizeRatingFetcher
|
PrizeRatingFetcher
|
||||||
.rate(pieceId, rating)
|
.rate(pieceId, rating, round)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.actions.updatePrizeRating(res.rating.rating);
|
this.actions.updatePrizeRating(res.rating.rating);
|
||||||
resolve(res);
|
resolve(res);
|
||||||
@ -71,10 +71,6 @@ class PrizeRatingActions {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRating(rating) {
|
|
||||||
this.actions.updatePrizeRating(rating);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default alt.createActions(PrizeRatingActions);
|
export default alt.createActions(PrizeRatingActions);
|
||||||
|
@ -9,15 +9,16 @@ import StarRating from 'react-star-rating';
|
|||||||
import ReactError from '../../../../../../mixins/react_error';
|
import ReactError from '../../../../../../mixins/react_error';
|
||||||
import { ResourceNotFoundError } from '../../../../../../models/errors';
|
import { ResourceNotFoundError } from '../../../../../../models/errors';
|
||||||
|
|
||||||
import PieceActions from '../../../../../../actions/piece_actions';
|
import PrizeActions from '../../actions/prize_actions';
|
||||||
import PieceStore from '../../../../../../stores/piece_store';
|
import PrizeStore from '../../stores/prize_store';
|
||||||
|
|
||||||
import PieceListStore from '../../../../../../stores/piece_list_store';
|
|
||||||
import PieceListActions from '../../../../../../actions/piece_list_actions';
|
|
||||||
|
|
||||||
import PrizeRatingActions from '../../actions/prize_rating_actions';
|
import PrizeRatingActions from '../../actions/prize_rating_actions';
|
||||||
import PrizeRatingStore from '../../stores/prize_rating_store';
|
import PrizeRatingStore from '../../stores/prize_rating_store';
|
||||||
|
|
||||||
|
import PieceActions from '../../../../../../actions/piece_actions';
|
||||||
|
import PieceStore from '../../../../../../stores/piece_store';
|
||||||
|
import PieceListStore from '../../../../../../stores/piece_list_store';
|
||||||
|
import PieceListActions from '../../../../../../actions/piece_list_actions';
|
||||||
|
|
||||||
import UserStore from '../../../../../../stores/user_store';
|
import UserStore from '../../../../../../stores/user_store';
|
||||||
import UserActions from '../../../../../../actions/user_actions';
|
import UserActions from '../../../../../../actions/user_actions';
|
||||||
|
|
||||||
@ -234,21 +235,24 @@ let PrizePieceRatings = React.createClass({
|
|||||||
getInitialState() {
|
getInitialState() {
|
||||||
return mergeOptions(
|
return mergeOptions(
|
||||||
PieceListStore.getState(),
|
PieceListStore.getState(),
|
||||||
|
PrizeStore.getState(),
|
||||||
PrizeRatingStore.getInitialState()
|
PrizeRatingStore.getInitialState()
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
PrizeRatingStore.listen(this.onChange);
|
|
||||||
PieceListStore.listen(this.onChange);
|
PieceListStore.listen(this.onChange);
|
||||||
|
PrizeStore.listen(this.onChange);
|
||||||
|
PrizeRatingStore.listen(this.onChange);
|
||||||
|
|
||||||
PrizeRatingActions.fetchOne(this.props.piece.id);
|
PrizeActions.fetchPrize();
|
||||||
PrizeRatingActions.fetchAverage(this.props.piece.id);
|
this.fetchPrizeRatings();
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
PrizeRatingStore.unlisten(this.onChange);
|
|
||||||
PieceListStore.unlisten(this.onChange);
|
PieceListStore.unlisten(this.onChange);
|
||||||
|
PrizeStore.unlisten(this.onChange);
|
||||||
|
PrizeRatingStore.unlisten(this.onChange);
|
||||||
},
|
},
|
||||||
|
|
||||||
// The StarRating component does not have a property that lets us set
|
// The StarRating component does not have a property that lets us set
|
||||||
@ -256,7 +260,12 @@ let PrizePieceRatings = React.createClass({
|
|||||||
// every mouseover be overridden, we need to set it ourselves initially to deal
|
// every mouseover be overridden, we need to set it ourselves initially to deal
|
||||||
// with the problem.
|
// with the problem.
|
||||||
onChange(state) {
|
onChange(state) {
|
||||||
|
if (state.prize && state.prize.active_round != this.state.prize.active_round) {
|
||||||
|
this.fetchPrizeRatings(state);
|
||||||
|
}
|
||||||
|
|
||||||
this.setState(state);
|
this.setState(state);
|
||||||
|
|
||||||
if (this.refs.rating) {
|
if (this.refs.rating) {
|
||||||
this.refs.rating.state.ratingCache = {
|
this.refs.rating.state.ratingCache = {
|
||||||
pos: this.refs.rating.state.pos,
|
pos: this.refs.rating.state.pos,
|
||||||
@ -267,10 +276,15 @@ let PrizePieceRatings = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fetchPrizeRatings(state = this.state) {
|
||||||
|
PrizeRatingActions.fetchOne(this.props.piece.id, state.prize.active_round);
|
||||||
|
PrizeRatingActions.fetchAverage(this.props.piece.id, state.prize.active_round);
|
||||||
|
},
|
||||||
|
|
||||||
onRatingClick(event, args) {
|
onRatingClick(event, args) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
PrizeRatingActions
|
PrizeRatingActions
|
||||||
.createRating(this.props.piece.id, args.rating)
|
.createRating(this.props.piece.id, args.rating, this.state.prize.active_round)
|
||||||
.then(this.refreshPieceData);
|
.then(this.refreshPieceData);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -4,16 +4,41 @@ import requests from '../../../../../utils/requests';
|
|||||||
|
|
||||||
|
|
||||||
let PrizeRatingFetcher = {
|
let PrizeRatingFetcher = {
|
||||||
fetchAverage(pieceId) {
|
fetchAverage(pieceId, round) {
|
||||||
return requests.get('rating_average', {'piece_id': pieceId});
|
const params = {
|
||||||
|
'piece_id': pieceId
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof round === 'number') {
|
||||||
|
params.round = round;
|
||||||
|
}
|
||||||
|
|
||||||
|
return requests.get('rating_average', params);
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchOne(pieceId) {
|
fetchOne(pieceId, round) {
|
||||||
return requests.get('rating', {'piece_id': pieceId});
|
const params = {
|
||||||
|
'piece_id': pieceId
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof round === 'number') {
|
||||||
|
params.round = round;
|
||||||
|
}
|
||||||
|
|
||||||
|
return requests.get('rating', params);
|
||||||
},
|
},
|
||||||
|
|
||||||
rate(pieceId, rating) {
|
rate(pieceId, rating, round) {
|
||||||
return requests.post('ratings', {body: {'piece_id': pieceId, 'note': rating}});
|
const body = {
|
||||||
|
'piece_id': pieceId,
|
||||||
|
'note': rating
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof round === 'number') {
|
||||||
|
body.round = round;
|
||||||
|
}
|
||||||
|
|
||||||
|
return requests.post('ratings', { body });
|
||||||
},
|
},
|
||||||
|
|
||||||
select(pieceId) {
|
select(pieceId) {
|
||||||
|
@ -6,7 +6,7 @@ import PrizeActions from '../actions/prize_actions';
|
|||||||
|
|
||||||
class PrizeStore {
|
class PrizeStore {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.prize = [];
|
this.prize = {};
|
||||||
this.bindActions(PrizeActions);
|
this.bindActions(PrizeActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,4 +15,4 @@ class PrizeStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default alt.createStore(PrizeStore, 'PrizeStore');
|
export default alt.createStore(PrizeStore, 'PrizeStore');
|
||||||
|
Loading…
Reference in New Issue
Block a user