gamebrary/src/components/GameCards/GameCard.js

109 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-11-21 19:32:41 +00:00
import { mapState, mapGetters } from 'vuex';
export default {
2019-11-08 19:56:03 +00:00
props: {
gameId: Number,
listId: Number,
},
data() {
return {
showEditOptions: false,
};
},
computed: {
...mapState(['settings', 'games', 'gameLists', 'platform', 'user', 'tags', 'activeList', 'notes']),
2019-11-21 19:32:41 +00:00
...mapGetters(['hasTags']),
2019-11-08 19:56:03 +00:00
showGameRatings() {
return this.list && !this.list.hideGameRatings;
},
2019-11-08 19:56:03 +00:00
gameCardClass() {
return [
'game-card',
this.list.view,
];
},
2019-11-08 19:56:03 +00:00
activePlatform() {
return this.gameLists[this.platform.code];
},
2019-11-08 19:56:03 +00:00
note() {
return this.notes && this.notes[this.gameId] && this.notes[this.gameId].text;
},
list() {
return this.activePlatform[this.listId];
},
game() {
return this.games[this.gameId];
},
coverUrl() {
const game = this.games[this.gameId];
return game.cover && game.cover.image_id
? `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() {
this.$bus.$emit('OPEN_GAME', {
id: this.game.id,
listId: this.listId,
});
},
openTags() {
this.$bus.$emit('OPEN_TAGS', this.game.id);
},
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(() => {
this.$bus.$emit('TOAST', {
message: `Added ${this.game.name} to list ${this.list.name}`,
imageUrl: this.coverUrl,
});
})
.catch(() => {
this.$bus.$emit('TOAST', { message: 'Authentication error', type: 'error' });
this.$router.push({ name: 'sessionExpired' });
});
},
2019-11-08 19:56:03 +00:00
removeTag(tagName) {
this.$store.commit('REMOVE_GAME_TAG', { tagName, gameId: this.gameId });
this.$bus.$emit('SAVE_TAGS', this.tags);
},
2019-11-08 19:56:03 +00:00
},
};
2019-11-08 20:34:06 +00:00