allow to open game in sidebar

This commit is contained in:
gamebrary 2021-09-10 13:02:29 -07:00
parent 4173f16da8
commit a7b8fef10d
6 changed files with 195 additions and 3 deletions

View file

@ -0,0 +1,180 @@
<template lang="html">
<b-sidebar
:id="gameDetailView === 'side' ? 'game-sidebar' : ''"
bg-variant="dark"
text-variant="white"
right
backdrop
@shown="load"
@hidden="reset"
>
<!-- TODO: restrict usage of sidebar when setting is set -->
<game :game="game" :loading="loading" />
</b-sidebar>
</template>
<script>
import { mapState } from 'vuex';
import Game from '@/components/Game';
import GameNotesModal from '@/components/Game/GameNotesModal';
import GameProgress from '@/components/Game/GameProgress';
import AddRemoveGame from '@/components/Game/AddRemoveGame';
import GameTagsModal from '@/components/Game/GameTagsModal';
export default {
components: {
Game,
GameTagsModal,
GameNotesModal,
GameProgress,
AddRemoveGame,
},
data() {
return {
gameId: null,
coverVisible: true,
game: {},
loading: true,
};
},
computed: {
...mapState(['board', 'notes', 'activeGame', 'games', 'platform', 'user', 'settings']),
gameDetailView() {
return this.settings && this.settings.gameDetailView;
},
hasMultipleGames() {
// TODO: use optional chaining
return this.activeGame
&& this.activeGame.list
&& this.activeGame.list.games
&& this.activeGame.list.games.length > 1;
},
standalone() {
return this.activeGame && !this.activeGame.list;
},
rating() {
return this.game && this.game.rating
? Math.round((this.game.rating / 20) * 2) / 2
: false;
},
gameIndex() {
const { gameId, list } = this.activeGame;
return list && list.games.indexOf(gameId);
},
prevDisabled() {
return !this.activeGame.list || this.gameIndex === 0;
},
nextDisabled() {
const { list } = this.activeGame;
const isLast = this.list && list.games && this.gameIndex === list.games.length - 1;
return !this.list || isLast;
},
},
watch: {
activeGame(value) {
if (value) {
this.load();
}
},
},
methods: {
toggleCoverVisible(value) {
this.coverVisible = value;
},
previousGame() {
// TODO: account for list sorting when getting previous game
this.loading = true;
const { gameId, list } = this.activeGame;
const index = list.games.indexOf(gameId);
const prevGameId = list.games[index - 1];
this.$store.commit('SET_GAME_MODAL_DATA', {
gameId: prevGameId,
list,
});
},
nextGame() {
// TODO: account for list sorting when getting next game
this.loading = true;
const { gameId, list } = this.activeGame;
const index = list.games.indexOf(gameId);
const nextGameId = list.games[index + 1];
this.$store.commit('SET_GAME_MODAL_DATA', {
gameId: nextGameId,
list,
});
},
load() {
const { gameId, list } = this.activeGame;
this.gameId = gameId;
this.list = list;
this.game = this.games[gameId];
this.loadGame();
},
async loadGame() {
this.loading = true;
const { gameId } = this.activeGame;
const game = await this.$store.dispatch('LOAD_GAME', gameId)
.catch(() => {
this.loading = false;
this.$bvToast.toast('Error loading game', { variant: 'error' });
});
// avoid error when closing modal before game finishes loading
if (!this.game) {
return;
}
this.game = {
...this.game,
...game,
};
this.loading = false;
// this.$ga.event({
// eventCategory: 'game',
// eventAction: 'view',
// eventLabel: 'gameViewed',
// eventValue: `${this.platform.name} - ${this.game.name}`,
// });
},
reset() {
this.gameId = null;
this.loading = true;
this.game = {};
},
},
};
</script>

View file

@ -2,6 +2,7 @@
<div> <div>
<create-board-modal /> <create-board-modal />
<game-modal /> <game-modal />
<game-sidebar />
<auth-modal /> <auth-modal />
<template v-if="user"> <template v-if="user">
@ -16,6 +17,7 @@ import { mapState } from 'vuex';
import DevToolsModal from '@/components/DevToolsModal'; import DevToolsModal from '@/components/DevToolsModal';
import GameModal from '@/components/Game/GameModal'; import GameModal from '@/components/Game/GameModal';
import GameSidebar from '@/components/Game/GameSidebar';
import CreateBoardModal from '@/components/Board/CreateBoardModal'; import CreateBoardModal from '@/components/Board/CreateBoardModal';
import AuthModal from '@/components/AuthModal'; import AuthModal from '@/components/AuthModal';
import KeyboardShortcutsModal from '@/components/KeyboardShortcutsModal'; import KeyboardShortcutsModal from '@/components/KeyboardShortcutsModal';
@ -27,6 +29,7 @@ export default {
KeyboardShortcutsModal, KeyboardShortcutsModal,
CreateBoardModal, CreateBoardModal,
GameModal, GameModal,
GameSidebar,
}, },
computed: { computed: {

View file

@ -76,6 +76,7 @@
:list="list" :list="list"
:game-id="game" :game-id="game"
:class="{ 'mb-2': view !== 'covers'}" :class="{ 'mb-2': view !== 'covers'}"
v-b-toggle.game-sidebar
@click.native="openGame(game, list)" @click.native="openGame(game, list)"
/> />
@ -213,6 +214,8 @@ export default {
if (gameDetailView === 'new') { if (gameDetailView === 'new') {
this.$router.push({ name: 'game', params: { gameId } }); this.$router.push({ name: 'game', params: { gameId } });
} else if (gameDetailView === 'side') {
// TODO: find a way to open sidebar programatically, open defect in gh?
} else { } else {
this.$bvModal.show('game-modal'); this.$bvModal.show('game-modal');
} }

View file

@ -215,9 +215,9 @@ export const SUPPORTED_LANGUAGES = [
]; ];
export const GAME_DETAIL_VIEWS = [ export const GAME_DETAIL_VIEWS = [
{ name: 'Modal', value: null },
// { name: 'Side panel', value: 'side' },
// { name: 'popup', value: 'popup' }, // { name: 'popup', value: 'popup' },
{ name: 'Modal', value: null },
{ name: 'Side panel', value: 'side' },
{ name: 'New page', value: 'new' }, { name: 'New page', value: 'new' },
]; ];

View file

@ -36,7 +36,7 @@ import GameDetailSettings from '@/components/Settings/GameDetailSettings';
// import ProviderCard from '@/components/ProviderCard'; // import ProviderCard from '@/components/ProviderCard';
import DeleteAccountModal from '@/components/Settings/DeleteAccountModal'; import DeleteAccountModal from '@/components/Settings/DeleteAccountModal';
import sessionMixin from '@/mixins/sessionMixin'; import sessionMixin from '@/mixins/sessionMixin';
import { mapState, mapGetters } from 'vuex'; import { mapState } from 'vuex';
export default { export default {
components: { components: {

View file

@ -19,6 +19,12 @@
} }
} }
.b-sidebar {
width: 500px;
max-width: calc(100% - 1rem);
}
/* custom scrollbar */ /* custom scrollbar */
::-webkit-scrollbar { ::-webkit-scrollbar {
width: 8px; width: 8px;