2019-04-19 05:33:49 +00:00
|
|
|
// Identify stuff that's not being reused
|
|
|
|
import { mapState, mapGetters } from 'vuex';
|
|
|
|
import firebase from 'firebase/app';
|
|
|
|
import 'firebase/firestore';
|
|
|
|
|
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
gameId: Number,
|
|
|
|
listId: Number,
|
|
|
|
searchResult: Boolean,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
showEditOptions: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2019-04-19 20:27:45 +00:00
|
|
|
...mapState(['settings', 'games', 'gameLists', 'platform', 'user', 'tags', 'activeList', 'notes']),
|
2019-04-19 05:33:49 +00:00
|
|
|
|
|
|
|
...mapGetters(['darkModeEnabled']),
|
|
|
|
|
|
|
|
showGameRatings() {
|
|
|
|
return this.settings && !this.settings.hideGameRatings;
|
|
|
|
},
|
|
|
|
|
|
|
|
gameCardClass() {
|
|
|
|
return [
|
|
|
|
'game-card',
|
|
|
|
this.list.view,
|
|
|
|
{
|
|
|
|
'search-result': this.searchResult,
|
|
|
|
dark: this.darkModeEnabled,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
},
|
|
|
|
|
|
|
|
activePlatform() {
|
|
|
|
return this.gameLists[this.platform.code];
|
|
|
|
},
|
|
|
|
|
2019-04-19 20:27:45 +00:00
|
|
|
note() {
|
|
|
|
return this.notes && this.notes[this.gameId] && this.notes[this.gameId].text;
|
|
|
|
},
|
|
|
|
|
2019-04-19 05:33:49 +00:00
|
|
|
list() {
|
|
|
|
return this.activePlatform[this.listId];
|
|
|
|
},
|
|
|
|
|
|
|
|
game() {
|
|
|
|
return this.games[this.gameId];
|
|
|
|
},
|
|
|
|
|
|
|
|
hasTags() {
|
|
|
|
return Object.keys(this.tags) && Object.keys(this.tags).length > 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
coverUrl() {
|
2019-06-09 02:04:07 +00:00
|
|
|
const game = this.games[this.gameId];
|
2019-04-19 05:33:49 +00:00
|
|
|
|
2019-06-09 02:04:07 +00:00
|
|
|
return game.cover && game.cover.image_id
|
|
|
|
? `https://images.igdb.com/igdb/image/upload/t_cover_small_2x/${game.cover.image_id}.jpg`
|
2019-04-19 05:33:49 +00:00
|
|
|
: '/static/no-image.jpg';
|
|
|
|
},
|
|
|
|
|
|
|
|
addToLabel() {
|
|
|
|
return this.list.name.length >= 25
|
|
|
|
? 'list'
|
|
|
|
: this.list.name;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
openDetails() {
|
2019-04-19 06:20:29 +00:00
|
|
|
this.$bus.$emit('OPEN_GAME', {
|
|
|
|
id: this.game.id,
|
|
|
|
listId: this.listId,
|
|
|
|
});
|
2019-04-19 05:33:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
|
2019-09-23 20:03:30 +00:00
|
|
|
// TOOD: move to actions
|
2019-04-19 05:33:49 +00:00
|
|
|
db.collection('lists').doc(this.user.uid).set(this.gameLists, { merge: true })
|
|
|
|
.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' });
|
2019-08-09 19:12:11 +00:00
|
|
|
this.$router.push({ name: 'sessionExpired' });
|
2019-04-19 05:33:49 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-04-25 23:25:13 +00:00
|
|
|
removeTag(tagName) {
|
|
|
|
this.$store.commit('REMOVE_GAME_TAG', { tagName, gameId: this.gameId });
|
|
|
|
this.$bus.$emit('SAVE_TAGS', this.tags);
|
|
|
|
},
|
|
|
|
|
2019-04-19 05:33:49 +00:00
|
|
|
removeGame() {
|
|
|
|
const data = {
|
|
|
|
listId: this.listId,
|
|
|
|
gameId: this.gameId,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$store.commit('REMOVE_GAME', data);
|
|
|
|
|
2019-09-23 20:03:30 +00:00
|
|
|
// TOOD: move to actions
|
2019-04-19 05:33:49 +00:00
|
|
|
db.collection('lists').doc(this.user.uid).set(this.gameLists, { merge: true })
|
|
|
|
.then(() => {
|
|
|
|
this.$bus.$emit('TOAST', {
|
|
|
|
message: `Removed ${this.game.name} from list ${this.list.name}`,
|
|
|
|
imageUrl: this.coverUrl,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.$bus.$emit('TOAST', { message: 'Authentication error', type: 'error' });
|
2019-08-09 19:12:11 +00:00
|
|
|
this.$router.push({ name: 'sessionExpired' });
|
2019-04-19 05:33:49 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|