From fdbe623e1060efc4b074d213a96e8f5a2ab7498b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 20 Sep 2023 15:16:28 -0300 Subject: more ui stuff, moved forms to util --- packages/web-util/src/hooks/index.ts | 3 +++ packages/web-util/src/hooks/useNotifications.ts | 29 ++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'packages/web-util/src/hooks') diff --git a/packages/web-util/src/hooks/index.ts b/packages/web-util/src/hooks/index.ts index a3a2053e6..c29de9023 100644 --- a/packages/web-util/src/hooks/index.ts +++ b/packages/web-util/src/hooks/index.ts @@ -5,6 +5,9 @@ export { useNotifications, notifyError, notifyInfo, + notify, + ErrorNotification, + InfoNotification } from "./useNotifications.js"; export { useAsyncAsHook, 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>(); const NOTIFICATION_KEY = "notification"; +export function notify(notif: NotificationMessage): void { + const currentState: Map = + 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 = - 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 = - 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 = { -- cgit v1.2.3