@burdenoff/microfe-notification 2026.1117.1 → 2026.1118.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ interface NotificationListFooterProps {
2
+ /** More notifications exist after the ones loaded. */
3
+ hasMore: boolean;
4
+ /** The next page is loading. */
5
+ isLoadingMore: boolean;
6
+ /** Load the next page (useNotifications' loadMore). */
7
+ onLoadMore: () => void | Promise<void>;
8
+ /** How many notifications the list shows; the end note needs at least one. */
9
+ shownCount: number;
10
+ }
11
+ /**
12
+ * The end of a notification list (BOFF-15331): loads the next page as it
13
+ * scrolls into view, shows a loading row meanwhile, keeps a "Load more"
14
+ * button for keyboard users and browsers without IntersectionObserver, and
15
+ * says so when everything is shown.
16
+ */
17
+ export declare function NotificationListFooter({ hasMore, isLoadingMore, onLoadMore, shownCount, }: NotificationListFooterProps): import('react').JSX.Element | null;
18
+ export {};
@@ -0,0 +1,43 @@
1
+ import { useTr as e } from "../shared/hooks/useTr.js";
2
+ import { Loader2 as t } from "lucide-react";
3
+ import { jsx as n, jsxs as r } from "react/jsx-runtime";
4
+ import { Button as i } from "@burdenoff/fe-libs/ui";
5
+ import { useInfiniteScroll as a } from "@burdenoff/fe-libs/shared/hooks";
6
+ // src/components/NotificationListFooter.tsx
7
+ function o({ hasMore: o, isLoadingMore: s, onLoadMore: c, shownCount: l }) {
8
+ let u = e(), d = a({
9
+ hasMore: o,
10
+ loading: s,
11
+ onLoadMore: () => void c()
12
+ });
13
+ return o ? /* @__PURE__ */ r("div", {
14
+ "data-testid": "notifications-list-footer",
15
+ className: "flex flex-col items-center py-4",
16
+ children: [/* @__PURE__ */ n("div", {
17
+ ref: d,
18
+ "aria-hidden": "true",
19
+ className: "h-px w-full"
20
+ }), s ? /* @__PURE__ */ r("div", {
21
+ role: "status",
22
+ className: "flex items-center gap-2 text-sm text-text-secondary",
23
+ children: [/* @__PURE__ */ n(t, {
24
+ size: 16,
25
+ className: "animate-spin",
26
+ "aria-hidden": "true"
27
+ }), u("notifications.loadingMore", "Loading more…")]
28
+ }) : /* @__PURE__ */ n(i, {
29
+ type: "button",
30
+ variant: "ghost",
31
+ size: "sm",
32
+ onClick: () => void c(),
33
+ children: u("notifications.loadMore", "Load more")
34
+ })]
35
+ }) : l > 0 ? /* @__PURE__ */ n("p", {
36
+ "data-testid": "notifications-list-end",
37
+ className: "py-4 text-center text-xs text-text-tertiary",
38
+ children: u("notifications.listEnd", "That's everything")
39
+ }) : null;
40
+ }
41
+ export { o as NotificationListFooter };
42
+
43
+ //# sourceMappingURL=NotificationListFooter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationListFooter.js","names":["NotificationListFooter","tr","useTr","endRef","useInfiniteScroll","isLoadingMore","onLoadMore","hasMore","Loader2","Button","shownCount"],"sources":["../../src/components/NotificationListFooter.tsx"],"sourcesContent":["import { Loader2 } from 'lucide-react';\nimport { useInfiniteScroll } from '@burdenoff/fe-libs/shared/hooks';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { useTr } from '../shared/hooks/useTr';\n\ninterface NotificationListFooterProps {\n /** More notifications exist after the ones loaded. */\n hasMore: boolean;\n /** The next page is loading. */\n isLoadingMore: boolean;\n /** Load the next page (useNotifications' loadMore). */\n onLoadMore: () => void | Promise<void>;\n /** How many notifications the list shows; the end note needs at least one. */\n shownCount: number;\n}\n\n/**\n * The end of a notification list (BOFF-15331): loads the next page as it\n * scrolls into view, shows a loading row meanwhile, keeps a \"Load more\"\n * button for keyboard users and browsers without IntersectionObserver, and\n * says so when everything is shown.\n */\nexport function NotificationListFooter({\n hasMore,\n isLoadingMore,\n onLoadMore,\n shownCount,\n}: NotificationListFooterProps) {\n const tr = useTr();\n const endRef = useInfiniteScroll({\n hasMore,\n loading: isLoadingMore,\n onLoadMore: () => void onLoadMore(),\n });\n\n if (!hasMore) {\n return shownCount > 0 ? (\n <p\n data-testid=\"notifications-list-end\"\n className=\"py-4 text-center text-xs text-text-tertiary\"\n >\n {tr('notifications.listEnd', \"That's everything\")}\n </p>\n ) : null;\n }\n\n return (\n <div data-testid=\"notifications-list-footer\" className=\"flex flex-col items-center py-4\">\n <div ref={endRef} aria-hidden=\"true\" className=\"h-px w-full\" />\n {isLoadingMore ? (\n <div role=\"status\" className=\"flex items-center gap-2 text-sm text-text-secondary\">\n <Loader2 size={16} className=\"animate-spin\" aria-hidden=\"true\" />\n {tr('notifications.loadingMore', 'Loading more…')}\n </div>\n ) : (\n <Button type=\"button\" variant=\"ghost\" size=\"sm\" onClick={() => void onLoadMore()}>\n {tr('notifications.loadMore', 'Load more')}\n </Button>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;AAsBA,SAAgBA,EAAuB,EACrC,YACA,kBACA,eACA,iBAC8B;CAC9B,IAAMC,IAAKC,EAAM,GACXC,IAASC,EAAkB;EAC/B;EACA,SAASC;EACT,kBAAkB,KAAKC,EAAW;CACpC,CAAC;CAaD,OAXKC,IAYH,kBAAC,OAAD;EAAK,eAAY;EAA4B,WAAU;EAAvD,UAAA,CACE,kBAAC,OAAD;GAAK,KAAKJ;GAAQ,eAAY;GAAO,WAAU;EAAe,CAAA,GAC7DE,IACC,kBAAC,OAAD;GAAK,MAAK;GAAS,WAAU;GAA7B,UAAA,CACE,kBAACG,GAAD;IAAS,MAAM;IAAI,WAAU;IAAe,eAAY;GAAQ,CAAA,GAC/DP,EAAG,6BAA6B,eAAe,CAC7C;EAEL,CAAA,IAAA,kBAACQ,GAAD;GAAQ,MAAK;GAAS,SAAQ;GAAQ,MAAK;GAAK,eAAe,KAAKH,EAAW;GAC5E,UAAAL,EAAG,0BAA0B,WAAW;EACnC,CAAA,CAEP;C,KAvBES,IAAa,IAClB,kBAAC,KAAD;EACE,eAAY;EACZ,WAAU;EAET,UAAAT,EAAG,yBAAyB,mBAAmB;CAC/C,CAAA,IACD;AAkBR"}
@@ -0,0 +1,51 @@
1
+ import { Notification, NotificationFilter } from '../types';
2
+ /** The page size the lists request. */
3
+ export declare const NOTIFICATION_PAGE_SIZE = 50;
4
+ /** The most the service returns in one request. */
5
+ export declare const NOTIFICATION_MAX_PAGE_SIZE = 100;
6
+ type Listed = Pick<Notification, 'id' | 'createdAt'>;
7
+ /**
8
+ * Whether the server still lists this notification under the filter. Only the
9
+ * read and archived state can change on this page after it was loaded.
10
+ */
11
+ export declare function stillListed(notification: Partial<Pick<Notification, 'readAt' | 'archivedAt'>>, filter: Pick<NotificationFilter, 'isRead' | 'archived'>): boolean;
12
+ /** Where the next page starts: `createdAt <= before`, then `offset`/`limit`. */
13
+ export interface NotificationPageWindow {
14
+ before: Date;
15
+ limit: number;
16
+ offset: number;
17
+ }
18
+ /**
19
+ * The next page after the notifications loaded from the server's pages
20
+ * (`fromServerPages`; live arrivals are newer, so they never matter here).
21
+ *
22
+ * The window starts at the oldest loaded notification, inclusive, so the
23
+ * notifications sharing its exact `createdAt` are asked for again together
24
+ * with the next page and dropped as repeats. The service orders only by
25
+ * `createdAt`, so the order inside such a tie can change between requests;
26
+ * fetching the whole tie again means none of it is ever skipped. Only tied
27
+ * rows the server still lists under the filter are counted (one marked read
28
+ * in an unread view is no longer in its result).
29
+ */
30
+ export declare function nextNotificationWindow<T extends Listed & Partial<Pick<Notification, 'readAt' | 'archivedAt'>>>(loaded: readonly T[], fromServerPages: ReadonlySet<string>, filter: Pick<NotificationFilter, 'isRead' | 'archived'>): NotificationPageWindow | null;
31
+ /** Adds a page after the loaded notifications, skipping any already shown. */
32
+ export declare function appendNotificationPage<T extends Pick<Notification, 'id'>>(loaded: readonly T[], page: readonly T[]): T[];
33
+ /**
34
+ * The list after the first page was fetched again (the tab became visible).
35
+ *
36
+ * When the fresh first page overlaps a notification loaded from the server's
37
+ * pages (`fromServerPages`; a live arrival proves nothing about what lies
38
+ * between it and the older pages), the loaded
39
+ * notifications at or before its oldest one carry on straight after it and
40
+ * are kept, so coming back to the tab does not throw away the pages scrolled
41
+ * through (`continued`). Loaded rows newer than that and missing from the
42
+ * fresh page left the list meanwhile and are dropped, except live arrivals
43
+ * that came in while the refresh was on its way. With no overlap, more
44
+ * than a page arrived and there is a gap of unknown size, so the list starts
45
+ * over from the fresh page instead.
46
+ */
47
+ export declare function mergeRefreshedFirstPage<T extends Listed>(loaded: readonly T[], firstPage: readonly T[], firstPageHasMore: boolean, fromServerPages: ReadonlySet<string>): {
48
+ list: T[];
49
+ continued: boolean;
50
+ };
51
+ export {};
@@ -0,0 +1,43 @@
1
+ function e(e, t) {
2
+ return !(t.isRead === !0 && !e.readAt || t.isRead === !1 && e.readAt || t.archived === !0 && !e.archivedAt || t.archived === !1 && e.archivedAt);
3
+ }
4
+ function t(t, n, r) {
5
+ let i = Infinity, a = 0;
6
+ for (let o of t) {
7
+ if (!n.has(o.id)) continue;
8
+ let t = Date.parse(o.createdAt);
9
+ if (Number.isNaN(t)) continue;
10
+ let s = +!!e(o, r);
11
+ t < i ? (i = t, a = s) : t === i && (a += s);
12
+ }
13
+ if (!Number.isFinite(i)) return null;
14
+ let o = new Date(i);
15
+ return a + 50 <= 100 ? {
16
+ before: o,
17
+ offset: 0,
18
+ limit: a + 50
19
+ } : {
20
+ before: o,
21
+ offset: a,
22
+ limit: 50
23
+ };
24
+ }
25
+ function n(e, t) {
26
+ let n = new Set(e.map((e) => e.id));
27
+ return [...e, ...t.filter((e) => !n.has(e.id))];
28
+ }
29
+ function r(e, t, n, r) {
30
+ let i = new Set(t.map((e) => e.id)), a = t.length ? Math.min(...t.map((e) => Date.parse(e.createdAt))) : -Infinity, o = [...e.filter((e) => !r.has(e.id) && !i.has(e.id) && Date.parse(e.createdAt) > a), ...t].sort((e, t) => Date.parse(t.createdAt) - Date.parse(e.createdAt)), s = e.some((e) => i.has(e.id) && r.has(e.id));
31
+ if (!n || t.length === 0 || !s) return {
32
+ list: o,
33
+ continued: !1
34
+ };
35
+ let c = e.filter((e) => !i.has(e.id) && r.has(e.id) && Date.parse(e.createdAt) <= a);
36
+ return {
37
+ list: [...o, ...c],
38
+ continued: c.length > 0
39
+ };
40
+ }
41
+ export { n as appendNotificationPage, r as mergeRefreshedFirstPage, t as nextNotificationWindow, e as stillListed };
42
+
43
+ //# sourceMappingURL=notificationPaging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notificationPaging.js","names":["stillListed","filter","notification","nextNotificationWindow","oldest","ties","loaded","fromServerPages","at","counts","before","appendNotificationPage","seen","page","mergeRefreshedFirstPage","fresh","firstPage","head","b","a","overlaps","firstPageHasMore","older"],"sources":["../../src/hooks/notificationPaging.ts"],"sourcesContent":["/**\n * Paging rules for the notification lists (BOFF-15331).\n *\n * The service lists `notifications(filter, limit, offset)` newest first\n * (`createdAt` descending) and its `endDate` filter is inclusive. The list on\n * screen keeps changing while it is open: new notifications arrive live at\n * the top, and marking one read or archiving it can take it out of the\n * filtered list. A plain offset would have to track all of that, so the next\n * page is asked for by time instead: everything created at or before the\n * oldest notification already loaded. Nothing newer can move that window, so\n * scrolling never skips a notification; the few rows it repeats are dropped.\n */\nimport type { Notification, NotificationFilter } from '../types';\n\n/** The page size the lists request. */\nexport const NOTIFICATION_PAGE_SIZE = 50;\n/** The most the service returns in one request. */\nexport const NOTIFICATION_MAX_PAGE_SIZE = 100;\n\ntype Listed = Pick<Notification, 'id' | 'createdAt'>;\n\n/**\n * Whether the server still lists this notification under the filter. Only the\n * read and archived state can change on this page after it was loaded.\n */\nexport function stillListed(\n notification: Partial<Pick<Notification, 'readAt' | 'archivedAt'>>,\n filter: Pick<NotificationFilter, 'isRead' | 'archived'>\n): boolean {\n if (filter.isRead === true && !notification.readAt) return false;\n if (filter.isRead === false && notification.readAt) return false;\n if (filter.archived === true && !notification.archivedAt) return false;\n if (filter.archived === false && notification.archivedAt) return false;\n return true;\n}\n\n/** Where the next page starts: `createdAt <= before`, then `offset`/`limit`. */\nexport interface NotificationPageWindow {\n before: Date;\n limit: number;\n offset: number;\n}\n\n/**\n * The next page after the notifications loaded from the server's pages\n * (`fromServerPages`; live arrivals are newer, so they never matter here).\n *\n * The window starts at the oldest loaded notification, inclusive, so the\n * notifications sharing its exact `createdAt` are asked for again together\n * with the next page and dropped as repeats. The service orders only by\n * `createdAt`, so the order inside such a tie can change between requests;\n * fetching the whole tie again means none of it is ever skipped. Only tied\n * rows the server still lists under the filter are counted (one marked read\n * in an unread view is no longer in its result).\n */\nexport function nextNotificationWindow<\n T extends Listed & Partial<Pick<Notification, 'readAt' | 'archivedAt'>>,\n>(\n loaded: readonly T[],\n fromServerPages: ReadonlySet<string>,\n filter: Pick<NotificationFilter, 'isRead' | 'archived'>\n): NotificationPageWindow | null {\n let oldest = Number.POSITIVE_INFINITY;\n let ties = 0;\n for (const notification of loaded) {\n if (!fromServerPages.has(notification.id)) continue;\n const at = Date.parse(notification.createdAt);\n if (Number.isNaN(at)) continue;\n const counts = stillListed(notification, filter) ? 1 : 0;\n if (at < oldest) {\n oldest = at;\n ties = counts;\n } else if (at === oldest) {\n ties += counts;\n }\n }\n if (!Number.isFinite(oldest)) return null;\n const before = new Date(oldest);\n // The tie plus a full page fits in one request: ask for both.\n if (ties + NOTIFICATION_PAGE_SIZE <= NOTIFICATION_MAX_PAGE_SIZE) {\n return { before, offset: 0, limit: ties + NOTIFICATION_PAGE_SIZE };\n }\n // A tie larger than a page (one huge batch): step past it by offset. The\n // service's order inside a tie is not stable yet (BOFF-15333).\n return { before, offset: ties, limit: NOTIFICATION_PAGE_SIZE };\n}\n\n/** Adds a page after the loaded notifications, skipping any already shown. */\nexport function appendNotificationPage<T extends Pick<Notification, 'id'>>(\n loaded: readonly T[],\n page: readonly T[]\n): T[] {\n const seen = new Set(loaded.map((notification) => notification.id));\n return [...loaded, ...page.filter((notification) => !seen.has(notification.id))];\n}\n\n/**\n * The list after the first page was fetched again (the tab became visible).\n *\n * When the fresh first page overlaps a notification loaded from the server's\n * pages (`fromServerPages`; a live arrival proves nothing about what lies\n * between it and the older pages), the loaded\n * notifications at or before its oldest one carry on straight after it and\n * are kept, so coming back to the tab does not throw away the pages scrolled\n * through (`continued`). Loaded rows newer than that and missing from the\n * fresh page left the list meanwhile and are dropped, except live arrivals\n * that came in while the refresh was on its way. With no overlap, more\n * than a page arrived and there is a gap of unknown size, so the list starts\n * over from the fresh page instead.\n */\nexport function mergeRefreshedFirstPage<T extends Listed>(\n loaded: readonly T[],\n firstPage: readonly T[],\n firstPageHasMore: boolean,\n fromServerPages: ReadonlySet<string>\n): { list: T[]; continued: boolean } {\n const fresh = new Set(firstPage.map((notification) => notification.id));\n const oldest = firstPage.length\n ? Math.min(...firstPage.map((notification) => Date.parse(notification.createdAt)))\n : Number.NEGATIVE_INFINITY;\n // Live arrivals newer than the fresh page and missing from it came in while\n // the refresh was on its way: keep them on top, newest first.\n const liveOnly = loaded.filter(\n (notification) =>\n !fromServerPages.has(notification.id) &&\n !fresh.has(notification.id) &&\n Date.parse(notification.createdAt) > oldest\n );\n const head = [...liveOnly, ...firstPage].sort(\n (a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt)\n );\n // The whole list fits in the first page, or nothing proves the older pages\n // connect to it: start over from the fresh page.\n const overlaps = loaded.some(\n (notification) => fresh.has(notification.id) && fromServerPages.has(notification.id)\n );\n if (!firstPageHasMore || firstPage.length === 0 || !overlaps) {\n return { list: head, continued: false };\n }\n const older = loaded.filter(\n (notification) =>\n !fresh.has(notification.id) &&\n fromServerPages.has(notification.id) &&\n Date.parse(notification.createdAt) <= oldest\n );\n return { list: [...head, ...older], continued: older.length > 0 };\n}\n"],"mappings":"AAyBA,SAAgBA,EACd,GACA,GACS;CAKT,OADA,EAHIC,EAAO,WAAW,MAAQ,CAACC,EAAa,UACxCD,EAAO,WAAW,MAASC,EAAa,UACxCD,EAAO,aAAa,MAAQ,CAACC,EAAa,cAC1CD,EAAO,aAAa,MAASC,EAAa;AAEhD;AAqBA,SAAgBC,EAGd,GACA,GACA,GAC+B;CAC/B,IAAIC,IAAS,UACTC,IAAO;CACX,KAAK,IAAMH,KAAgBI,GAAQ;EACjC,IAAI,CAACC,EAAgB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,EAAE,CACrF;CACA,IAAI,CAACmB,KAAoBL,EAAU,WAAW,KAAK,CAACI,GAClD,OAAO;EAAE,MAAMH;EAAM,WAAW;CAAM;CAExC,IAAMK,IAAQhB,EAAO,QAClB,MACC,CAACS,EAAM,IAAIb,EAAa,EAAE,KAC1BK,EAAgB,IAAIL,EAAa,EAAE,KACnC,KAAK,MAAMA,EAAa,SAAS,KAAKE,CAC1C;CACA,OAAO;EAAE,MAAM,CAAC,GAAGa,GAAM,GAAGK,CAAK;EAAG,WAAWA,EAAM,SAAS;CAAE;AAClE"}
@@ -21,6 +21,8 @@ export declare function useNotifications(options?: UseNotificationsOptions): {
21
21
  selectedNotification: Notification | null;
22
22
  notificationFilter: NotificationFilter;
23
23
  isLoading: boolean;
24
+ /** A further page is loading (infinite scroll). */
25
+ isLoadingMore: boolean;
24
26
  error: string | null;
25
27
  hasMore: boolean;
26
28
  total: number;