gamebrary/src/components/Game/GameModal.vue

396 lines
9.7 KiB
Vue
Raw Normal View History

2020-08-14 23:58:55 +00:00
<template lang="html">
<b-modal
id="game-modal"
scrollable
size="lg"
footer-class="p-2 justify-content-center"
2021-01-04 20:15:32 +00:00
header-class="align-items-center border-0 pb-2"
hide-footer
body-class="pt-0"
2020-10-14 21:47:02 +00:00
:header-bg-variant="nightMode ? 'dark' : null"
:header-text-variant="nightMode ? 'white' : null"
:body-bg-variant="nightMode ? 'dark' : null"
:body-text-variant="nightMode ? 'white' : null"
2020-08-24 16:43:02 +00:00
@show="load"
2020-08-14 23:58:55 +00:00
@hidden="reset"
>
2020-10-08 19:16:50 +00:00
<template v-slot:modal-header="{ close }">
2020-10-14 00:09:37 +00:00
<modal-header
:title="game.name"
2020-11-03 22:49:30 +00:00
:subtitle="gameModalData.list ? gameModalData.list.name : null"
2020-11-02 21:18:25 +00:00
@close="close"
2020-10-23 16:20:35 +00:00
>
<template v-slot:header>
2021-02-12 23:14:10 +00:00
<!-- TODO: Open gallery from cover, also include cover in screenshots carousel -->
<b-img
2021-02-09 20:43:21 +00:00
:src="activeGameCoverUrl"
:alt="game.name"
v-if="!coverVisible"
2021-02-09 20:43:21 +00:00
class="float-left mr-2"
height="40"
rounded
/>
</template>
2021-01-08 06:55:03 +00:00
<b-dropdown
v-if="user && user.uid === board.owner"
2021-01-08 06:55:03 +00:00
right
no-caret
:variant="nightMode ? 'dark' : 'light'"
2021-02-03 21:04:02 +00:00
:menu-class="nightMode ? 'bg-dark' : ''"
2021-01-08 06:55:03 +00:00
>
<template v-slot:button-content>
<i class="fas fa-ellipsis-h fa-fw" aria-hidden></i>
</template>
<game-progress :game="game" />
<game-notes-modal :game="game" />
2021-01-25 23:14:45 +00:00
2021-02-03 21:04:02 +00:00
<b-dropdown-item
v-b-modal.tags
2021-02-11 20:53:12 +00:00
v-shortkey="['t']"
@shortkey.native="$bvModal.show('tags');"
2021-02-03 21:04:02 +00:00
:variant="nightMode ? 'secondary' : null"
>
2021-01-25 23:14:45 +00:00
<i class="far fa-tags fa-fw" /> Tags
<game-tags-modal :game="game" />
</b-dropdown-item>
<b-dropdown-item-button
v-if="!prevDisabled"
2021-02-03 21:04:02 +00:00
:variant="nightMode ? 'secondary' : null"
2021-02-11 20:53:12 +00:00
v-shortkey="['arrowleft']"
@shortkey.native="previousGame"
@click="previousGame"
>
<i class="fas fa-caret-left fa-fw" aria-hidden /> Previous game
</b-dropdown-item-button>
<b-dropdown-item-button
v-if="!nextDisabled"
2021-02-11 20:53:12 +00:00
v-shortkey="['arrowright']"
@shortkey.native="nextGame"
2021-02-03 21:04:02 +00:00
:variant="nightMode ? 'secondary' : null"
@click="nextGame"
>
<i class="fas fa-caret-right fa-fw" aria-hidden /> Next game
</b-dropdown-item-button>
<add-remove-game v-if="list" :game="game" :list="list" />
</b-dropdown>
2020-10-23 16:20:35 +00:00
</modal-header>
2020-10-08 19:16:50 +00:00
</template>
2021-01-04 20:15:32 +00:00
<b-container
v-if="game.name"
fluid
class="m-0 p-0"
>
2020-08-14 23:58:55 +00:00
<b-row>
2021-01-04 20:15:32 +00:00
<b-col
cols="12"
md="5"
lg="4"
2021-02-16 23:03:29 +00:00
class="sidebar pr-md-1"
2021-01-04 20:15:32 +00:00
>
2020-11-29 05:43:42 +00:00
<b-skeleton-img
v-if="loading"
width="100%"
height="200px"
2020-08-14 23:58:55 +00:00
/>
2020-11-29 05:43:42 +00:00
<template v-else>
<b-img
2021-02-09 20:43:21 +00:00
:src="activeGameCoverUrl"
2020-11-29 05:43:42 +00:00
:alt="game.name"
class="game-cover"
v-observe-visibility="toggleCoverVisible"
2020-11-29 05:43:42 +00:00
rounded
/>
<game-screenshots :game="game" />
2021-01-08 06:55:03 +00:00
<!-- <game-videos :videos="game.videos" v-if="game.videos" /> -->
<amazon-links :game="game" class="d-none d-md-inline" />
2020-11-29 05:43:42 +00:00
</template>
2021-02-16 15:54:25 +00:00
<!-- <pre>{{ game.genres.map(({ id }) => id) }}</pre> -->
2021-02-12 23:14:10 +00:00
<!-- TODO: add bundles to game detail? -->
<!-- {{ game.bundles ? `Found in ${game.bundles.length} compilations.` : null }} -->
2020-08-14 23:58:55 +00:00
</b-col>
2021-01-04 20:15:32 +00:00
<!-- cols="12"
md="7" -->
<b-col
cols="12"
md="7"
lg="8"
>
2020-08-22 12:21:15 +00:00
<h3 class="mb-0">{{ game.name }}</h3>
2020-10-14 23:49:05 +00:00
<b-progress
v-if="progress"
:value="progress"
variant="success"
height="8px"
v-b-modal.progress
2021-02-16 21:29:09 +00:00
class="my-1 w-25"
2020-10-14 23:49:05 +00:00
/>
2020-08-14 23:58:55 +00:00
2021-02-16 21:29:09 +00:00
<!-- <b-form-rating
2020-08-14 23:58:55 +00:00
v-if="rating"
:value="rating"
2020-10-14 23:49:05 +00:00
:class="['p-0 mt-1', { 'bg-dark': nightMode }]"
2020-08-22 12:21:15 +00:00
inline
2020-08-14 23:58:55 +00:00
readonly
variant="warning"
size="lg"
no-border
/>
2020-10-14 23:49:05 +00:00
2021-02-16 21:29:09 +00:00
<br /> -->
2020-08-14 23:58:55 +00:00
2020-08-22 12:21:15 +00:00
<b-badge
v-for="({ games, hex, tagTextColor }, name) in tags"
v-if="games.includes(game.id)"
:key="name"
pill
tag="small"
class="mr-1 mb-2"
:style="`background-color: ${hex}; color: ${tagTextColor}`"
2021-01-25 16:51:15 +00:00
v-b-modal.tags
2020-08-22 12:21:15 +00:00
>
{{ name }}
</b-badge>
2020-09-30 23:11:09 +00:00
<template v-if="loading">
<b-skeleton v-for="n in 3" :key="n" />
</template>
2020-10-08 19:16:50 +00:00
<template v-else>
<amazon-links
:game="game"
class="d-md-none"
modal-id="mobile-amazon"
/>
2021-02-16 21:29:09 +00:00
<game-description :game="game" />
<game-notes :game="game" />
<game-details :game="game" />
2020-11-03 22:49:30 +00:00
<game-websites :game="game" />
2021-02-16 21:29:09 +00:00
<similar-games
:game="game"
:loading="loading"
class="mb-2"
/>
2020-10-08 19:16:50 +00:00
</template>
2020-08-14 23:58:55 +00:00
</b-col>
2021-01-04 20:15:32 +00:00
<igdb-logo />
2020-08-14 23:58:55 +00:00
</b-row>
</b-container>
</b-modal>
</template>
<script>
2020-10-14 21:47:02 +00:00
import { mapState, mapGetters } from 'vuex';
2020-10-08 19:16:50 +00:00
import GameDetails from '@/components/Game/GameDetails';
import GameDescription from '@/components/Game/GameDescription';
2021-02-16 15:54:25 +00:00
import SimilarGames from '@/components/Game/SimilarGames';
2020-08-22 12:21:15 +00:00
import GameNotes from '@/components/Game/GameNotes';
2020-11-03 22:49:30 +00:00
import GameScreenshots from '@/components/Game/GameScreenshots';
import AmazonLinks from '@/components/Game/AmazonLinks';
2020-11-03 22:49:30 +00:00
import GameVideos from '@/components/Game/GameVideos';
import GameWebsites from '@/components/Game/GameWebsites';
import GameNotesModal from '@/components/Game/GameNotesModal';
2020-08-22 12:21:15 +00:00
import GameProgress from '@/components/Game/GameProgress';
import AddRemoveGame from '@/components/Game/AddRemoveGame';
2021-01-25 23:14:45 +00:00
import GameTagsModal from '@/components/Game/GameTagsModal';
2020-08-14 23:58:55 +00:00
import IgdbLogo from '@/components/IgdbLogo';
export default {
components: {
2021-01-25 23:14:45 +00:00
GameTagsModal,
2020-08-14 23:58:55 +00:00
IgdbLogo,
2020-10-08 19:16:50 +00:00
GameDetails,
GameDescription,
2021-02-16 15:54:25 +00:00
SimilarGames,
2020-08-22 12:21:15 +00:00
GameNotes,
2020-11-03 22:49:30 +00:00
GameScreenshots,
AmazonLinks,
2020-11-03 22:49:30 +00:00
GameVideos,
GameWebsites,
GameNotesModal,
2020-08-22 12:21:15 +00:00
GameProgress,
AddRemoveGame,
2020-08-14 23:58:55 +00:00
},
data() {
return {
gameId: null,
coverVisible: true,
2020-08-22 12:21:15 +00:00
game: {},
2020-08-14 23:58:55 +00:00
loading: true,
};
},
computed: {
2020-08-21 06:13:45 +00:00
// TODO: rename gameModalData
...mapState(['board', 'gameModalData', 'games', 'platform', 'progresses', 'tags', 'user']),
2021-02-09 20:43:21 +00:00
...mapGetters(['nightMode', 'activeGameCoverUrl']),
2020-08-14 23:58:55 +00:00
hasMultipleGames() {
// TODO: use optional chaining
return this.gameModalData
&& this.gameModalData.list
&& this.gameModalData.list.games
&& this.gameModalData.list.games.length > 1;
},
2020-08-14 23:58:55 +00:00
progress() {
2020-08-15 20:41:43 +00:00
const { gameId, progresses } = this;
2020-08-14 23:58:55 +00:00
2020-08-15 20:41:43 +00:00
return progresses[gameId] || null;
2020-08-14 23:58:55 +00:00
},
rating() {
return this.game && this.game.rating
? Math.round((this.game.rating / 20) * 2) / 2
: false;
},
gameIndex() {
const { gameId, list } = this.gameModalData;
2020-11-03 22:49:30 +00:00
return list && list.games.indexOf(gameId);
},
prevDisabled() {
return this.gameIndex === 0;
},
nextDisabled() {
const { list } = this.gameModalData;
2020-11-03 22:49:30 +00:00
return this.list && list.games && this.gameIndex === list.games.length - 1;
},
2020-08-14 23:58:55 +00:00
},
2021-02-16 15:54:25 +00:00
watch: {
gameModalData(value) {
if (value) {
this.load();
}
},
},
2020-08-14 23:58:55 +00:00
methods: {
toggleCoverVisible(value) {
this.coverVisible = value;
},
previousGame() {
// TODO: account for list sorting when getting previous game
2020-11-29 05:43:42 +00:00
this.loading = true;
const { gameId, list } = this.gameModalData;
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
2020-11-29 05:43:42 +00:00
this.loading = true;
const { gameId, list } = this.gameModalData;
const index = list.games.indexOf(gameId);
const nextGameId = list.games[index + 1];
this.$store.commit('SET_GAME_MODAL_DATA', {
gameId: nextGameId,
list,
});
},
2020-08-24 16:43:02 +00:00
load() {
2020-08-21 06:13:45 +00:00
const { gameId, list } = this.gameModalData;
this.gameId = gameId;
this.list = list;
this.game = this.games[gameId];
2020-08-24 16:43:02 +00:00
this.loadGame();
2020-08-21 06:13:45 +00:00
},
async loadGame() {
this.loading = true;
const { gameId } = this.gameModalData;
const game = await this.$store.dispatch('LOAD_GAME', gameId)
2020-10-21 23:03:09 +00:00
.catch(() => {
2020-08-21 06:13:45 +00:00
this.loading = false;
2020-12-10 05:26:57 +00:00
this.$bvToast.toast('Error loading game', { variant: 'error' });
2020-08-21 06:13:45 +00:00
});
// avoid error when closing modal before game finishes loading
if (!this.game) {
return;
}
this.game = {
...this.game,
...game,
};
this.loading = false;
2020-08-26 00:06:49 +00:00
// this.$ga.event({
// eventCategory: 'game',
// eventAction: 'view',
// eventLabel: 'gameViewed',
// eventValue: `${this.platform.name} - ${this.game.name}`,
// });
2020-08-21 06:13:45 +00:00
},
2020-08-14 23:58:55 +00:00
reset() {
this.gameId = null;
2020-08-22 12:21:15 +00:00
this.loading = true;
this.game = {};
2020-08-14 23:58:55 +00:00
},
},
};
</script>
2020-08-22 12:21:15 +00:00
2020-08-25 05:18:56 +00:00
<style lang="scss" rel="stylesheet/scss" scoped>
2020-08-22 12:21:15 +00:00
.b-rating {
line-height: normal !important;
height: auto !important;
}
2020-08-25 05:18:56 +00:00
.game-cover {
2020-10-08 19:16:50 +00:00
width: 100%;
2020-11-07 05:49:11 +00:00
height: auto;
}
2020-11-07 05:49:11 +00:00
2021-01-10 19:57:23 +00:00
.sidebar {
@media(min-width: 768px) {
position: sticky;
top: 0;
align-self: baseline;
}
}
2020-08-22 12:21:15 +00:00
</style>