diff --git a/packages/builder/src/components/common/Notification/NotificationDisplay.svelte b/packages/builder/src/components/common/Notification/NotificationDisplay.svelte index 976059a5bf..657bc3bcdb 100644 --- a/packages/builder/src/components/common/Notification/NotificationDisplay.svelte +++ b/packages/builder/src/components/common/Notification/NotificationDisplay.svelte @@ -1,6 +1,5 @@ + +
+ {#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/index.js b/packages/client/src/store/index.js index 324d8c23e8..ae1a477c8f 100644 --- a/packages/client/src/store/index.js +++ b/packages/client/src/store/index.js @@ -1,5 +1,5 @@ export { authStore } from "./auth" -export { notificationStore } from "./notifier" +export { notificationStore } from "./notification" export { routeStore } from "./routes" export { screenStore } from "./screens" export { builderStore } from "./builder" diff --git a/packages/client/src/store/notification.js b/packages/client/src/store/notification.js new file mode 100644 index 0000000000..854238fd9e --- /dev/null +++ b/packages/client/src/store/notification.js @@ -0,0 +1,36 @@ +import { writable, derived } from "svelte/store" + +let NOTIFICATION_TIMEOUT = 3000 + +export const createNotificationStore = () => { + const _notifications = writable([]) + + const send = (message, type = "default") => { + _notifications.update(state => { + state = [ + ...state, + { id: 1, type, message }, + ] + }) + } + + const notifications = derived(_notifications, ($_notifications, set) => { + const timeout = setTimeout({ + set($_notifications) + }, NOTIFICATION_TIMEOUT) + + return () => { + clearTimeout(timeout); + }; + }) + const {subscribe} = notifications + + return { + subscribe, + send, + danger: msg => send(msg, "danger"), + warning: msg => send(msg, "warning"), + info: msg => send(msg, "info"), + success: msg => send(msg, "success"), + } +} \ No newline at end of file diff --git a/packages/client/src/store/notifier.js b/packages/client/src/store/notifier.js deleted file mode 100644 index 85e708e92a..0000000000 --- a/packages/client/src/store/notifier.js +++ /dev/null @@ -1,23 +0,0 @@ -import { writable } from "svelte/store" -import { generate } from "shortid" - -export const notificationStore = writable({ - notifications: [], -}) - -export function send(message, type = "default") { - notificationStore.update(state => { - state.notifications = [ - ...state.notifications, - { id: generate(), type, message }, - ] - return state - }) -} - -export const notifier = { - danger: msg => send(msg, "danger"), - warning: msg => send(msg, "warning"), - info: msg => send(msg, "info"), - success: msg => send(msg, "success"), -} diff --git a/packages/standard-components/src/Icon.svelte b/packages/standard-components/src/Icon.svelte index 4b8838d43e..d175bfd6b0 100644 --- a/packages/standard-components/src/Icon.svelte +++ b/packages/standard-components/src/Icon.svelte @@ -3,9 +3,6 @@ const { styleable } = getContext("sdk") const component = getContext("component") - const notification = getContext("notification") - - console.log($notification) export let icon = "" export let size = "fa-lg"