diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte index 404a91f210..b0337bd53f 100644 --- a/packages/client/src/components/ClientApp.svelte +++ b/packages/client/src/components/ClientApp.svelte @@ -2,7 +2,6 @@ import { writable } from "svelte/store" import { setContext, onMount } from "svelte" import Component from "./Component.svelte" - import NotificationDisplay from './NotificationDisplay.svelte' import SDK from "../sdk" import { createDataStore, initialise, screenStore, notificationStore } from "../store" @@ -10,7 +9,7 @@ setContext("sdk", SDK) setContext("component", writable({})) setContext("data", createDataStore()) - setContext("notifier", notificationStore) + setContext("notification", notificationStore) setContext("screenslot", false) let loaded = false @@ -24,5 +23,4 @@ {#if loaded && $screenStore.activeLayout} -{/if} - \ No newline at end of file +{/if} \ No newline at end of file diff --git a/packages/client/src/components/NotificationDisplay.svelte b/packages/client/src/components/NotificationDisplay.svelte index 9b57cc932e..e69de29bb2 100644 --- a/packages/client/src/components/NotificationDisplay.svelte +++ b/packages/client/src/components/NotificationDisplay.svelte @@ -1,71 +0,0 @@ - - -
- {#each $notificationStore.notifications as notification (notification.id)} -
-
{notification.message}
- {#if notification.icon}{/if} -
- {/each} -
- - - \ No newline at end of file diff --git a/packages/client/src/store/notification.js b/packages/client/src/store/notification.js index 854238fd9e..d6c892ecb8 100644 --- a/packages/client/src/store/notification.js +++ b/packages/client/src/store/notification.js @@ -1,29 +1,37 @@ import { writable, derived } from "svelte/store" +import { generate } from "shortid" + let NOTIFICATION_TIMEOUT = 3000 -export const createNotificationStore = () => { +const createNotificationStore = () => { const _notifications = writable([]) const send = (message, type = "default") => { _notifications.update(state => { - state = [ + return [ ...state, - { id: 1, type, message }, + { id: generate(), type, message }, ] }) } const notifications = derived(_notifications, ($_notifications, set) => { - const timeout = setTimeout({ - set($_notifications) - }, NOTIFICATION_TIMEOUT) - - return () => { - clearTimeout(timeout); - }; + set($_notifications) + if ($_notifications.length > 0) { + const timeout = setTimeout(() => { + _notifications.update(state => { + state.shift() + return state + }) + set($_notifications) + }, NOTIFICATION_TIMEOUT) + return () => { + clearTimeout(timeout); + }; + } }) - const {subscribe} = notifications + const { subscribe } = notifications return { subscribe, @@ -33,4 +41,14 @@ export const createNotificationStore = () => { info: msg => send(msg, "info"), success: msg => send(msg, "success"), } -} \ No newline at end of file +} + +export const notificationStore = createNotificationStore() + +// setTimeout(() => { +// notificationStore.update(state => { +// state.notifications.shift() +// state.notifications = state.notifications +// return state +// }) +// }, timeout) \ No newline at end of file diff --git a/packages/standard-components/src/Icon.svelte b/packages/standard-components/src/Icon.svelte index d175bfd6b0..8b5db301a6 100644 --- a/packages/standard-components/src/Icon.svelte +++ b/packages/standard-components/src/Icon.svelte @@ -3,6 +3,9 @@ const { styleable } = getContext("sdk") const component = getContext("component") + const notification = getContext("notification") + + $: console.log($notification) export let icon = "" export let size = "fa-lg" @@ -17,4 +20,8 @@ \ No newline at end of file + class="{icon} {size}" /> + + \ No newline at end of file