gamebrary/src/components/GameCards/GameCard.js

92 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-08-25 04:24:09 +00:00
// TODO: dissolve
2020-08-21 06:12:51 +00:00
// import moment from 'moment';
2019-11-21 19:32:41 +00:00
import { mapState, mapGetters } from 'vuex';
export default {
2019-11-08 19:56:03 +00:00
props: {
2020-08-21 06:12:51 +00:00
list: {
type: Object,
default: () => {},
},
gameId: [String, Number],
2019-11-08 19:56:03 +00:00
},
computed: {
...mapState(['settings', 'games', 'tags', 'notes', 'progresses', 'board']),
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
showCompletedBadge() {
return this.gameProgress && Number(this.gameProgress) === 100;
},
showGameProgress() {
return this.gameProgress && Number(this.gameProgress) < 100;
},
2020-08-11 23:39:11 +00:00
showGameTags() {
2020-08-21 06:12:51 +00:00
const { settings } = this.list;
return settings && settings.showGameTags && this.gameTags;
},
2020-08-11 23:39:11 +00:00
gameRating() {
2020-08-21 06:12:51 +00:00
const { settings } = this.list;
return settings && settings.showGameRatings && this.game.rating
2020-08-11 23:39:11 +00:00
? Math.round((this.game.rating / 20) * 2) / 2
: false;
},
gameProgress() {
2020-08-22 12:23:58 +00:00
const { gameId, progresses, list: { settings } } = this;
2020-08-11 23:39:11 +00:00
2020-08-22 12:23:58 +00:00
return settings && settings.showGameProgress && gameId && progresses[gameId]
2020-08-15 22:39:22 +00:00
? progresses[gameId]
: null;
2019-12-15 04:32:40 +00:00
},
2020-08-11 23:39:11 +00:00
gameNotes() {
2020-08-21 06:12:51 +00:00
const { settings } = this.list;
2020-08-21 06:12:51 +00:00
return settings && settings.showGameNotes && this.notes[this.gameId];
2019-11-08 19:56:03 +00:00
},
game() {
return this.games[this.gameId];
},
2020-08-25 04:24:09 +00:00
// TODO: move to utils file
2019-11-08 19:56:03 +00:00
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';
},
},
methods: {
openDetails() {
2020-08-21 06:12:51 +00:00
const { gameId, list } = this;
2020-08-13 06:55:56 +00:00
2020-08-21 06:12:51 +00:00
this.$store.commit('SET_GAME_MODAL_DATA', { gameId, list });
2020-08-13 06:55:56 +00:00
this.$bvModal.show('game-modal');
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() {
2020-09-09 20:38:52 +00:00
await this.$store.dispatch('SAVE_TAGS', this.tags)
2019-12-03 18:26:19 +00:00
.catch(() => {
2020-09-23 23:01:39 +00:00
this.$store.commit('SET_SESSION_EXPIRED', true);
2019-12-03 18:26:19 +00:00
});
2020-08-13 06:55:56 +00:00
this.$bvToast.toast('Tags updated', { title: 'Success', variant: 'success' });
},
2019-11-08 19:56:03 +00:00
},
};