felicity-lims/frontend/vite/src/App.vue

49 lines
1.3 KiB
Vue
Raw Normal View History

2021-01-16 00:54:31 +08:00
<template>
<component :is="layout">
<!-- <div class="text-center">Flash Messages will come here.</div> -->
2021-01-16 00:54:31 +08:00
<router-view />
</component>
</template>
<script lang="ts">
2021-12-01 06:11:13 +08:00
import { defineComponent, computed } from 'vue';
import { useRouter } from 'vue-router';
2021-12-06 00:37:33 +08:00
import { useStore } from 'vuex';
2021-12-01 06:11:13 +08:00
const defaultLayout = 'default';
2021-12-06 00:37:33 +08:00
import { ActionTypes } from './store/actions'
2021-12-13 00:20:48 +08:00
import useStreamComposable from './modules/stream'
import {
SUBSCRIBE_TO_ACTIVITY_STREAM
} from './graphql/stream.subscriptions';
import { useSubscription } from '@urql/vue'
2021-04-09 06:37:58 +08:00
2021-12-01 06:11:13 +08:00
export default defineComponent({
setup() {
2021-12-06 00:37:33 +08:00
const store = useStore();
2021-12-13 00:20:48 +08:00
const { initSubscriptions } = useStreamComposable()
initSubscriptions()
const result = useSubscription({
query: SUBSCRIBE_TO_ACTIVITY_STREAM
}, (messages = [], response:any) => {
console.log(messages, response)
return [response.newMessages, ...messages];
})
2021-12-06 00:37:33 +08:00
if (window.performance.getEntriesByType('navigation').map((nav: any) => nav.type).includes('reload')) {
store.dispatch(ActionTypes.PERSIST_AUTH_FROM_LOCAL_STORAGE)
}
2021-12-01 06:11:13 +08:00
const { currentRoute } = useRouter();
2021-12-01 06:11:13 +08:00
const layout = computed(() => `${currentRoute.value.meta.layout || defaultLayout}-layout`);
2021-04-09 06:37:58 +08:00
2021-12-01 06:11:13 +08:00
return {
layout,
};
},
});
2021-01-16 00:54:31 +08:00
</script>