gamebrary/src/components/Board/PinnedBoards.vue

120 lines
2.8 KiB
Vue
Raw Normal View History

2021-01-25 21:05:35 +00:00
<template lang="html">
<div>
2021-02-19 22:59:21 +00:00
<template v-if="pinnedBoards.length">
<span
v-for="{ id, name, backgroundColor, backgroundUrl } in pinnedBoards"
2021-02-19 22:59:21 +00:00
:key="id"
>
<b-avatar
rounded
:class="['mb-1 cursor-pointer pinned-board', { active: board.name === name }]"
:title="name"
@click.native="viewBoard(id)"
:style="`
${backgroundColor ? `background-color: ${backgroundColor};` : null }
${getWallpaperUrl(backgroundUrl)}
2021-02-19 22:59:21 +00:00
`"
>
<span class="board-initials text-uppercase">{{ getBoardInitials(name) }}</span>
</b-avatar>
</span>
<hr class="mb-1 mt-0">
</template>
<template v-if="isBoard && !board.pinned">
2021-01-25 21:05:35 +00:00
<b-avatar
rounded
2021-02-19 22:59:21 +00:00
class="active pinned-board"
:title="board.name"
2021-01-25 21:05:35 +00:00
:style="`
2021-02-19 22:59:21 +00:00
${board.backgroundColor ? ` background-color: ${board.backgroundColor};` : null }
${getWallpaperUrl(board.backgroundUrl) }
2021-01-25 21:05:35 +00:00
`"
2021-02-19 22:59:21 +00:00
@click.native="$bvModal.show('edit-board')"
>
2021-02-19 22:59:21 +00:00
<span class="board-initials text-uppercase mr-1">
{{ getBoardInitials(board.name) }}
</span>
</b-avatar>
2021-02-19 22:59:21 +00:00
<hr class="my-1">
</template>
2021-01-25 21:05:35 +00:00
</div>
</template>
<script>
import { mapGetters, mapState } from 'vuex';
export default {
computed: {
...mapState(['board', 'boards', 'wallpapers']),
2021-02-21 18:14:46 +00:00
...mapGetters(['sortedBoards', 'darkTheme']),
2021-01-25 21:05:35 +00:00
isBoard() {
return ['public-board', 'board'].includes(this.$route.name);
},
hasMultipleBoards() {
return this.$route.name === 'board' && this.board.name && this.sortedBoards.length > 1;
},
pinnedBoards() {
return this.boards.filter(({ pinned }) => pinned);
},
},
methods: {
getWallpaperUrl(url) {
if (!url) {
2021-02-27 05:35:08 +00:00
return '';
}
if (url && url.includes('igdb.com')) {
return `background-image: url(${url});`;
}
2021-02-27 05:35:08 +00:00
const wallpaperObject = this.wallpapers.find(({ fullPath }) => fullPath === url);
2021-01-25 21:05:35 +00:00
2021-02-27 05:35:08 +00:00
return wallpaperObject && wallpaperObject.url
2021-01-25 21:05:35 +00:00
? `background-image: url(${wallpaperObject.url});`
2021-02-27 05:35:08 +00:00
: '';
2021-01-25 21:05:35 +00:00
},
viewBoard(id) {
if (this.board.id !== id) {
this.$router.push({ name: 'board', params: { id } });
2021-02-03 23:38:37 +00:00
} else {
this.$bvModal.show('edit-board');
2021-01-25 21:05:35 +00:00
}
},
getBoardInitials(boardName) {
const boardInitials = boardName
? boardName.split(' ').map(n => n[0]).join('')
: '';
return boardInitials.length > 2
? boardInitials.substring(0, 2)
: boardInitials;
},
},
};
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
.pinned-board {
background-size: cover;
2021-02-01 23:20:41 +00:00
2021-02-18 23:07:45 +00:00
&.active {
box-shadow: inset 0 0 0 2px black;
2021-02-01 23:20:41 +00:00
}
2021-01-25 21:05:35 +00:00
}
2021-01-25 23:45:12 +00:00
.board-initials {
color: white;
text-shadow: 1px 1px black;
}
2021-02-01 19:31:15 +00:00
2021-01-25 21:05:35 +00:00
</style>