refactor: common.vue to composition api

This commit is contained in:
Norm 2022-07-28 21:54:48 -04:00 committed by Gitea
parent 86b94e213e
commit a485d13e8a
2 changed files with 30 additions and 40 deletions

View file

@ -150,6 +150,7 @@ export const popups = ref([]) as Ref<{
id: any;
component: any;
props: Record<string, any>;
events: any[];
}[]>;
const zIndexes = {

View file

@ -1,5 +1,6 @@
<template>
<component :is="popup.component"
<component
:is="popup.component"
v-for="popup in popups"
:key="popup.id"
v-bind="popup.props"
@ -15,39 +16,36 @@
<div v-if="dev" id="devTicker"><span>DEV BUILD</span></div>
</template>
<script lang="ts">
import { defineAsyncComponent, defineComponent } from 'vue';
import { popup, popups, pendingApiRequestsCount } from '@/os';
<script lang="ts" setup>
import { defineAsyncComponent, Ref, ref } from 'vue';
import { swInject } from './sw-inject';
import { popup as showPopup, popups, pendingApiRequestsCount } from '@/os';
import { uploads } from '@/scripts/upload';
import * as sound from '@/scripts/sound';
import { $i } from '@/account';
import { swInject } from './sw-inject';
import { stream } from '@/stream';
export default defineComponent({
components: {
XStreamIndicator: defineAsyncComponent(() => import('./stream-indicator.vue')),
XUpload: defineAsyncComponent(() => import('./upload.vue')),
},
const XStreamIndicator = defineAsyncComponent(() => import('./stream-indicator.vue'));
const XUpload = defineAsyncComponent(() => import('./upload.vue'));
const dev: Ref<boolean> = ref(_DEV_);
setup() {
const onNotification = notification => {
if ($i.mutingNotificationTypes.includes(notification.type)) return;
const onNotification = (notification: { type: string; id: any; }): void => {
if ($i?.mutingNotificationTypes.includes(notification.type)) return;
if (document.visibilityState === 'visible') {
stream.send('readNotification', {
id: notification.id
id: notification.id,
});
popup(defineAsyncComponent(() => import('@/components/notification-toast.vue')), {
showPopup(defineAsyncComponent(() => import('@/components/notification-toast.vue')), {
notification
}, {}, 'closed');
}
sound.play('notification');
};
};
if ($i) {
if ($i) {
const connection = stream.useChannel('main', null, 'UI');
connection.on('notification', onNotification);
@ -55,16 +53,7 @@ export default defineComponent({
if ('serviceWorker' in navigator) {
swInject();
}
}
return {
uploads,
popups,
pendingApiRequestsCount,
dev: _DEV_,
};
},
});
}
</script>
<style lang="scss">