gamebrary/src/pages/ShareList/ShareList.vue

210 lines
5.4 KiB
Vue
Raw Normal View History

2018-10-19 05:15:28 +00:00
<template lang="html">
2018-11-21 02:43:10 +00:00
<main v-dragscroll:nochilddrag>
2019-01-11 20:20:21 +00:00
<game-board-placeholder v-if="loading" />
2018-11-21 02:43:10 +00:00
<section
v-if="!loading && listData && publicGameData"
v-for="list in listData"
:key="list.name"
>
<header>{{ list.name }} ({{ list.games.length }})</header>
2019-01-11 20:20:21 +00:00
<div class="games">
<p v-if="!list.games.length">This list is empty</p>
2018-10-19 05:15:28 +00:00
2018-11-21 02:43:10 +00:00
<div
v-if="publicGameData[game]"
class="game-card"
v-for="game in list.games"
:key="game"
>
2018-10-19 05:15:28 +00:00
<img
2018-11-21 06:14:29 +00:00
v-if="publicGameData[game].cover"
2018-11-21 02:43:10 +00:00
height="30"
:src="`https://images.igdb.com/igdb/image/upload/t_cover_small/${publicGameData[game].cover.cloudinary_id}.jpg`"
2018-10-19 05:15:28 +00:00
/>
2018-11-21 02:43:10 +00:00
<strong>{{ publicGameData[game].name }}</strong>
2018-10-19 05:15:28 +00:00
</div>
</div>
2018-11-21 02:43:10 +00:00
</section>
</main>
2018-10-19 05:15:28 +00:00
</template>
<script>
2018-11-21 02:43:10 +00:00
import firebase from 'firebase/app';
2019-01-11 20:20:21 +00:00
import GameBoardPlaceholder from '@/components/GameBoard/GameBoardPlaceholder';
2018-11-21 02:43:10 +00:00
import { swal } from '@/shared/modals';
import { dragscroll } from 'vue-dragscroll';
import { mapState } from 'vuex';
import 'firebase/firestore';
const db = firebase.firestore();
db.settings({
timestampsInSnapshots: true,
});
2018-10-19 05:15:28 +00:00
export default {
2019-01-11 20:20:21 +00:00
components: {
GameBoardPlaceholder,
},
2018-11-21 02:43:10 +00:00
directives: {
dragscroll,
2018-10-19 05:15:28 +00:00
},
data() {
return {
loading: true,
2018-11-21 02:43:10 +00:00
listData: null,
2018-10-19 05:15:28 +00:00
};
},
2018-11-21 02:43:10 +00:00
computed: {
...mapState(['publicGameData']),
},
2018-10-19 05:15:28 +00:00
mounted() {
this.load();
},
methods: {
load() {
2018-11-21 02:43:10 +00:00
const { userId, listName } = this.$route.params;
db.collection('lists').doc(userId).get()
.then((doc) => {
if (doc.exists) {
const data = doc.data();
this.listData = data[listName];
this.loadGameData();
}
})
.catch(() => {
this.loading = false;
this.handleError();
});
2018-10-19 05:15:28 +00:00
},
loadGameData() {
const gameList = [];
this.listData.forEach((list) => {
if (list && list.games.length) {
list.games.forEach((id) => {
if (!gameList.includes(id)) {
gameList.push(id);
}
});
}
});
2018-10-19 05:15:28 +00:00
if (gameList.length > 0) {
2018-11-21 02:43:10 +00:00
this.$store.dispatch('LOAD_PUBLIC_GAMES', gameList)
.catch(() => {
this.handleError();
})
.finally(() => {
2018-10-19 05:15:28 +00:00
this.loading = false;
});
} else {
this.loading = false;
}
},
2018-11-21 02:43:10 +00:00
handleError() {
swal({
title: 'Uh no!',
text: 'There was an error loading game data',
type: 'error',
showCancelButton: true,
confirmButtonClass: 'primary',
confirmButtonText: 'Retry',
}).then(({ value }) => {
if (value) {
2018-11-21 05:36:09 +00:00
this.load();
2018-11-21 02:43:10 +00:00
} else {
this.$router.push({ name: 'home' });
}
});
},
2018-10-19 05:15:28 +00:00
},
};
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
@import "~styles/styles.scss";
2018-11-21 02:43:10 +00:00
main {
align-items: flex-start;
background: $color-gray;
box-sizing: border-box;
display: flex;
2019-01-11 21:52:08 +00:00
height: calc(100vh - #{$navHeight});
2018-11-21 02:43:10 +00:00
overflow-x: auto;
overflow-x: overlay;
padding: $gp;
user-select: none;
@include drag-cursor;
&.drag-scroll-active {
@include dragging-cursor;
}
2018-10-19 05:15:28 +00:00
}
2018-11-21 02:43:10 +00:00
section {
flex-shrink: 0;
cursor: default;
position: relative;
width: 300px;
border-radius: $border-radius;
overflow: hidden;
margin-right: $gp;
2019-01-11 21:52:08 +00:00
max-height: calc(100vh - #{$navHeight + $gp * 2});
2018-11-21 02:43:10 +00:00
header {
align-items: center;
background: $color-dark-gray;
color: $color-white;
display: flex;
height: 30px;
justify-content: space-between;
padding: 0 $gp / 2;
position: absolute;
width: 100%;
}
.games {
height: 100%;
2018-11-21 05:32:40 +00:00
overflow-x: hidden;
2018-11-21 02:43:10 +00:00
min-height: 60px;
2019-01-11 21:52:08 +00:00
max-height: calc(100vh - #{$navHeight + $gp * 4});
2018-11-21 02:43:10 +00:00
overflow-y: auto;
overflow-y: overlay;
column-gap: $gp;
background: $color-light-gray;
margin-top: 30px;
padding: $gp / 2 $gp / 2 0;
width: 100%;
}
2018-10-19 05:15:28 +00:00
}
2018-11-21 02:43:10 +00:00
.game-card {
background-color: $color-white;
margin-bottom: $gp / 2;
position: relative;
display: flex;
align-items: center;
img {
width: 80px;
height: auto;
margin-right: $gp / 2;
display: flex;
}
}
2018-10-19 05:15:28 +00:00
</style>