gamebrary/src/components/GameCards/GameCardRecent.vue

97 lines
2.1 KiB
Vue
Raw Normal View History

2021-02-01 19:37:09 +00:00
<template lang="html">
<b-card
no-body
class="game-card"
2021-02-21 18:14:46 +00:00
:bg-variant="darkTheme ? 'dark' : ''"
:text-variant="darkTheme ? 'white' : ''"
2021-02-01 19:37:09 +00:00
@click="addGame"
>
<b-row no-gutters v-if="game && game.name">
<b-col cols="2">
<b-card-img
:src="coverUrl"
:alt="game.name"
/>
</b-col>
<b-col cols="10">
<b-card-body body-class="p-2">
<b-card-title class="mb-2" title-tag="h6">
{{ game.name }}
</b-card-title>
<b-form-rating
v-if="gameRating"
2021-02-21 18:14:46 +00:00
:class="['p-0', { 'bg-dark': darkTheme }]"
2021-02-01 19:37:09 +00:00
inline
:value="gameRating"
readonly
variant="warning"
size="sm"
no-border
/>
</b-card-body>
</b-col>
</b-row>
</b-card>
</template>
<script>
2021-03-23 23:51:48 +00:00
import GameCardMixin from '@/mixins/GameCardMixin';
2021-02-01 19:37:09 +00:00
export default {
2021-03-23 22:55:31 +00:00
mixins: [GameCardMixin],
2021-02-01 19:37:09 +00:00
methods: {
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.showGameToast();
},
showGameToast() {
const h = this.$createElement;
const vNodesMsg = h(
'div', { class: 'image-toast' }, [
h('b-img', {
props: {
src: this.coverUrl,
alt: this.game.name,
width: 80,
},
}),
h('small', `${this.game.name} added`),
],
);
this.$bvToast.toast([vNodesMsg], {
title: this.list.name,
solid: true,
variant: 'info',
});
},
},
};
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
.image-toast {
display: grid;
grid-gap: .5rem;
}
.game-card {
cursor: pointer;
}
</style>