Files
fotospiel-app/resources/js/admin/mobile/lib/notificationGrouping.ts
Codex Agent 1d2242fb4d
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
tests / ui (push) Waiting to run
feat(ai): finalize AI magic edits epic rollout and operations
2026-02-06 22:41:51 +01:00

51 lines
1.2 KiB
TypeScript

export type NotificationScope = 'photos' | 'guests' | 'gallery' | 'events' | 'package' | 'ai' | 'general';
export type ScopedNotification = {
scope: NotificationScope;
is_read?: boolean;
};
export type NotificationGroup<T extends ScopedNotification> = {
scope: NotificationScope;
items: T[];
unread: number;
};
const SCOPE_ORDER: NotificationScope[] = [
'photos',
'guests',
'gallery',
'events',
'package',
'ai',
'general',
];
export function groupNotificationsByScope<T extends ScopedNotification>(items: T[]): NotificationGroup<T>[] {
const groups = new Map<NotificationScope, NotificationGroup<T>>();
items.forEach((item) => {
const scope = item.scope ?? 'general';
const existing = groups.get(scope);
if (existing) {
existing.items.push(item);
if (!item.is_read) {
existing.unread += 1;
}
return;
}
groups.set(scope, {
scope,
items: [item],
unread: item.is_read ? 0 : 1,
});
});
return Array.from(groups.values()).sort((a, b) => {
const aIndex = SCOPE_ORDER.indexOf(a.scope);
const bIndex = SCOPE_ORDER.indexOf(b.scope);
return aIndex - bIndex;
});
}