Files
habitica/website/client/app.vue
Matteo Pagliazzi 33a39d3683 Client fixes (#8844)
* client: fix router when not authenticated, small fixes for tasks

* load the user only when necessary

* fix tests
2017-06-29 20:49:05 +02:00

60 lines
1.5 KiB
Vue

<template lang="pug">
#app
router-view(v-if="!isUserLoggedIn || isStaticPage")
template(v-else)
#loading-screen.h-100.w-100.d-flex.justify-content-center.align-items-center(v-if="!isUserLoaded")
p Loading...
template(v-else)
app-menu
.container-fluid
app-header
router-view
</template>
<script>
import AppMenu from './components/appMenu';
import AppHeader from './components/appHeader';
import { mapState } from 'client/libs/store';
export default {
name: 'app',
components: {
AppMenu,
AppHeader,
},
data () {
return {
isUserLoaded: false,
};
},
computed: {
...mapState(['isUserLoggedIn']),
isStaticPage () {
return this.$route.meta.requiresLogin === false ? true : false;
},
},
created () {
// Setup listener for title
this.$store.watch(state => state.title, (title) => {
document.title = title;
});
if (this.isUserLoggedIn && !this.isStaticPage) {
// Load the user and the user tasks
Promise.all([
this.$store.dispatch('user:fetch'),
this.$store.dispatch('tasks:fetchUserTasks'),
]).then(() => {
this.isUserLoaded = true;
}).catch((err) => {
console.error('Impossible to fetch user. Clean up localStorage and refresh.', err); // eslint-disable-line no-console
});
}
},
};
</script>
<style src="bootstrap/scss/bootstrap.scss" lang="scss"></style>
<style src="assets/scss/index.scss" lang="scss"></style>
<style src="assets/css/index.css"></style>