2020-02-18 17:30:34 +00:00
|
|
|
import moment from 'moment';
|
2019-11-21 19:32:41 +00:00
|
|
|
import { mapState, mapGetters } from 'vuex';
|
2019-04-19 05:33:49 +00:00
|
|
|
|
|
|
|
export default {
|
2019-11-08 19:56:03 +00:00
|
|
|
props: {
|
|
|
|
gameId: Number,
|
|
|
|
listId: Number,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
showEditOptions: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2019-12-17 05:05:35 +00:00
|
|
|
...mapState(['settings', 'games', 'gameLists', 'platform', 'user', 'tags', 'activeList', 'notes', 'progresses']),
|
2020-08-15 00:00:04 +00:00
|
|
|
// TODO: remove getter
|
2020-08-11 23:39:11 +00:00
|
|
|
...mapGetters(['gameTags']),
|
2019-11-08 19:56:03 +00:00
|
|
|
|
2020-08-11 23:39:11 +00:00
|
|
|
showGameTags() {
|
|
|
|
return this.list.showGameTags && this.gameTags;
|
2019-04-19 05:33:49 +00:00
|
|
|
},
|
|
|
|
|
2020-08-11 23:39:11 +00:00
|
|
|
gameRating() {
|
|
|
|
return this.list.showGameRatings && this.game.rating
|
|
|
|
? Math.round((this.game.rating / 20) * 2) / 2
|
|
|
|
: false;
|
2020-02-11 17:56:13 +00:00
|
|
|
},
|
|
|
|
|
2019-12-18 05:47:35 +00:00
|
|
|
gameProgress() {
|
2020-08-15 20:41:43 +00:00
|
|
|
const { game, progresses, list } = this;
|
2020-08-11 23:39:11 +00:00
|
|
|
|
|
|
|
return game
|
|
|
|
&& list.showGameProgress
|
2020-08-15 20:41:43 +00:00
|
|
|
&& progresses[game.id]
|
|
|
|
|| null;
|
2019-12-15 04:32:40 +00:00
|
|
|
},
|
|
|
|
|
2020-02-18 17:30:34 +00:00
|
|
|
releaseDate() {
|
|
|
|
const releaseDate = this.game
|
2020-08-11 23:39:11 +00:00
|
|
|
&& this.list.showReleaseDates
|
2020-02-18 17:30:34 +00:00
|
|
|
&& this.game.release_dates
|
2020-08-11 23:39:11 +00:00
|
|
|
&& this.game.release_dates.find(({ platform }) => this.platform.id === platform);
|
2020-02-18 17:30:34 +00:00
|
|
|
|
2020-08-11 23:39:11 +00:00
|
|
|
const formattedDate = releaseDate && releaseDate.date
|
|
|
|
? moment.unix(releaseDate.date)
|
|
|
|
: null;
|
2020-02-18 17:30:34 +00:00
|
|
|
|
2020-08-11 23:39:11 +00:00
|
|
|
return moment(formattedDate).isAfter()
|
|
|
|
? formattedDate.toNow(true)
|
|
|
|
: null;
|
2020-02-18 17:30:34 +00:00
|
|
|
},
|
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
gameCardClass() {
|
|
|
|
return [
|
|
|
|
'game-card',
|
|
|
|
this.list.view,
|
|
|
|
];
|
2019-04-19 05:33:49 +00:00
|
|
|
},
|
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
activePlatform() {
|
|
|
|
return this.gameLists[this.platform.code];
|
|
|
|
},
|
2019-04-19 05:33:49 +00:00
|
|
|
|
2020-08-11 23:39:11 +00:00
|
|
|
gameNotes() {
|
|
|
|
return this.list.showGameNotes
|
|
|
|
&& this.notes
|
|
|
|
&& this.notes[this.gameId]
|
|
|
|
&& this.notes[this.gameId].text;
|
2019-12-17 05:05:35 +00:00
|
|
|
},
|
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
list() {
|
2020-08-11 23:39:11 +00:00
|
|
|
return this.activePlatform[this.listId] || {};
|
2019-11-08 19:56:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
game() {
|
|
|
|
return this.games[this.gameId];
|
|
|
|
},
|
|
|
|
|
|
|
|
coverUrl() {
|
|
|
|
const game = this.games[this.gameId];
|
|
|
|
|
2020-08-11 04:16:43 +00:00
|
|
|
return game && game.cover && game.cover.image_id
|
2019-11-08 19:56:03 +00:00
|
|
|
? `https://images.igdb.com/igdb/image/upload/t_cover_small_2x/${game.cover.image_id}.jpg`
|
|
|
|
: '/static/no-image.jpg';
|
|
|
|
},
|
|
|
|
|
|
|
|
addToLabel() {
|
|
|
|
return this.list.name.length >= 25
|
|
|
|
? 'list'
|
|
|
|
: this.list.name;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
openDetails() {
|
2020-08-13 06:55:56 +00:00
|
|
|
const { gameId, listId } = this;
|
|
|
|
|
|
|
|
this.$store.commit('SET_GAME_MODAL_DATA', { gameId, listId });
|
|
|
|
this.$bvModal.show('game-modal');
|
2019-11-08 19:56:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
addGame() {
|
|
|
|
const data = {
|
|
|
|
listId: this.listId,
|
|
|
|
gameId: this.gameId,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$emit('added');
|
|
|
|
this.$store.commit('ADD_GAME', data);
|
|
|
|
|
|
|
|
this.$ga.event({
|
|
|
|
eventCategory: 'game',
|
|
|
|
eventAction: 'add',
|
|
|
|
eventLabel: 'addGame',
|
|
|
|
eventValue: data,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$store.dispatch('SAVE_LIST', this.gameLists)
|
|
|
|
.then(() => {
|
2020-08-13 06:55:56 +00:00
|
|
|
// TODO: customize, show cover url
|
|
|
|
this.$bvToast.toast(`Added ${this.game.name} to list ${this.list.name}`, { title: 'Game added', variant: 'success' });
|
2019-11-08 19:56:03 +00:00
|
|
|
})
|
|
|
|
.catch(() => {
|
2020-08-13 06:55:56 +00:00
|
|
|
this.$bvToast.toast('Authentication error', { title: 'Error', variant: 'danger' });
|
2019-11-08 19:56:03 +00:00
|
|
|
this.$router.push({ name: 'sessionExpired' });
|
|
|
|
});
|
2019-04-19 05:33:49 +00:00
|
|
|
},
|
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
removeTag(tagName) {
|
|
|
|
this.$store.commit('REMOVE_GAME_TAG', { tagName, gameId: this.gameId });
|
2019-12-03 18:26:19 +00:00
|
|
|
this.saveTags();
|
|
|
|
},
|
|
|
|
|
|
|
|
async saveTags() {
|
|
|
|
await this.$store.dispatch('SAVE_TAGS', this.tags)
|
|
|
|
.catch(() => {
|
2020-08-13 06:55:56 +00:00
|
|
|
this.$bvToast.toast('Authentication error', { title: 'Error', variant: 'danger' });
|
2019-12-03 18:26:19 +00:00
|
|
|
this.$router.push({ name: 'sessionExpired' });
|
|
|
|
});
|
|
|
|
|
2020-08-13 06:55:56 +00:00
|
|
|
this.$bvToast.toast('Tags updated', { title: 'Success', variant: 'success' });
|
2019-04-19 05:33:49 +00:00
|
|
|
},
|
2019-11-08 19:56:03 +00:00
|
|
|
},
|
2019-04-19 05:33:49 +00:00
|
|
|
};
|