2021-12-21 16:46:19 +01:00
|
|
|
<script lang="ts">
|
2021-12-21 20:02:47 +01:00
|
|
|
import { notify } from "../../notifications";
|
2021-12-21 16:46:19 +01:00
|
|
|
import { fade } from "svelte/transition";
|
2021-12-21 20:02:47 +01:00
|
|
|
import type { UpNotification } from "../../notifications";
|
2021-12-30 19:28:43 +01:00
|
|
|
import Icon from "../utils/Icon.svelte";
|
2021-12-21 16:46:19 +01:00
|
|
|
|
2021-12-21 16:51:25 +01:00
|
|
|
let notifications: UpNotification[] = [];
|
|
|
|
|
|
|
|
notify.on("notification", (notification) => {
|
|
|
|
notifications.push(notification);
|
|
|
|
notifications = notifications;
|
2021-12-21 16:46:19 +01:00
|
|
|
|
|
|
|
setTimeout(() => {
|
2021-12-21 16:51:25 +01:00
|
|
|
notifications.splice(
|
|
|
|
notifications.findIndex((n) => (n.id = notification.id)),
|
|
|
|
1
|
|
|
|
);
|
2021-12-21 16:46:19 +01:00
|
|
|
notifications = notifications;
|
|
|
|
}, 5000);
|
|
|
|
});
|
|
|
|
|
|
|
|
const icons = {
|
2021-12-22 11:56:06 +01:00
|
|
|
error: "x-octagon",
|
|
|
|
warning: "exclamation-triangle"
|
2021-12-21 16:51:25 +01:00
|
|
|
};
|
2021-12-21 16:46:19 +01:00
|
|
|
</script>
|
|
|
|
|
2021-12-21 16:51:25 +01:00
|
|
|
{#each notifications as notification (notification.id)}
|
|
|
|
<div
|
|
|
|
class="notification notification-{notification.level || 'info'}"
|
|
|
|
transition:fade
|
|
|
|
>
|
2021-12-30 19:28:43 +01:00
|
|
|
<Icon name={icons[notification.level] || "bell"} />
|
2021-12-21 16:46:19 +01:00
|
|
|
{notification.content}
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
.notification-error {
|
|
|
|
color: var(--error);
|
|
|
|
}
|
2021-12-22 11:56:06 +01:00
|
|
|
|
|
|
|
.notification-warning {
|
|
|
|
color: var(--warning);
|
|
|
|
}
|
2021-12-21 16:46:19 +01:00
|
|
|
</style>
|