parsley/app/javascript/components/App.vue

67 lines
1.8 KiB
Vue
Raw Normal View History

2018-03-29 01:57:00 -05:00
<template>
<div id="app">
2024-10-02 16:20:07 -05:00
<app-progress-bar></app-progress-bar>
2018-03-30 14:31:09 -05:00
<app-navbar></app-navbar>
<section id="main" class="">
2018-03-30 14:31:09 -05:00
<div class="container">
<router-view v-slot="{ Component }">
<transition name="fade" mode="out-in">
<component v-if="!hasError" :is="Component" />
<div v-else>
<h1>Error!</h1>
2024-09-29 13:35:49 -05:00
<p>{{ appConfig.error }}</p>
</div>
</transition>
</router-view>
2018-03-30 14:31:09 -05:00
</div>
</section>
2018-03-29 01:57:00 -05:00
</div>
</template>
2024-09-29 13:35:49 -05:00
<script setup>
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from "vue";
2024-09-29 09:44:40 -05:00
import { useGlobalTweenGroup } from "../lib/useGlobalTweenGroup";
import { useAppConfigStore } from "../stores/appConfig";
2024-09-29 13:35:49 -05:00
import { useLoadResource } from "../lib/useLoadResource";
import { useCheckAuthentication } from "../lib/useCheckAuthentication";
2024-10-02 16:20:07 -05:00
import AppProgressBar from "./AppProgressBar.vue";
2018-03-30 14:31:09 -05:00
2024-09-29 09:44:40 -05:00
const globalTweenGroup = useGlobalTweenGroup();
2024-09-29 13:35:49 -05:00
let animationLoop = true;
2024-09-29 09:44:40 -05:00
2024-09-29 13:35:49 -05:00
const appConfig = useAppConfigStore();
const hasError = computed(() => appConfig.error !== null);
2024-09-29 13:35:49 -05:00
const { loadResource } = useLoadResource();
const { checkAuthentication } = useCheckAuthentication(loadResource);
2018-03-29 01:57:00 -05:00
2024-09-29 13:35:49 -05:00
watch(
() => appConfig.initialLoad,
(val) => {
2018-04-01 21:43:23 -05:00
if (val) {
2024-09-29 13:35:49 -05:00
nextTick(() => document.body.classList.remove("loading"));
2018-04-01 21:43:23 -05:00
}
},
2024-09-29 13:35:49 -05:00
{ immediate: true }
);
2024-09-29 13:35:49 -05:00
onMounted(() => {
// Setup global animation loop
function animate() {
if (animationLoop) {
globalTweenGroup.update();
2018-09-13 14:51:41 -05:00
requestAnimationFrame(animate);
}
2024-09-29 13:35:49 -05:00
}
animate();
2024-09-29 13:35:49 -05:00
if (appConfig.user === null && appConfig.authChecked === false) {
checkAuthentication();
2018-03-30 14:31:09 -05:00
}
2024-09-29 13:35:49 -05:00
});
onUnmounted(() => {
animationLoop = false;
});
2018-03-29 01:57:00 -05:00
</script>