2020-08-22 12:21:15 +00:00
|
|
|
<template lang="html">
|
2021-01-08 06:47:06 +00:00
|
|
|
<b-dropdown-item
|
|
|
|
:variant="gameInList ? 'danger' : 'success'"
|
|
|
|
@click="handleClick"
|
2020-08-22 12:21:15 +00:00
|
|
|
>
|
2021-01-08 06:47:06 +00:00
|
|
|
<i :class="`fas fa-${gameInList ? 'trash-alt' : 'plus'} fa-fw`" aria-hidden />
|
|
|
|
{{ label }}
|
|
|
|
</b-dropdown-item>
|
2020-08-22 12:21:15 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapState } from 'vuex';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
game: Object,
|
|
|
|
list: Object,
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState(['board']),
|
2021-01-08 06:47:06 +00:00
|
|
|
|
|
|
|
gameInList() {
|
|
|
|
return this.game && this.list.games.includes(this.game.id);
|
|
|
|
},
|
|
|
|
|
|
|
|
label() {
|
|
|
|
return this.gameInList
|
|
|
|
? this.$t('board.gameModal.removeFromList')
|
|
|
|
: this.$t('board.list.addGame');
|
|
|
|
},
|
2020-08-22 12:21:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2021-01-08 06:47:06 +00:00
|
|
|
handleClick() {
|
|
|
|
if (this.gameInList) {
|
|
|
|
this.removeGame();
|
|
|
|
} else {
|
|
|
|
this.addGame();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-08-22 12:21:15 +00:00
|
|
|
async addGame() {
|
|
|
|
const { list, game, board } = this;
|
|
|
|
|
|
|
|
const listIndex = board.lists.findIndex(({ name }) => name === list.name);
|
|
|
|
|
|
|
|
this.$store.commit('ADD_GAME_TO_LIST', {
|
|
|
|
listIndex,
|
|
|
|
game,
|
|
|
|
});
|
|
|
|
|
|
|
|
await this.$store.dispatch('SAVE_BOARD')
|
|
|
|
.catch(() => {
|
|
|
|
this.$bvToast.toast(`There was an error adding "${this.game.name}"`, { title: list.name, variant: 'danger' });
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$bvToast.toast(`${this.game.name} added`, { title: list.name, variant: 'success' });
|
|
|
|
|
|
|
|
// this.$ga.event({
|
|
|
|
// eventCategory: 'game',
|
|
|
|
// eventAction: 'add',
|
|
|
|
// eventLabel: 'addGame',
|
|
|
|
// eventValue: data,
|
|
|
|
// });
|
|
|
|
},
|
|
|
|
|
|
|
|
async removeGame() {
|
|
|
|
const { list, game, board } = this;
|
|
|
|
|
|
|
|
const listIndex = board.lists.findIndex(({ name }) => name === list.name);
|
|
|
|
|
|
|
|
this.$store.commit('REMOVE_GAME_FROM_LIST', { listIndex, game });
|
|
|
|
|
|
|
|
await this.$store.dispatch('SAVE_BOARD')
|
|
|
|
.catch(() => {
|
|
|
|
this.$bvToast.toast(`There was an error removing "${this.game.name}"`, { title: list.name, variant: 'danger' });
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$bvToast.toast(`${this.game.name} removed`, { title: list.name, variant: 'success' });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|