in src/App.js [61:132]
async componentDidMount(){
let firstMovies = await API.graphql(graphqlOperation(listMoviess));
let existingReviews = await API.graphql(graphqlOperation(listReviewss));
let reviews = existingReviews.data.listReviewss.items;
reviews.map((review) => {
switch(review.id){
case "1":
this.setState({ love: review.votes});
break;
case "2":
this.setState({ like: review.votes});
break;
case "3":
this.setState({ meh: review.votes});
break;
case "4":
this.setState({ unknown: review.votes});
break;
case "5":
this.setState({ hate: review.votes});
break;
default:
console.log("Unknown ID, unable to resolve");
break;
};
return this.state;
});
this.setState({poster: firstMovies.data.listMoviess.items[0].poster, name:firstMovies.data.listMoviess.items[0].name, plot:firstMovies.data.listMoviess.items[0].plot, date:firstMovies.data.listMoviess.items[0].date});
this.subscription = API.graphql(graphqlOperation(onUpdateMovies)).subscribe({
next: (event) => {
this.setState({poster: event.value.data.onUpdateMovies.poster,name: event.value.data.onUpdateMovies.name, plot:event.value.data.onUpdateMovies.plot, date:event.value.data.onUpdateMovies.date, clickLove:0, clickLike:0, clickMeh:0, clickUnknown:0, clickHate:0, timer:10});
console.log("Subscription for Movie " + event.value.data.onUpdateMovies.name);
setInterval(this.aggVotes,3300);
}
});
this.subscription = API.graphql(graphqlOperation(onUpdateReviews)).subscribe({
next: (event) => {
switch(event.value.data.onUpdateReviews.id){
case "1":
this.setState({ love: event.value.data.onUpdateReviews.votes, topLovedMovie: event.value.data.onUpdateReviews.topMovie, topLove: event.value.data.onUpdateReviews.topVotes, player: '1', animation: !this.state.animation});
if (this.state.love === 0 ) this.setState({display:false,player:'0'});
break;
case "2":
this.setState({ like: event.value.data.onUpdateReviews.votes, topLikedMovie: event.value.data.onUpdateReviews.topMovie, topLike: event.value.data.onUpdateReviews.topVotes, player: '2', animation: !this.state.animation});
if (this.state.like === 0 ) this.setState({display:false,player:'0'});
break;
case "3":
this.setState({ meh: event.value.data.onUpdateReviews.votes, topMehMovie: event.value.data.onUpdateReviews.topMovie, topMeh: event.value.data.onUpdateReviews.topVotes,player: '3', animation: !this.state.animation});
if (this.state.meh === 0 ) this.setState({display:false,player:'0'});
break;
case "4":
this.setState({ unknown: event.value.data.onUpdateReviews.votes, topUnknownMovie: event.value.data.onUpdateReviews.topMovie, topUnknown: event.value.data.onUpdateReviews.topVotes,player: '4', animation: !this.state.animation});
if (this.state.unknown === 0 ) this.setState({display:false,player:'0'});
break;
case "5":
this.setState({ hate: event.value.data.onUpdateReviews.votes, topHatedMovie: event.value.data.onUpdateReviews.topMovie, topHate: event.value.data.onUpdateReviews.topVotes,player: '5', animation: !this.state.animation});
if (this.state.hate === 0 ) this.setState({display:false,player:'0'});
break;
default:
console.log("Unknown ID, unable to resolve");
break;
};
}
});
this.subscription = API.graphql(graphqlOperation(onCreateMessage)).subscribe({
next: (event) => {
this.setState({
messages: [...this.state.messages, event.value.data.onCreateMessage.message]
});
}
});
}