gamebrary/src/components/Game/GameModal.vue

339 lines
8.2 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"
2020-10-14 00:09:37 +00:00
header-class="align-items-center pb-0 border-0"
2020-11-22 03:31:18 +00:00
body-class="pt-1"
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"
:footer-bg-variant="nightMode ? 'dark' : null"
:footer-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
>
<b-button-group v-if="hasMultipleGames">
2020-10-14 21:47:02 +00:00
<b-button
size="sm"
:variant="nightMode ? 'dark' : 'light'"
:disabled="prevDisabled"
@click="previousGame"
>
<i class="fas fa-caret-left fa-fw" aria-hidden></i>
2020-10-14 21:47:02 +00:00
</b-button>
<b-button
size="sm"
2020-10-14 21:47:02 +00:00
:variant="nightMode ? 'dark' : 'light'"
:disabled="nextDisabled"
@click="nextGame"
>
<i class="fas fa-caret-right fa-fw" aria-hidden></i>
2020-10-08 19:16:50 +00:00
</b-button>
2020-10-14 21:47:02 +00:00
</b-button-group>
2020-10-23 16:20:35 +00:00
</modal-header>
2020-10-08 19:16:50 +00:00
</template>
2020-08-25 05:18:56 +00:00
<b-container v-if="game.name" class="m-0 p-0">
2020-08-14 23:58:55 +00:00
<b-row>
2020-10-08 19:16:50 +00:00
<b-col cols="12" md="4">
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
:src="coverUrl"
:alt="game.name"
class="game-cover"
rounded
/>
<game-screenshots :game="game" />
</template>
2020-11-03 22:49:30 +00:00
<game-notes :game="game" />
2020-11-07 05:49:11 +00:00
<!-- TODO: add related games -->
<!-- More games like {{ game.name }} -->
<!-- <pre>{{ game.genres.map(({ id }) => id) }}</pre> -->
2020-08-14 23:58:55 +00:00
</b-col>
2020-08-25 05:18:56 +00:00
<b-col cols="12" md="8" class="mt-md-0 mt-3 text-md-left text-center">
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"
class="my-1 w-50"
/>
2020-08-14 23:58:55 +00:00
<b-form-rating
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
<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}`"
>
{{ name }}
</b-badge>
2020-10-14 00:09:37 +00:00
<div
v-if="loading"
class="my-2 d-flex justify-content-md-start justify-content-center"
>
<b-skeleton
v-for="n in 4"
:key="n"
type="button"
width="45px"
class="mr-1"
/>
2020-08-14 23:58:55 +00:00
</div>
2020-09-30 23:08:11 +00:00
<div v-else class="my-2">
2020-08-22 12:21:15 +00:00
<game-progress :game="game" />
2020-11-03 22:49:30 +00:00
<game-notes-modal :game="game" />
2020-08-22 12:21:15 +00:00
<game-tags :game="game" />
<add-remove-game v-if="list" :game="game" :list="list" />
2020-08-22 12:21:15 +00:00
</div>
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>
<p class="text-left">{{ game.summary }}</p>
2020-10-08 19:16:50 +00:00
<game-details :game="game" />
2020-11-03 22:49:30 +00:00
<game-websites :game="game" />
<game-videos :game="game" />
2020-10-08 19:16:50 +00:00
</template>
2020-08-14 23:58:55 +00:00
</b-col>
</b-row>
</b-container>
<template v-slot:modal-footer>
<igdb-logo />
</template>
</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';
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 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';
2020-08-18 18:56:10 +00:00
import GameTags from '@/components/Game/GameTags';
2020-08-14 23:58:55 +00:00
import IgdbLogo from '@/components/IgdbLogo';
export default {
components: {
GameTags,
IgdbLogo,
2020-10-08 19:16:50 +00:00
GameDetails,
2020-08-22 12:21:15 +00:00
GameNotes,
2020-11-03 22:49:30 +00:00
GameScreenshots,
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,
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
2020-08-22 12:21:15 +00:00
...mapState(['gameModalData', 'games', 'platform', 'progresses', 'tags']),
2020-10-14 21:47:02 +00:00
...mapGetters(['nightMode']),
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
},
coverUrl() {
return this.game
&& this.game.cover
&& this.game.cover.image_id
? `https://images.igdb.com/igdb/image/upload/t_cover_big_2x/${this.game.cover.image_id}.jpg`
: '/static/no-image.jpg';
},
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
},
methods: {
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,
});
this.load();
},
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,
});
this.load();
},
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;
@media(max-width: 780px) {
max-height: 40vh;
width: auto;
display: block;
margin: 0 auto;
}
2020-08-25 05:18:56 +00:00
}
2020-08-22 12:21:15 +00:00
</style>