gamebrary/src/components/Boards.vue

202 lines
4.8 KiB
Vue
Raw Normal View History

2020-08-18 18:56:10 +00:00
<template lang="html">
2020-09-01 22:04:43 +00:00
<div>
2020-09-26 00:09:20 +00:00
<!-- TODO: allow board settings to be accessed here -->
2020-09-01 22:04:43 +00:00
<div class="d-flex justify-content-between align-items-center">
2020-10-05 18:42:04 +00:00
<h5>{{ $t('boards.title') }}</h5>
2020-08-18 18:56:10 +00:00
2020-10-14 21:49:06 +00:00
<create-board />
2020-08-18 18:56:10 +00:00
</div>
2020-08-25 23:38:19 +00:00
<div class="text-right" v-if="!loading && !boards.length">
<b-img src="/static/img/empty-state.png" fluid class="mr-5" />
</div>
<template v-if="loading">
<b-card
v-for="n in 3"
:key="n"
no-body
img-left
class="w-100 mb-3 p-2 mt-3"
>
<b-skeleton-img
card-img="left"
width="210px"
/>
<div class="w-50 ml-3">
<b-skeleton class="w-50" />
<b-skeleton class="w-25" />
</div>
</b-card>
</template>
<template v-else>
2020-09-08 22:51:11 +00:00
<b-card
v-for="board in sortedBoards"
:key="board.id"
no-body
2020-10-14 00:08:56 +00:00
:bg-variant="nightMode ? 'dark' : null"
:text-variant="nightMode ? 'white' : null"
2020-09-08 22:51:11 +00:00
class="overflow-hidden clickable mt-3"
@click="viewBoard(board.id)"
>
2020-10-22 21:54:05 +00:00
<b-row>
<b-col cols="6" md="3">
2020-10-22 21:54:05 +00:00
<b-img
v-if="board.wallpaper"
rounded
class="m-2 w-100"
2020-09-09 20:38:52 +00:00
:src="getWallpaper(board)"
:alt="board.name"
/>
2020-10-22 21:54:05 +00:00
<b-img
v-else
rounded
:alt="board.name"
class="m-2 w-100"
width="150"
height="84"
blank
blank-color="darkgray"
fluid
/>
2020-09-08 22:51:11 +00:00
</b-col>
<b-col cols="6" md="9" class="p-2" >
2020-10-22 21:54:05 +00:00
<h6 class="m-0">{{ board.name }}</h6>
<small :id="board.id">
{{ board.platforms.length }} {{ $t('boards.platforms') }}
</small>
<b-popover :target="board.id" triggers="hover">
<div v-for="id in board.platforms" :key="id">
{{ platformNames[id].name }}
</div>
</b-popover>
<p class="text-muted small" v-if="board.description">
{{ board.description }}
</p>
2020-09-08 22:51:11 +00:00
</b-col>
</b-row>
</b-card>
</template>
2020-08-18 18:56:10 +00:00
</div>
</template>
<script>
import CreateBoard from '@/components/Board/CreateBoard';
2020-08-26 18:07:13 +00:00
import { mapState, mapGetters } from 'vuex';
2020-08-18 18:56:10 +00:00
export default {
components: {
CreateBoard,
},
data() {
return {
loading: false,
};
},
computed: {
2020-10-14 00:36:49 +00:00
...mapState(['boards', 'wallpapers', 'gameLists', 'settings']),
2020-10-14 00:08:56 +00:00
...mapGetters(['platformNames', 'sortedBoards', 'nightMode']),
2020-09-06 14:53:04 +00:00
hasLists() {
return Object.keys(this.gameLists).length > 0;
},
2020-08-18 18:56:10 +00:00
},
mounted() {
this.load();
},
methods: {
load() {
this.loadBoards();
2020-08-22 12:24:24 +00:00
this.loadPlatforms();
},
2020-09-01 22:04:43 +00:00
getWallpaper({ wallpaper, name }) {
const boardWallpaper = this.wallpapers.find(({ fullPath }) => fullPath === wallpaper);
2020-08-28 21:56:20 +00:00
2020-09-01 22:04:43 +00:00
return this.wallpapers.length && boardWallpaper && boardWallpaper.url
? boardWallpaper.url
2020-09-08 22:51:11 +00:00
: `https://via.placeholder.com/300x100?text=${name}`;
2020-08-28 21:56:20 +00:00
},
getPlatformImage(id) {
const { platformNames } = this;
return id && platformNames && platformNames[id] && platformNames[id].logoFormat
? `/static/platform-logos/${platformNames[id].slug}.${platformNames[id].logoFormat}`
: '';
},
2020-08-22 12:24:24 +00:00
async loadPlatforms() {
await this.$store.dispatch('LOAD_IGDB_PLATFORMS')
.catch(() => {
this.$bvToast.toast('There was an error loading platforms', { title: 'Error', variant: 'error' });
});
2020-08-18 18:56:10 +00:00
},
async loadBoards() {
this.loading = true;
await this.$store.dispatch('LOAD_BOARDS')
.catch(() => {
this.loading = false;
2020-09-23 23:01:39 +00:00
this.$store.commit('SET_SESSION_EXPIRED', true);
2020-08-18 18:56:10 +00:00
});
this.loading = false;
},
viewBoard(id) {
this.$router.push({ name: 'board', params: { id } });
},
confirmDelete(id) {
this.$bvModal.msgBoxConfirm('Are you sure you want to delete this board?', {
title: 'Delete board',
okVariant: 'danger',
okTitle: 'Yes, delete board',
})
.then((value) => {
if (value) {
this.deleteBoard(id);
}
});
},
async deleteBoard(id) {
this.loading = true;
await this.$store.dispatch('DELETE_BOARD', id)
.catch(() => {
this.loading = false;
this.$bvToast.toast('There was an error deleting board', { title: 'Error', variant: 'error' });
});
this.loading = false;
this.$bvToast.toast('Board removed', { title: 'Success', variant: 'success' });
},
},
};
</script>
2020-08-26 21:23:28 +00:00
<style lang="scss" rel="stylesheet/scss">
.b-avatar .b-avatar-img img {
width: 40px !important;
height: auto !important;
max-width: 100% !important;
max-height: 100% !important;
}
</style>