gamebrary/src/pages/ShareList/ShareList.vue

197 lines
5.1 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>
<span v-if="loading">Loading...</span>
<section
v-if="!loading && listData && publicGameData"
v-for="list in listData"
:key="list.name"
>
<header>{{ list.name }} ({{ list.games.length }})</header>
<div class="empty-list" v-if="!list.games.length">
<h3>This collection is empty</h3>
</div>
2018-10-19 05:15:28 +00:00
2018-11-21 02:43:10 +00:00
<div class="games" v-else>
<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 05:40:21 +00:00
v-if="publicGameData[game].cover && publicGameData[game].cover.cloudinary_id"
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';
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 {
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() {
2018-11-21 02:43:10 +00:00
const gameList = this.listData.map(({ games }) => games).join().replace(/(^,)|(,$)/g, '');
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;
height: 100vh;
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;
max-height: calc(100vh - 48px);
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;
2018-11-21 05:32:40 +00:00
max-height: calc(100vh - 78px);
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>