diff options
author | Sebastian <sebasjm@gmail.com> | 2023-09-20 15:16:28 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-09-25 14:50:39 -0300 |
commit | fdbe623e1060efc4b074d213a96e8f5a2ab7498b (patch) | |
tree | 6bbe00f6f36f1910ea99180a6e0d5c53aeb9f34f /packages/web-util/src/hooks/useNotifications.ts | |
parent | a5406c5a5dc437e036168eb068db11d88e05bb0f (diff) | |
download | wallet-core-fdbe623e1060efc4b074d213a96e8f5a2ab7498b.tar.xz |
more ui stuff, moved forms to util
Diffstat (limited to 'packages/web-util/src/hooks/useNotifications.ts')
-rw-r--r-- | packages/web-util/src/hooks/useNotifications.ts | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/packages/web-util/src/hooks/useNotifications.ts b/packages/web-util/src/hooks/useNotifications.ts index 733950592..52e626b38 100644 --- a/packages/web-util/src/hooks/useNotifications.ts +++ b/packages/web-util/src/hooks/useNotifications.ts @@ -4,13 +4,13 @@ import { memoryMap } from "../index.browser.js"; export type NotificationMessage = ErrorNotification | InfoNotification; -interface ErrorNotification { +export interface ErrorNotification { type: "error"; title: TranslatedString; description?: TranslatedString; debug?: string; } -interface InfoNotification { +export interface InfoNotification { type: "info"; title: TranslatedString; } @@ -18,30 +18,29 @@ interface InfoNotification { const storage = memoryMap<Map<string, NotificationMessage>>(); const NOTIFICATION_KEY = "notification"; +export function notify(notif: NotificationMessage): void { + const currentState: Map<string, NotificationMessage> = + storage.get(NOTIFICATION_KEY) ?? new Map(); + const newState = currentState.set(hash(notif), notif); + storage.set(NOTIFICATION_KEY, newState); +} export function notifyError( title: TranslatedString, description: TranslatedString | undefined, debug?: any, ) { - const currentState: Map<string, NotificationMessage> = - storage.get(NOTIFICATION_KEY) ?? new Map(); - - const notif = { + notify({ type: "error" as const, title, description, debug, - }; - const newState = currentState.set(hash(notif), notif); - storage.set(NOTIFICATION_KEY, newState); + }); } export function notifyInfo(title: TranslatedString) { - const currentState: Map<string, NotificationMessage> = - storage.get(NOTIFICATION_KEY) ?? new Map(); - - const notif = { type: "info" as const, title }; - const newState = currentState.set(hash(notif), notif); - storage.set(NOTIFICATION_KEY, newState); + notify({ + type: "info" as const, + title, + }); } type Notification = { |