gamebrary/src/components/Boards.vue

168 lines
3.7 KiB
Vue
Raw Normal View History

2020-08-18 18:56:10 +00:00
<template lang="html">
2021-01-20 21:04:48 +00:00
<b-container>
2020-09-26 00:09:20 +00:00
<!-- TODO: allow board settings to be accessed here -->
2021-01-20 21:04:48 +00:00
<div v-if="showPlaceholder" class="boards">
<b-card
v-for="n in 3"
:key="n"
no-body
2021-01-20 21:04:48 +00:00
class="mb-3 p-1 mt-3"
>
2021-01-20 21:04:48 +00:00
<b-skeleton-img />
</b-card>
2021-01-20 21:04:48 +00:00
</div>
2020-11-23 18:09:33 +00:00
<empty-state
v-else-if="!boards.length"
title="Boards"
message="Use boards to easily organize your video game collections"
>
2021-02-01 21:11:31 +00:00
<b-button
2021-02-21 18:14:46 +00:00
:variant="darkTheme ? 'dark' : 'primary'"
2021-02-01 21:11:31 +00:00
v-b-modal:create-board
>
{{ $t('boards.create') }}
</b-button>
2020-11-23 18:09:33 +00:00
</empty-state>
2020-11-22 03:31:18 +00:00
2021-01-20 21:04:48 +00:00
<div v-else class="d-flex w-100 justify-content-between align-items-center mb-3">
<h3 class="m-0 mr-a">{{ $t('boards.title') }}</h3>
2020-11-22 03:31:18 +00:00
2021-02-01 21:11:31 +00:00
<b-button
variant="primary"
2021-02-01 21:11:31 +00:00
v-b-modal:create-board
>
{{ $t('boards.create') }}
</b-button>
2021-01-20 21:04:48 +00:00
</div>
2020-11-22 03:31:18 +00:00
2021-01-20 21:04:48 +00:00
<div class="boards">
<b-card
v-for="board in sortedBoards"
:key="board.id"
no-body
2021-02-21 18:14:46 +00:00
:bg-variant="darkTheme ? 'dark' : null"
:text-variant="darkTheme ? 'white' : null"
2021-01-20 21:04:48 +00:00
class="overflow-hidden clickable"
@click="viewBoard(board.id)"
>
<mini-board
:board="board"
:background-image="getWallpaper(board)"
/>
</b-card>
</div>
2020-12-18 04:44:40 +00:00
</b-container>
2020-08-18 18:56:10 +00:00
</template>
<script>
import MiniBoard from '@/components/Board/MiniBoard';
2020-11-22 03:31:18 +00:00
import EmptyState from '@/components/EmptyState';
2020-08-26 18:07:13 +00:00
import { mapState, mapGetters } from 'vuex';
2020-08-18 18:56:10 +00:00
export default {
components: {
MiniBoard,
2020-11-22 03:31:18 +00:00
EmptyState,
2020-08-18 18:56:10 +00:00
},
data() {
return {
loading: false,
};
},
computed: {
...mapState(['boards', 'wallpapers', 'gameLists']),
2021-02-21 18:14:46 +00:00
...mapGetters(['platformNames', 'sortedBoards', 'darkTheme']),
2020-09-06 14:53:04 +00:00
hasLists() {
return Object.keys(this.gameLists).length > 0;
},
2020-12-17 19:26:08 +00:00
showPlaceholder() {
2020-12-18 04:46:31 +00:00
return this.loading && Object.keys(this.boards).length === 0;
2020-12-17 19:26:08 +00:00
},
2020-08-18 18:56:10 +00:00
},
mounted() {
this.load();
},
methods: {
load() {
2020-08-22 12:24:24 +00:00
this.loadPlatforms();
},
getWallpaper({ wallpaper }) {
2020-09-01 22:04:43 +00:00
const boardWallpaper = this.wallpapers.find(({ fullPath }) => fullPath === wallpaper);
2020-08-28 21:56:20 +00:00
return this.wallpapers.length && boardWallpaper && boardWallpaper.url;
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(() => {
2020-12-10 05:26:57 +00:00
this.$bvToast.toast('There was an error loading platforms', { variant: 'error' });
2020-08-22 12:24:24 +00:00
});
2020-11-22 05:00:17 +00:00
this.loadBoards();
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 } });
},
async deleteBoard(id) {
this.loading = true;
await this.$store.dispatch('DELETE_BOARD', id)
.catch(() => {
this.loading = false;
2020-12-10 05:26:57 +00:00
this.$bvToast.toast('There was an error deleting board', { variant: 'error' });
2020-08-18 18:56:10 +00:00
});
this.loading = false;
2020-12-10 05:26:57 +00:00
this.$bvToast.toast('Board removed');
2020-08-18 18:56:10 +00:00
},
},
};
</script>
2020-08-26 21:23:28 +00:00
<style lang="scss" rel="stylesheet/scss" scoped>
.boards {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 1rem;
@media(max-width: 780px) {
grid-template-columns: 1fr 1fr;
}
@media(max-width: 480px) {
grid-template-columns: 1fr;
}
2020-08-26 21:23:28 +00:00
}
</style>