gamebrary/src/App.vue

185 lines
4 KiB
Vue
Raw Normal View History

2021-02-19 15:58:46 -07:00
<!-- TODO: only show save button when data has changed -->
2018-10-18 22:15:28 -07:00
<template>
2019-11-08 13:34:06 -07:00
<div
id="app"
:dir="dir"
2021-02-09 11:54:52 -07:00
v-shortkey="KEYBOARD_SHORTCUTS"
@shortkey="handleShortcutAction"
2019-11-08 13:34:06 -07:00
>
2021-02-21 18:20:33 -07:00
<dock v-if="user || isPublicRoute" />
2021-02-01 14:16:03 -07:00
<global-modals />
2020-10-31 10:44:15 -07:00
<main :class="{
'authorizing': !user,
2021-02-21 11:14:46 -07:00
'bg-dark text-white': darkTheme,
'offset': !isBoard,
}"
>
2020-09-25 17:09:20 -07:00
<router-view />
</main>
2019-11-08 13:34:06 -07:00
</div>
2018-10-18 22:15:28 -07:00
</template>
<script>
2021-01-10 12:55:45 -07:00
import Dock from '@/components/Dock';
2021-02-01 14:16:03 -07:00
import GlobalModals from '@/components/GlobalModals';
2018-11-04 19:28:29 -07:00
import firebase from 'firebase/app';
2020-10-13 17:38:35 -07:00
import { mapState, mapGetters } from 'vuex';
2021-02-18 12:40:53 -07:00
import { KEYBOARD_SHORTCUTS, FIREBASE_CONFIG } from '@/constants';
2018-11-04 19:28:29 -07:00
import 'firebase/firestore';
2021-02-18 12:40:53 -07:00
firebase.initializeApp(FIREBASE_CONFIG);
2018-10-18 22:15:28 -07:00
export default {
2019-11-08 12:56:03 -07:00
name: 'App',
2018-10-18 22:15:28 -07:00
2019-11-08 12:56:03 -07:00
components: {
2021-01-10 12:55:45 -07:00
Dock,
2021-02-01 14:16:03 -07:00
GlobalModals,
2019-11-08 12:56:03 -07:00
},
2020-08-10 21:16:43 -07:00
data() {
return {
debugUserId: null,
2021-02-09 11:54:52 -07:00
KEYBOARD_SHORTCUTS,
2020-08-10 21:16:43 -07:00
};
},
2019-11-08 12:56:03 -07:00
computed: {
2020-09-23 16:01:39 -07:00
...mapState(['user', 'wallpaperUrl', 'settings', 'sessionExpired']),
2021-02-21 11:14:46 -07:00
...mapGetters(['darkTheme']),
2018-11-20 19:43:10 -07:00
2020-08-10 21:16:43 -07:00
userId() {
return this.debugUserId || this.user.uid;
},
2019-11-08 12:56:03 -07:00
dir() {
2021-02-21 18:20:33 -07:00
const { settings } = this;
2021-02-21 18:20:33 -07:00
return settings && settings.language === 'ar' ? 'rtl' : 'ltr';
2019-11-08 12:56:03 -07:00
},
2020-10-05 11:42:28 -07:00
2021-02-21 18:20:33 -07:00
isPublicRoute() {
2020-10-05 11:42:28 -07:00
return this.$route.meta && this.$route.meta.public;
},
2020-11-17 22:55:35 -07:00
isBoard() {
2021-01-06 14:42:33 -07:00
return ['public-board', 'board'].includes(this.$route.name);
2020-11-17 22:55:35 -07:00
},
2019-11-08 12:56:03 -07:00
},
2020-10-15 16:15:09 -07:00
async mounted() {
await this.$store.dispatch('GET_TWITCH_TOKEN');
2019-11-08 12:56:03 -07:00
this.init();
},
methods: {
2021-02-09 11:54:52 -07:00
handleShortcutAction(data) {
this.$bus.$emit('HANDLE_SHORTCUT', data);
},
2019-11-08 12:56:03 -07:00
init() {
2021-02-21 18:20:33 -07:00
if (this.isPublicRoute) {
2020-10-05 11:42:28 -07:00
return;
}
2019-11-08 12:56:03 -07:00
if (this.user) {
this.load();
2020-09-28 16:27:08 -07:00
} else if (this.$route.name !== 'auth') {
this.$router.replace({ name: 'auth' });
2019-11-08 12:56:03 -07:00
}
},
2020-09-28 16:27:08 -07:00
loadWallpapers() {
this.$store.dispatch('LOAD_WALLPAPERS')
.catch(() => {
2020-12-09 22:26:57 -07:00
this.$bvToast.toast('There was an error loading wallpapers', { variant: 'danger' });
2020-09-28 16:27:08 -07:00
});
},
2019-11-08 12:56:03 -07:00
load() {
2021-02-18 12:40:53 -07:00
const db = firebase.firestore();
2020-09-28 16:30:49 -07:00
// TODO: move logic to actions
this.$store.dispatch('LOAD_RELEASES')
.then((releases) => {
const [latestRelease] = releases;
const latestReleaseVersion = latestRelease && latestRelease.tag_name;
const lastReleaseSeenByUser = (this.settings && this.settings.release) || null;
2020-09-09 16:44:31 -07:00
if (latestReleaseVersion !== lastReleaseSeenByUser) {
this.$store.commit('SET_NOTIFICATION', true);
}
});
2020-08-28 14:57:28 -07:00
this.loadWallpapers();
2020-09-28 16:30:49 -07:00
// TODO: remove onSnapshot? May get costly $$$
// TODO: track progresses as well
2019-11-08 12:56:03 -07:00
2019-12-03 11:26:35 -07:00
// TODO: move to actions
2020-08-10 21:16:43 -07:00
db.collection('settings').doc(this.userId)
2019-11-08 12:56:03 -07:00
.onSnapshot((doc) => {
if (doc.exists) {
const settings = doc.data();
this.$store.commit('SET_SETTINGS', settings);
}
});
2019-12-03 11:26:35 -07:00
// TODO: move to actions
2020-08-10 21:16:43 -07:00
db.collection('tags').doc(this.userId)
2019-11-08 12:56:03 -07:00
.onSnapshot((doc) => {
if (doc.exists) {
const tags = doc.data();
this.$store.commit('SET_TAGS', tags);
}
});
2019-12-03 11:26:35 -07:00
// TODO: move to actions
2020-08-10 21:16:43 -07:00
db.collection('notes').doc(this.userId)
2019-11-08 12:56:03 -07:00
.onSnapshot((doc) => {
if (doc.exists) {
const notes = doc.data();
this.$store.commit('SET_NOTES', notes);
}
});
// TODO: move to actions
2020-08-10 21:16:43 -07:00
db.collection('progresses').doc(this.userId)
.onSnapshot((doc) => {
if (doc.exists) {
const progresses = doc.data();
this.$store.commit('SET_PROGRESSES', progresses);
}
});
2019-11-08 12:56:03 -07:00
},
},
2018-10-18 22:15:28 -07:00
};
</script>
<style lang="scss" rel="stylesheet/scss">
2020-08-25 16:41:57 -07:00
@import "~styles/styles";
2018-10-18 22:15:28 -07:00
</style>
2019-02-15 15:58:32 -07:00
<style lang="scss" rel="stylesheet/scss" scoped>
2020-09-25 17:09:20 -07:00
main {
height: 100vh;
overflow-y: auto;
2020-09-28 16:27:08 -07:00
&.authorizing {
width: 100%;
left: 0;
}
2020-11-17 22:55:35 -07:00
&.offset {
padding-left: calc(58px + .5rem);
2020-11-17 22:55:35 -07:00
}
2019-11-08 13:34:06 -07:00
}
2019-02-15 15:58:32 -07:00
</style>