From 204e4e97bddaaac462a5c348a4f72708e6f8e09e Mon Sep 17 00:00:00 2001 From: imperosol Date: Wed, 20 May 2026 10:39:52 +0200 Subject: [PATCH] apply review comments --- core/static/bundled/alpine-index.ts | 6 ++-- core/static/bundled/utils/notifications.ts | 34 ++++++++------------ core/templates/core/base/notifications.jinja | 2 +- core/templates/core/macros.jinja | 10 ++++-- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/core/static/bundled/alpine-index.ts b/core/static/bundled/alpine-index.ts index 9dd1171f..75ff18f5 100644 --- a/core/static/bundled/alpine-index.ts +++ b/core/static/bundled/alpine-index.ts @@ -3,7 +3,7 @@ import { Alpine } from "alpinejs"; import { limitedChoices } from "#core:alpine/limited-choices"; import { type NotificationPlugin, - alpinePlugin as notificationPlugin, + notificationsPlugin as notifications, } from "#core:utils/notifications"; declare module "alpinejs" { @@ -11,8 +11,8 @@ declare module "alpinejs" { $notifications: NotificationPlugin; } } -Alpine.plugin([sort, limitedChoices]); -Alpine.magic("notifications", notificationPlugin); + +Alpine.plugin([sort, limitedChoices, notifications]); // biome-ignore lint/style/useNamingConvention: it's how it's named Object.assign(window, { Alpine }); diff --git a/core/static/bundled/utils/notifications.ts b/core/static/bundled/utils/notifications.ts index 540bbe31..f5ee874c 100644 --- a/core/static/bundled/utils/notifications.ts +++ b/core/static/bundled/utils/notifications.ts @@ -44,27 +44,21 @@ Alpine.store("notifications", [] as Notification[]); function createNotification(message: string, level: NotificationLevel) { (Alpine.store("notifications") as Notification[]).push({ text: message, tag: level }); } - -function deleteNotifications() { - Alpine.store("notifications", []); +function createManyNotifications(notifs: Notification[]) { + for (const notif of notifs) { + createNotification(notif.text, notif.tag); + } } -function getNotifications() { - return Alpine.store("notifications") as Notification[]; -} +export const notifications: NotificationPlugin = { + error: (message: string) => createNotification(message, NotificationLevel.Error), + warning: (message: string) => createNotification(message, NotificationLevel.Warning), + success: (message: string) => createNotification(message, NotificationLevel.Success), + clear: () => Alpine.store("notifications", []), + addMany: (notifs: Notification[]) => createManyNotifications(notifs), + getAll: () => Alpine.store("notifications") as Notification[], +}; -export function alpinePlugin(): NotificationPlugin { - return { - error: (message: string) => createNotification(message, NotificationLevel.Error), - warning: (message: string) => - createNotification(message, NotificationLevel.Warning), - success: (message: string) => - createNotification(message, NotificationLevel.Success), - clear: () => deleteNotifications(), - addMany: (notifs: Notification[]) => - notifs.forEach((n) => { - createNotification(n.text, n.tag); - }), - getAll: () => getNotifications(), - }; +export function notificationsPlugin(GlobalAlpine: Alpine) { + GlobalAlpine.magic("notifications", () => ({ ...notifications })); } diff --git a/core/templates/core/base/notifications.jinja b/core/templates/core/base/notifications.jinja index fedd337e..6eb7b749 100644 --- a/core/templates/core/base/notifications.jinja +++ b/core/templates/core/base/notifications.jinja @@ -2,7 +2,7 @@ x-init='$notifications.addMany([ {%- for message in messages -%} {%- if not message.extra_tags -%} - { tag: {{ message.tags|string|tojson }}, text: {{ message|string|tojson }} }, + { tag: "{{ message.tags }}", text: {{ message|string|tojson }} }, {%- endif -%} {%- endfor -%} ])' diff --git a/core/templates/core/macros.jinja b/core/templates/core/macros.jinja index d56beb38..303c670e 100644 --- a/core/templates/core/macros.jinja +++ b/core/templates/core/macros.jinja @@ -237,14 +237,18 @@ clear : optional boolean that controls if notifications should be cleared first. True is the default #} {% if messages %} -
+ ]) + }'> {% endif %} {% endmacro %}