2018-10-19 05:15:28 +00:00
|
|
|
<template>
|
|
|
|
<div id="app">
|
2018-11-21 02:43:10 +00:00
|
|
|
<nav-header v-if="user && !isPublic" />
|
2018-10-19 05:15:28 +00:00
|
|
|
|
2018-11-21 02:43:10 +00:00
|
|
|
<main :class="{ 'logged-in': user && !isPublic }">
|
2018-10-19 05:15:28 +00:00
|
|
|
<router-view />
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import NavHeader from '@/components/NavHeader/NavHeader';
|
2018-11-05 02:28:29 +00:00
|
|
|
import firebase from 'firebase/app';
|
2018-11-21 02:43:10 +00:00
|
|
|
import { $error } from '@/shared/modals';
|
2018-11-05 02:28:29 +00:00
|
|
|
import 'firebase/auth';
|
|
|
|
import 'firebase/firestore';
|
2018-10-25 06:33:15 +00:00
|
|
|
import { mapState } from 'vuex';
|
|
|
|
|
2018-11-05 02:28:29 +00:00
|
|
|
firebase.initializeApp({
|
|
|
|
apiKey: 'AIzaSyA6MsmnLtqT4b11r-j15wwreRypO3AodcA',
|
|
|
|
authDomain: 'gamebrary.com',
|
|
|
|
databaseURL: 'https://gamebrary-8c736.firebaseio.com',
|
|
|
|
projectId: 'gamebrary-8c736',
|
|
|
|
storageBucket: 'gamebrary-8c736.appspot.com',
|
|
|
|
messagingSenderId: '324529217902',
|
|
|
|
});
|
|
|
|
|
2018-10-25 06:33:15 +00:00
|
|
|
const db = firebase.firestore();
|
|
|
|
|
|
|
|
db.settings({
|
|
|
|
timestampsInSnapshots: true,
|
|
|
|
});
|
2018-10-19 05:15:28 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'App',
|
|
|
|
|
|
|
|
components: {
|
|
|
|
NavHeader,
|
|
|
|
},
|
2018-10-25 06:33:15 +00:00
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState(['user']),
|
2018-11-21 02:43:10 +00:00
|
|
|
|
|
|
|
isPublic() {
|
|
|
|
return this.$route.name === 'shareList';
|
|
|
|
},
|
2018-10-25 06:33:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
firebase.auth().getRedirectResult().then(({ user }) => {
|
|
|
|
if (user) {
|
|
|
|
this.init(user);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
init(user) {
|
|
|
|
this.$store.commit('SET_AUTHORIZING_STATUS', false);
|
|
|
|
this.$store.commit('SET_USER', user);
|
|
|
|
this.loadSettings();
|
|
|
|
this.loadLists();
|
|
|
|
},
|
|
|
|
|
|
|
|
loadSettings() {
|
|
|
|
const docRef = db.collection('settings').doc(this.user.uid);
|
|
|
|
|
|
|
|
docRef.get().then((doc) => {
|
|
|
|
if (doc.exists) {
|
|
|
|
this.$store.commit('SET_SETTINGS', doc.data());
|
|
|
|
} else {
|
|
|
|
this.initSettings();
|
|
|
|
}
|
|
|
|
}).catch(() => {
|
2018-11-21 02:43:10 +00:00
|
|
|
$error('Authentication error');
|
2018-10-25 06:33:15 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
loadLists() {
|
|
|
|
db.collection('lists').doc(this.user.uid).get()
|
|
|
|
.then((doc) => {
|
|
|
|
if (doc.exists) {
|
2018-11-21 02:43:10 +00:00
|
|
|
const data = doc.data();
|
|
|
|
this.$store.commit('SET_GAME_LISTS', data);
|
2018-10-25 06:33:15 +00:00
|
|
|
} else {
|
|
|
|
this.initList();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2018-11-21 02:43:10 +00:00
|
|
|
$error('Authentication error');
|
2018-10-25 06:33:15 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
initList() {
|
|
|
|
db.collection('lists').doc(this.user.uid).set({}, { merge: true })
|
|
|
|
.then(() => {
|
|
|
|
this.loadLists();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
initSettings() {
|
|
|
|
db.collection('settings').doc(this.user.uid).set({}, { merge: true })
|
|
|
|
.then(() => {
|
|
|
|
this.loadSettings();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2018-10-19 05:15:28 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" rel="stylesheet/scss">
|
2018-10-25 06:33:15 +00:00
|
|
|
@import url(https://fonts.googleapis.com/css?family=Fira+Sans:700|Roboto:400,400italic,700);
|
2018-10-19 05:15:28 +00:00
|
|
|
@import "~styles/styles.scss";
|
|
|
|
|
|
|
|
body {
|
2018-10-29 23:53:49 +00:00
|
|
|
background: $color-dark-gray;
|
2018-10-19 05:15:28 +00:00
|
|
|
margin: 0;
|
|
|
|
font-size: 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#app {
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
> main {
|
2018-10-29 23:53:49 +00:00
|
|
|
height: 100vh;
|
2018-10-19 05:15:28 +00:00
|
|
|
overflow: auto;
|
|
|
|
background: $color-gray;
|
2018-10-29 23:53:49 +00:00
|
|
|
|
|
|
|
&.logged-in {
|
2018-11-08 03:49:04 +00:00
|
|
|
margin-top: $navHeight;
|
2018-10-29 23:53:49 +00:00
|
|
|
height: calc(100vh - #{$navHeight});
|
|
|
|
}
|
2018-10-19 05:15:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 06:33:15 +00:00
|
|
|
h1, h2, h3, h4, h5, h6 {
|
|
|
|
font-family: "Fira Sans", sans-serif;
|
|
|
|
font-weight: 700;
|
|
|
|
}
|
2018-10-19 05:15:28 +00:00
|
|
|
|
2018-10-25 06:33:15 +00:00
|
|
|
body, p, a, li, blockquote {
|
|
|
|
font-family: "Roboto", sans-serif;
|
|
|
|
font-weight: 400;
|
2018-10-19 05:15:28 +00:00
|
|
|
}
|
|
|
|
</style>
|