From f9b1b12b10ead6e2cec4d80aaf9196f7a85e674c Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 25 Aug 2022 23:04:23 -0700 Subject: [PATCH] Implement notification box for web (#533) * Added test button * styling notification box * Added auto dismission and animation to each notificaiont list * Remove test button --- .../notification/notification-card.svelte | 70 +++++++++++++++++++ .../notification/notification-list.svelte | 22 ++++++ .../notification/notification.ts | 36 ++++++++++ .../side-bar/side-bar.svelte | 3 +- .../shared-components/status-box.svelte | 2 +- web/src/routes/+layout.svelte | 3 +- 6 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 web/src/lib/components/shared-components/notification/notification-card.svelte create mode 100644 web/src/lib/components/shared-components/notification/notification-list.svelte create mode 100644 web/src/lib/components/shared-components/notification/notification.ts diff --git a/web/src/lib/components/shared-components/notification/notification-card.svelte b/web/src/lib/components/shared-components/notification/notification-card.svelte new file mode 100644 index 0000000000..5e4efba38a --- /dev/null +++ b/web/src/lib/components/shared-components/notification/notification-card.svelte @@ -0,0 +1,70 @@ + + +
+
+ +

{notificationInfo.type.toString()}

+
+ +

{notificationInfo.message} {notificationInfo.id}

+
diff --git a/web/src/lib/components/shared-components/notification/notification-list.svelte b/web/src/lib/components/shared-components/notification/notification-list.svelte new file mode 100644 index 0000000000..6abc478efe --- /dev/null +++ b/web/src/lib/components/shared-components/notification/notification-list.svelte @@ -0,0 +1,22 @@ + + +{#if $notificationList?.length > 0} +
+ {#each $notificationList as notificationInfo (notificationInfo.id)} +
+ +
+ {/each} +
+{/if} diff --git a/web/src/lib/components/shared-components/notification/notification.ts b/web/src/lib/components/shared-components/notification/notification.ts new file mode 100644 index 0000000000..dba110ac4a --- /dev/null +++ b/web/src/lib/components/shared-components/notification/notification.ts @@ -0,0 +1,36 @@ +import { writable } from 'svelte/store'; + +export enum NotificationType { + Info = 'Info', + Error = 'Error' +} + +export class ImmichNotification { + id = new Date().getTime(); + type!: NotificationType; + message!: string; +} + +function createNotificationList() { + const { set, update, subscribe } = writable([]); + + const show = ({ message = '', type = NotificationType.Info }) => { + const notification = new ImmichNotification(); + notification.message = message; + notification.type = type; + + update((currentList) => [...currentList, notification]); + }; + + const removeNotificationById = (id: number) => { + update((currentList) => currentList.filter((n) => n.id != id)); + }; + + return { + show, + removeNotificationById, + subscribe + }; +} + +export const notificationList = createNotificationList(); diff --git a/web/src/lib/components/shared-components/side-bar/side-bar.svelte b/web/src/lib/components/shared-components/side-bar/side-bar.svelte index 3760bf0f56..690772af95 100644 --- a/web/src/lib/components/shared-components/side-bar/side-bar.svelte +++ b/web/src/lib/components/shared-components/side-bar/side-bar.svelte @@ -1,5 +1,4 @@