@micha.bigler/ui-core-micha 4.40.1 → 4.40.3

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.40.3 - UCM-NOTIF-17
4
+
5
+ Notification feed, unread count and pagination state are cleared before the
6
+ first committed render for a different account. Delayed operations from the
7
+ previous account cannot restore its state or request further feed pages.
8
+
9
+ ## 4.40.2 - UCM-SHELL-10
10
+
11
+ Notification and account menu buttons include their visible unread count or
12
+ avatar initials in their accessible names while retaining their existing
13
+ menu behavior.
14
+
3
15
  ## 4.40.1 - UCM-AUTH-18
4
16
 
5
17
  The English, French and Swahili signup password-too-short messages now match the existing local and server error wording.
@@ -54,7 +54,7 @@ export function UserMenu({ resolveLink, items = [], profileLink = '/account', av
54
54
  handleClose();
55
55
  (_a = item.onSelect) === null || _a === void 0 ? void 0 : _a.call(item);
56
56
  };
57
- return (_jsxs(_Fragment, { children: [_jsx(IconButton, { "aria-label": t('UserMenu.TITLE'), color: "inherit", onClick: (event) => setAnchorEl(event.currentTarget), children: _jsx(Avatar, { src: avatarSrc, sx: {
57
+ return (_jsxs(_Fragment, { children: [_jsx(IconButton, { "aria-label": [t('UserMenu.TITLE'), !avatarSrc && getInitials(user)].filter(Boolean).join(' '), color: "inherit", onClick: (event) => setAnchorEl(event.currentTarget), children: _jsx(Avatar, { src: avatarSrc, sx: {
58
58
  width: 32,
59
59
  height: 32,
60
60
  fontSize: '0.8rem',
@@ -1,5 +1,6 @@
1
1
  export const notificationsTranslations = {
2
2
  'NotificationBell.TITLE': { de: 'Benachrichtigungen', fr: 'Notifications', en: 'Notifications', sw: 'Arifa' },
3
+ 'NotificationBell.UNREAD': { de: '{{count}} ungelesen', fr: '{{count}} non lues', en: '{{count}} unread', sw: '{{count}} ambazo hazijasomwa' },
3
4
  'NotificationBell.EMPTY': { de: 'Keine Benachrichtigungen vorhanden.', fr: 'Aucune notification.', en: 'No notifications.', sw: 'Hakuna arifa.' },
4
5
  'NotificationBell.LOAD_MORE': { de: 'Mehr laden', fr: 'Charger plus', en: 'Load more', sw: 'Pakia zaidi' },
5
6
  'NotificationBell.LOADING': { de: 'Wird geladen…', fr: 'Chargement…', en: 'Loading…', sw: 'Inapakia…' },
@@ -20,7 +20,7 @@ export function NotificationBell({ resolveLink }) {
20
20
  if (resolveLink && typeof ((_a = notification.content) === null || _a === void 0 ? void 0 : _a.link) === 'string' && notification.content.link)
21
21
  resolveLink(notification.content.link);
22
22
  };
23
- return (_jsxs(_Fragment, { children: [_jsx(IconButton, { "aria-label": t('NotificationBell.TITLE'), color: "inherit", onClick: (event) => setAnchorEl(event.currentTarget), children: _jsx(Badge, { badgeContent: unreadCount, color: "error", max: 99, children: _jsx(NotificationsIcon, {}) }) }), _jsx(Menu, { anchorEl: anchorEl, anchorOrigin: { horizontal: 'right', vertical: 'bottom' }, onClose: () => setAnchorEl(null), open: open, transformOrigin: { horizontal: 'right', vertical: 'top' }, children: _jsxs(Box, { sx: { width: 320, maxWidth: 'calc(100vw - 32px)' }, children: [_jsxs(Box, { sx: { alignItems: 'center', display: 'flex', justifyContent: 'space-between', px: 2, py: 1 }, children: [_jsx(Typography, { variant: "subtitle1", children: t('NotificationBell.TITLE') }), (canMarkAll ? unreadCount > 0 : unreadIds.length > 0) && (_jsx(Button, { disabled: marking, onClick: () => canMarkAll ? markAllSeen() : Promise.resolve(markSeen(unreadIds)).catch(() => { }), size: "small", children: t(canMarkAll ? 'NotificationBell.MARK_ALL' : 'NotificationBell.MARK_LOADED') }))] }), markError && _jsx(Typography, { role: "alert", sx: { px: 2 }, children: t('NotificationBell.MARK_ERROR') }), notifications.length === 0 ? (_jsx(Typography, { sx: { px: 2, py: 2 }, variant: "body2", children: t('NotificationBell.EMPTY') })) : (_jsx(List, { dense: true, disablePadding: true, children: notifications.map((notification) => { var _a, _b, _c; var _d; return (_jsx(ListItemButton, { onClick: () => handleItemClick(notification), children: _jsx(ListItemText, { primary: t((_a = notification.content) === null || _a === void 0 ? void 0 : _a.title_key, ((_b = notification.content) === null || _b === void 0 ? void 0 : _b.params) || {}), secondary: ((_c = notification.content) === null || _c === void 0 ? void 0 : _c.body_key)
23
+ return (_jsxs(_Fragment, { children: [_jsx(IconButton, { "aria-label": `${t('NotificationBell.TITLE')} ${t('NotificationBell.UNREAD', { count: unreadCount > 99 ? '99+' : unreadCount })}`, color: "inherit", onClick: (event) => setAnchorEl(event.currentTarget), children: _jsx(Badge, { badgeContent: unreadCount, color: "error", max: 99, children: _jsx(NotificationsIcon, {}) }) }), _jsx(Menu, { anchorEl: anchorEl, anchorOrigin: { horizontal: 'right', vertical: 'bottom' }, onClose: () => setAnchorEl(null), open: open, transformOrigin: { horizontal: 'right', vertical: 'top' }, children: _jsxs(Box, { sx: { width: 320, maxWidth: 'calc(100vw - 32px)' }, children: [_jsxs(Box, { sx: { alignItems: 'center', display: 'flex', justifyContent: 'space-between', px: 2, py: 1 }, children: [_jsx(Typography, { variant: "subtitle1", children: t('NotificationBell.TITLE') }), (canMarkAll ? unreadCount > 0 : unreadIds.length > 0) && (_jsx(Button, { disabled: marking, onClick: () => canMarkAll ? markAllSeen() : Promise.resolve(markSeen(unreadIds)).catch(() => { }), size: "small", children: t(canMarkAll ? 'NotificationBell.MARK_ALL' : 'NotificationBell.MARK_LOADED') }))] }), markError && _jsx(Typography, { role: "alert", sx: { px: 2 }, children: t('NotificationBell.MARK_ERROR') }), notifications.length === 0 ? (_jsx(Typography, { sx: { px: 2, py: 2 }, variant: "body2", children: t('NotificationBell.EMPTY') })) : (_jsx(List, { dense: true, disablePadding: true, children: notifications.map((notification) => { var _a, _b, _c; var _d; return (_jsx(ListItemButton, { onClick: () => handleItemClick(notification), children: _jsx(ListItemText, { primary: t((_a = notification.content) === null || _a === void 0 ? void 0 : _a.title_key, ((_b = notification.content) === null || _b === void 0 ? void 0 : _b.params) || {}), secondary: ((_c = notification.content) === null || _c === void 0 ? void 0 : _c.body_key)
24
24
  ? t(notification.content.body_key, notification.content.params || {})
25
25
  : undefined, slotProps: { primary: { fontWeight: notification.seen || notification.dismissed ? 'regular' : 'bold' } } }) }, (_d = notification.id) !== null && _d !== void 0 ? _d : notification.notification_id)); }) })), feedError && _jsx(Typography, { role: "alert", sx: { px: 2 }, children: t('NotificationBell.LOAD_ERROR') }), feedError && !hasMore && _jsx(Button, { onClick: () => refresh().catch(() => { }), children: t('NotificationBell.RETRY') }), hasMore && _jsx(Button, { disabled: loadingMore, onClick: loadMore, children: t(loadingMore ? 'NotificationBell.LOADING' : feedError ? 'NotificationBell.RETRY' : 'NotificationBell.LOAD_MORE') }), !feedError && !hasMore && notifications.length > 0 && _jsx(Typography, { sx: { px: 2, py: 1 }, variant: "body2", children: t('NotificationBell.END') })] }) })] }));
26
26
  }
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
2
+ import { createContext, useCallback, useContext, useEffect, useInsertionEffect, useRef, useState } from 'react';
3
3
  import { AuthContext } from '../auth/AuthContext';
4
4
  import { getNotificationFeed, getUnreadCount, markNotifications, markAllNotificationsSeen } from './feedApi';
5
5
  import { DEFAULT_ENVELOPE, RealtimeContext, useRealtimeCore } from './realtime';
@@ -43,14 +43,9 @@ function NotificationsScope({ children, wsUrlBase }) {
43
43
  const auth = useContext(AuthContext);
44
44
  const authenticated = Boolean(auth === null || auth === void 0 ? void 0 : auth.user);
45
45
  const accountKey = (auth === null || auth === void 0 ? void 0 : auth.user) ? `user:${auth.user.id}` : 'logged-out';
46
- const accountRef = useRef(accountKey);
47
- const generation = useRef(0);
48
- if (accountRef.current !== accountKey) {
49
- accountRef.current = accountKey;
50
- generation.current += 1;
51
- }
52
- const accountGeneration = generation.current;
53
- const isCurrent = () => alive.current && generation.current === accountGeneration;
46
+ const [account, setAccount] = useState(() => ({ key: accountKey }));
47
+ const accountRef = useRef(account);
48
+ const isCurrent = () => alive.current && accountRef.current === account;
54
49
  const bootstrapSeed = auth === null || auth === void 0 ? void 0 : auth.bootstrapNotificationSeed;
55
50
  const consumeBootstrapSeed = auth === null || auth === void 0 ? void 0 : auth.consumeBootstrapNotificationSeed;
56
51
  const [notifications, setNotifications] = useState([]);
@@ -69,6 +64,31 @@ function NotificationsScope({ children, wsUrlBase }) {
69
64
  const [feedError, setFeedError] = useState(false);
70
65
  const [markError, setMarkError] = useState(false);
71
66
  const [marking, setMarking] = useState(false);
67
+ const [seeded, setSeeded] = useState(false);
68
+ if (account.key !== accountKey) {
69
+ setAccount({ key: accountKey });
70
+ setNotifications([]);
71
+ setUnreadCount(0);
72
+ setNext(null);
73
+ setCapable(false);
74
+ setLoadingMore(false);
75
+ setFeedError(false);
76
+ setMarkError(false);
77
+ setMarking(false);
78
+ setSeeded(false);
79
+ }
80
+ const accountGeneration = account;
81
+ useInsertionEffect(() => {
82
+ if (accountRef.current === account)
83
+ return;
84
+ accountRef.current = account;
85
+ notificationsRef.current = [];
86
+ nextRef.current = null;
87
+ loadingRef.current = false;
88
+ pageCount.current = 1;
89
+ pageVersion.current += 1;
90
+ pageEpoch.current += 1;
91
+ }, [account]);
72
92
  useEffect(() => { alive.current = true; return () => { alive.current = false; }; }, []);
73
93
  const setContinuation = (value) => { nextRef.current = value || null; setNext(value || null); };
74
94
  const replaceNotifications = useCallback((nextNotifications) => {
@@ -77,6 +97,8 @@ function NotificationsScope({ children, wsUrlBase }) {
77
97
  }, []);
78
98
  const refresh = useCallback(async () => {
79
99
  var _a;
100
+ if (!isCurrent())
101
+ return;
80
102
  if (!authenticated) {
81
103
  replaceNotifications([]);
82
104
  setUnreadCount(0);
@@ -89,6 +111,8 @@ function NotificationsScope({ children, wsUrlBase }) {
89
111
  let continuation = feed.next;
90
112
  const rows = [...(feed.results || [])];
91
113
  for (let page = 1; page < targetPages && continuation; page += 1) {
114
+ if (!isCurrent())
115
+ return;
92
116
  const result = await getNotificationFeed({ next: continuation });
93
117
  rows.push(...(result.results || []));
94
118
  continuation = result.next;
@@ -117,7 +141,6 @@ function NotificationsScope({ children, wsUrlBase }) {
117
141
  // Preserved here rather than connecting immediately, since `refresh()`'s
118
142
  // `replaceNotifications(...)` is unconditional and would silently drop a message that
119
143
  // arrived and patched state before the initial REST response landed.
120
- const [seeded, setSeeded] = useState(false);
121
144
  const { subscribe, onReconnect } = useRealtimeCore({
122
145
  active: authenticated && seeded,
123
146
  wsUrl: getWebSocketUrl(wsUrlBase),
@@ -221,6 +244,8 @@ function NotificationsScope({ children, wsUrlBase }) {
221
244
  };
222
245
  }, [authenticated, accountGeneration, refresh, replaceNotifications, consumeBootstrapSeed]);
223
246
  const mark = useCallback((action, ids) => {
247
+ if (!isCurrent())
248
+ return Promise.resolve();
224
249
  const selectedIds = Array.isArray(ids) ? ids : [];
225
250
  const selected = new Set(selectedIds);
226
251
  const current = notificationsRef.current;
@@ -273,7 +298,7 @@ function NotificationsScope({ children, wsUrlBase }) {
273
298
  const markDismissed = useCallback((ids) => mark('dismissed', ids), [mark]);
274
299
  const markDone = useCallback((ids) => mark('done', ids), [mark]);
275
300
  const loadMore = useCallback(async () => {
276
- if (!nextRef.current || loadingRef.current)
301
+ if (!isCurrent() || !nextRef.current || loadingRef.current)
277
302
  return;
278
303
  loadingRef.current = true;
279
304
  setLoadingMore(true);
@@ -308,7 +333,7 @@ function NotificationsScope({ children, wsUrlBase }) {
308
333
  }
309
334
  }, [replaceNotifications, accountGeneration]);
310
335
  const markAllSeen = useCallback(async () => {
311
- if (!capable || marking)
336
+ if (!isCurrent() || !capable || marking)
312
337
  return;
313
338
  setMarking(true);
314
339
  setMarkError(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "4.40.1",
3
+ "version": "4.40.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "exports": {
@@ -72,6 +72,7 @@
72
72
  "@testing-library/react": "^16.3.3",
73
73
  "@testing-library/user-event": "14.6.9",
74
74
  "@vitejs/plugin-react": "^6.3.0",
75
+ "axe-core": "4.14.1",
75
76
  "i18next": "^26.7.2",
76
77
  "jsdom": "^30.1.3",
77
78
  "react-i18next": "^17.1.13",