antares/src/renderer/components/TheNotificationsBoard.vue

77 lines
2.2 KiB
Vue
Raw Normal View History

2020-05-15 17:52:59 +02:00
<template>
<div
id="notifications-board"
@mouseenter="clearTimeouts"
@mouseleave="rearmTimeouts"
>
2022-04-25 13:45:07 +02:00
<TransitionGroup tag="div" name="slide-fade">
2020-05-15 17:52:59 +02:00
<BaseNotification
v-for="notification in latestNotifications"
:key="notification.uid"
:message="notification.message"
:status="notification.status"
@close="removeNotification(notification.uid)"
/>
2022-04-25 13:45:07 +02:00
</TransitionGroup>
2020-05-15 17:52:59 +02:00
</div>
</template>
<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { computed, Ref, ref, watch } from 'vue';
import BaseNotification from '@/components/BaseNotification.vue';
2022-04-30 00:47:37 +02:00
import { useNotificationsStore } from '@/stores/notifications';
import { useSettingsStore } from '@/stores/settings';
const notificationsStore = useNotificationsStore();
const settingsStore = useSettingsStore();
const { removeNotification } = notificationsStore;
const { notifications } = storeToRefs(notificationsStore);
const { notificationsTimeout } = storeToRefs(settingsStore);
2020-05-15 17:52:59 +02:00
const timeouts: Ref<{[key: string]: NodeJS.Timeout}> = ref({});
2022-04-30 00:47:37 +02:00
const latestNotifications = computed(() => notifications.value.slice(0, 10));
2022-04-30 00:47:37 +02:00
watch(() => notifications.value.length, (val) => {
if (val > 0) {
const nUid: string = notifications.value[0].uid;
timeouts.value[nUid] = setTimeout(() => {
removeNotification(nUid);
delete timeouts.value[nUid];
}, notificationsTimeout.value * 1000);
}
});
const clearTimeouts = () => {
for (const uid in timeouts.value) {
clearTimeout(timeouts.value[uid]);
delete timeouts.value[uid];
}
};
2022-04-30 00:47:37 +02:00
const rearmTimeouts = () => {
const delay = 50;
let i = notifications.value.length * delay;
for (const notification of notifications.value) {
timeouts.value[notification.uid] = setTimeout(() => {
removeNotification(notification.uid);
delete timeouts.value[notification.uid];
}, (notificationsTimeout.value * 1000) + i);
i = i > delay ? i - delay : 0;
2020-05-15 17:52:59 +02:00
}
};
</script>
<style lang="scss">
2020-07-31 18:16:28 +02:00
#notifications-board {
position: absolute;
2020-08-12 18:11:48 +02:00
z-index: 999;
2020-07-31 18:16:28 +02:00
right: 1rem;
bottom: 1rem;
}
2020-05-15 17:52:59 +02:00
</style>