gamebrary/src/components/Game/GameModal.vue

335 lines
8.1 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-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-14 00:09:37 +00:00
<!-- header-bg-variant="dark"
body-bg-variant="dark"
footer-bg-variant="dark" -->
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"
:subtitle="gameModalData.list.name"
2020-10-14 21:47:02 +00:00
@close="close"
/>
<b-button-group>
<b-button
size="sm"
:variant="nightMode ? 'dark' : 'light'"
:disabled="prevDisabled"
@click="previousGame"
>
<icon name="triangle-left" />
</b-button>
<b-button
size="sm"
2020-10-14 21:47:02 +00:00
:variant="nightMode ? 'dark' : 'light'"
:disabled="nextDisabled"
@click="nextGame"
>
2020-10-14 21:47:02 +00:00
<icon name="triangle-right" />
2020-10-08 19:16:50 +00:00
</b-button>
2020-10-14 21:47:02 +00:00
</b-button-group>
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-08-14 23:58:55 +00:00
<b-img
:src="coverUrl"
2020-08-22 12:21:15 +00:00
:alt="game.name"
2020-08-25 05:18:56 +00:00
class="game-cover"
2020-08-14 23:58:55 +00:00
rounded
fluid
/>
<game-screenshots :game="game" v-if="!loading" />
2020-10-08 19:16:50 +00:00
<game-notes-tab :game="game" />
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-08-21 06:13:45 +00:00
<!-- <h6>
2020-08-14 23:58:55 +00:00
<b-badge
v-if="releaseDate"
variant="secondary"
>
Releases in
{{ releaseDate }}
</b-badge>
2020-08-21 06:13:45 +00:00
</h6> -->
2020-08-14 23:58:55 +00:00
<b-form-rating
v-if="rating"
:value="rating"
2020-08-31 22:19:53 +00:00
class="p-0 mt-1 border-0 shadow-none"
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-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-08 19:16:50 +00:00
<b-progress
v-if="progress"
:value="progress"
variant="success"
height="8px"
class="mt-2"
/>
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" />
<game-notes :game="game" />
<game-tags :game="game" />
<add-remove-game :game="game" :list="list" />
</div>
2020-09-30 23:11:09 +00:00
<template v-if="loading">
<b-skeleton v-for="n in 3" :key="n" />
2020-10-08 19:16:50 +00:00
<game-detail-placeholder />
2020-09-30 23:11:09 +00:00
</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" />
<game-websites-tab :game="game" />
<game-videos-tab :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>
import moment from 'moment';
2020-10-14 21:47:02 +00:00
import { mapState, mapGetters } from 'vuex';
2020-08-18 18:56:10 +00:00
import GameDetailPlaceholder from '@/components/Game/GameDetailPlaceholder';
2020-10-08 19:16:50 +00:00
import GameDetails from '@/components/Game/GameDetails';
2020-08-22 12:21:15 +00:00
import GameNotesTab from '@/components/Game/GameNotesTab';
2020-10-08 19:16:50 +00:00
import GameScreenshots from '@/components/Game/GameScreenshots';
2020-08-22 12:21:15 +00:00
import GameVideosTab from '@/components/Game/GameVideosTab';
import GameWebsitesTab from '@/components/Game/GameWebsitesTab';
import GameNotes from '@/components/Game/GameNotes';
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,
GameDetailPlaceholder,
2020-10-08 19:16:50 +00:00
GameDetails,
2020-08-22 12:21:15 +00:00
GameNotesTab,
2020-10-08 19:16:50 +00:00
GameScreenshots,
2020-08-22 12:21:15 +00:00
GameVideosTab,
GameWebsitesTab,
GameNotes,
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
releaseDate() {
const releaseDate = this.game
&& this.game.release_dates
&& this.game.release_dates.find(({ platform }) => this.platform.id === platform);
const formattedDate = releaseDate && releaseDate.date
? moment.unix(releaseDate.date)
: null;
return moment(formattedDate).isAfter()
? formattedDate.toNow(true)
: null;
},
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;
return list.games.indexOf(gameId);
},
prevDisabled() {
return this.gameIndex === 0;
},
nextDisabled() {
const { list } = this.gameModalData;
return this.gameIndex === list.games.length - 1;
},
2020-08-14 23:58:55 +00:00
},
methods: {
previousGame() {
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() {
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)
.catch(() => {
this.loading = false;
this.$bvToast.toast('Error loading game', { title: 'Error', variant: 'error' });
});
// 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
// max-height: 50vh;
width: 100%;
2020-08-25 05:18:56 +00:00
margin: 0 auto;
}
2020-08-22 12:21:15 +00:00
</style>