apply review comments

This commit is contained in:
imperosol
2026-05-20 10:39:52 +02:00
parent 57a422de8c
commit 204e4e97bd
4 changed files with 25 additions and 27 deletions
+3 -3
View File
@@ -3,7 +3,7 @@ import { Alpine } from "alpinejs";
import { limitedChoices } from "#core:alpine/limited-choices"; import { limitedChoices } from "#core:alpine/limited-choices";
import { import {
type NotificationPlugin, type NotificationPlugin,
alpinePlugin as notificationPlugin, notificationsPlugin as notifications,
} from "#core:utils/notifications"; } from "#core:utils/notifications";
declare module "alpinejs" { declare module "alpinejs" {
@@ -11,8 +11,8 @@ declare module "alpinejs" {
$notifications: NotificationPlugin; $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 // biome-ignore lint/style/useNamingConvention: it's how it's named
Object.assign(window, { Alpine }); Object.assign(window, { Alpine });
+14 -20
View File
@@ -44,27 +44,21 @@ Alpine.store("notifications", [] as Notification[]);
function createNotification(message: string, level: NotificationLevel) { function createNotification(message: string, level: NotificationLevel) {
(Alpine.store("notifications") as Notification[]).push({ text: message, tag: level }); (Alpine.store("notifications") as Notification[]).push({ text: message, tag: level });
} }
function createManyNotifications(notifs: Notification[]) {
function deleteNotifications() { for (const notif of notifs) {
Alpine.store("notifications", []); createNotification(notif.text, notif.tag);
}
} }
function getNotifications() { export const notifications: NotificationPlugin = {
return Alpine.store("notifications") as Notification[];
}
export function alpinePlugin(): NotificationPlugin {
return {
error: (message: string) => createNotification(message, NotificationLevel.Error), error: (message: string) => createNotification(message, NotificationLevel.Error),
warning: (message: string) => warning: (message: string) => createNotification(message, NotificationLevel.Warning),
createNotification(message, NotificationLevel.Warning), success: (message: string) => createNotification(message, NotificationLevel.Success),
success: (message: string) => clear: () => Alpine.store("notifications", []),
createNotification(message, NotificationLevel.Success), addMany: (notifs: Notification[]) => createManyNotifications(notifs),
clear: () => deleteNotifications(), getAll: () => Alpine.store("notifications") as Notification[],
addMany: (notifs: Notification[]) => };
notifs.forEach((n) => {
createNotification(n.text, n.tag); export function notificationsPlugin(GlobalAlpine: Alpine) {
}), GlobalAlpine.magic("notifications", () => ({ ...notifications }));
getAll: () => getNotifications(),
};
} }
+1 -1
View File
@@ -2,7 +2,7 @@
x-init='$notifications.addMany([ x-init='$notifications.addMany([
{%- for message in messages -%} {%- for message in messages -%}
{%- if not message.extra_tags -%} {%- if not message.extra_tags -%}
{ tag: {{ message.tags|string|tojson }}, text: {{ message|string|tojson }} }, { tag: "{{ message.tags }}", text: {{ message|string|tojson }} },
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
])' ])'
+7 -3
View File
@@ -237,14 +237,18 @@
clear : optional boolean that controls if notifications should be cleared first. True is the default clear : optional boolean that controls if notifications should be cleared first. True is the default
#} #}
{% if messages %} {% if messages %}
<div x-init="() => { <div x-init='() => {
{%- if clear -%} {%- if clear -%}
$notifications.clear(); $notifications.clear();
{%- endif -%} {%- endif -%}
$notifications.addMany([
{%- for message in messages -%} {%- for message in messages -%}
$notifications.{{ message.tags }}('{{ message }}'); {%- if not message.extra_tags -%}
{ tag: "{{ message.tags }}", text: {{ message|string|tojson }} },
{%- endif -%}
{%- endfor -%} {%- endfor -%}
}"></div> ])
}'></div>
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}