@micha.bigler/ui-core-micha 2.12.0 → 2.14.0
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/WORK_ORDERS.md +2 -0
- package/dist/i18n/notificationsTranslations.js +2 -0
- package/dist/index.js +2 -0
- package/dist/notifications/NotificationsProvider.js +74 -91
- package/dist/notifications/PopupSurface.js +84 -0
- package/dist/notifications/realtime.js +110 -0
- package/dist/onboarding/OnboardingWizard.js +3 -12
- package/dist/onboarding/WizardDialogShell.js +29 -0
- package/package.json +1 -1
- package/src/i18n/notificationsTranslations.ts +2 -0
- package/src/index.js +2 -0
- package/src/notifications/NotificationsProvider.jsx +88 -96
- package/src/notifications/PopupSurface.jsx +103 -0
- package/src/notifications/realtime.jsx +118 -0
- package/src/onboarding/OnboardingWizard.jsx +9 -23
- package/src/onboarding/WizardDialogShell.jsx +51 -0
- package/tests/NotificationsProvider.test.jsx +39 -0
- package/tests/OnboardingWizard.test.jsx +143 -0
- package/tests/PopupSurface.test.jsx +142 -0
- package/tests/notificationsExports.test.js +5 -0
- package/tests/realtime.test.jsx +192 -0
- package/work-orders/NOTIF-12.md +214 -0
- package/work-orders/NOTIF-13.md +142 -0
package/WORK_ORDERS.md
CHANGED
|
@@ -22,3 +22,5 @@ prefixed ID; never reuse a bare flat number across workstreams.
|
|
|
22
22
|
| ONB-1 | Per-app configurable notifications onboarding step | New `browserPush` prop `{nagUntil, showOnce}` on `OnboardingProvider`; parameterizes the `browser_push` descriptor's condition (default changes from implicit "all-channels" to "any-channel", stopping the over-nag); `showOnce` via a persisted `onboarding_seen` set (frozen-at-mount ref, no mid-session flicker) | 2026-07-17 | done | 1ae7c20 | Default behavior change affects cockpit and all consumers on their next ucm bump. jg-ferien companion WO pins the new version with `browserPush={{nagUntil: 'any-channel'}}` explicit (matches new default, but pinned explicitly per the WO). |
|
|
23
23
|
| PERF-3B1 | Parallel auth bootstrap after CSRF | Starts auth-methods and current-user concurrently once CSRF is available, while preserving error handling and loading semantics. | 2026-07-19 | done | ee89329 | Independent `reviewer` + `sec_reviewer` passes both clean (no findings); one P3 test-coverage gap from the reviewer (missing mirror case: auth-methods rejects, current-user succeeds) closed with an added regression test — 45/45 tests green. Published as 2.10.1 (patch, no interface change) and pinned in jg-ferien alongside its PERF-3A companion WO. |
|
|
24
24
|
| NOTIF-6 | NotificationsProvider + bell on canonical dcm feed/* API | Single-WS-owner `NotificationsProvider`/`useNotifications` (initial REST seed via `feedApi.js` + one `/ws/notifications/` socket, reconnect w/ backoff) + generic MUI `NotificationBell`; additive exports only | 2026-07-27 | done | 6c63fb9 | Codex-built direct (no nesting), independent `reviewer`: single-WS-owner invariant traced clean (no way to break it — `authenticated`/`replaceNotifications`/`refresh` all referentially stable across unrelated re-renders, re-render test is genuine not a no-op). R1 (P2, real bug): the `notification.status` WS handler patched item flags but never adjusted `unreadCount`, so the badge went stale after a cross-tab/cross-device mark — the test had locked in the stale count as expected behavior. Fixed: delta computed from before/after unread state on the WS patch path, mirroring `mark()`'s own logic; test corrected + a new cross-tab regression test added. 57 passing, build clean. No new npm dependency. Full history + backend contract: dcm's `WORK_ORDERS.md`/`docs/design/notifications-platform.md`. Publishes ucm 2.11.0 |
|
|
25
|
+
| NOTIF-13 | Layer-1 transport extraction (pluggable realtime) | Extract the socket out of `NotificationsProvider` into a generic subscribe-by-message-type realtime primitive so a second domain (messaging) can ride the same socket; the catch-all that turns every non-`notification.status` message into a feed entry is replaced by explicit dispatch with unknown types ignored. Additive: `NotificationsProvider` stays the sole mount point, its context value unchanged. Full spec: [work-orders/NOTIF-13.md](work-orders/NOTIF-13.md). | 2026-07-29 | done | ucm: 7a83ee9; dcm: de77335 | Tier 2 (cockpit consumes `NotificationsProvider` at 2.12.0 in prod). Phase A, the hinge: unblocks NOTIF-15 (jg bell adoption) and is the substrate for Phase B messaging. Canonical register row: django-core-micha `WORK_ORDERS.md`. Operator decision 2026-07-29: additive only, NO standalone `RealtimeProvider` apps must mount. Scope E (envelope contract + helper + doc) also touches dcm; note that the roadmap wording "dcm multi-stream consumer" overstates it — `push_to_users`/`NotificationConsumer` are already stream-agnostic. Codex failed twice on this WO with a genuine CLI/model-version error (`gpt-5.6-terra requires a newer version of Codex`), not a transient issue — orchestrator fell back to direct Claude implementation per the Codex→Claude fallback rule. Independent `reviewer` (sec_reviewer not required per WO): found R1 (P2, real bug — decoupling the REST seed from the socket connect opened a race where a live push arriving before the initial feed loaded would be silently discarded by `refresh()`'s unconditional `replaceNotifications()`; fixed via a `seeded` state gate restoring the exact original seed-then-connect ordering, re-verified 70/70 green), R2 (P3 — the WO's "must be called out in the CHANGELOG" has no home since ucm has no CHANGELOG.md convention at all; operator decision: document via commit message + this register entry only, no new file), R3 (register housekeeping, closed by this update). ucm full suite 70/70 + `pnpm build` clean; dcm notifications suite 92/92, full dcm suite 392/392. Published: ucm 2.13.0 (npm), dcm 2.33.0 (PyPI, verified live before this record) — no app pin bumps in this WO per spec. |
|
|
26
|
+
| NOTIF-12 | Popup channel via the wizard renderer | Make `popup` a real delivery channel: extract the presentational dialog shell out of `OnboardingWizard`, render popup-eligible notifications through it, and record seen/dismissed on `NotificationRecipient` (design D-F7: renderer reuse only, NOT the onboarding progress store); dcm `PopupDispatcher` stops being a logging stub. Full spec: [work-orders/NOTIF-12.md](work-orders/NOTIF-12.md). | 2026-07-29 | planned | | Tier 2 (extracts a renderer cockpit+jg run in production; the roadmap label "uncritical" is about urgency, not blast radius). **HARD GATE: starts only after NOTIF-13 landed + published** — consumes its envelope contract and `subscribe()`, and edits the same ucm files (AGENTS.md overlap rule). **SHIPS WITH ZERO PRODUCERS, deliberately** (operator decision 2026-07-29, made with the evidence): no notification type declares `popup` in `eligible_channels` anywhere in dcm/jg/cockpit/hram/spesix/survey_app, so the channel is wired but inactive until an app opts a type in. WO therefore requires (a) CHANGELOG wording that does not overclaim (NOTIF-4 R1 precedent) and (b) a test-local producer type proving the path end-to-end, so it is not untested dead code. Was NOTIF-11 (renumbered 2026-07-29 for the jg cutover/drop split). **Gate satisfied 2026-07-30** (ucm 2.13.0 / dcm 2.33.0); WO re-verified against the landed NOTIF-13 code and corrected in `345631d`: NOTIF-13 shipped the envelope as a **domain**-level discriminator, so a popup payload built the same way as a chip payload would be indistinguishable from it - the WO now mandates a `channel` field inside the envelope (never a second envelope value) plus feed de-duplication by `notification_id`, without which chip+popup double-counts the unread badge. |
|
|
@@ -17,4 +17,6 @@ export const notificationsTranslations = {
|
|
|
17
17
|
'NotificationSettings.PUSH_CONFLICT': { de: 'Dieses Gerät ist bereits mit einem anderen Konto für Push-Benachrichtigungen verbunden.', fr: 'Cet appareil est déjà associé à un autre compte pour les notifications push.', en: 'This device is already associated with another account for push notifications.', sw: 'Kifaa hiki tayari kimeunganishwa na akaunti nyingine kwa arifa za push.' },
|
|
18
18
|
'NotificationSettings.PUSH_NOT_SUPPORTED': { de: 'Push-Benachrichtigungen werden von diesem Browser nicht unterstützt.', fr: 'Les notifications push ne sont pas prises en charge par ce navigateur.', en: 'Push notifications are not supported by this browser.', sw: 'Arifa za push hazitumiki na kivinjari hiki.' },
|
|
19
19
|
'NotificationSettings.IOS_HINT': { de: 'Füge diese App zuerst zum Home-Bildschirm hinzu, um Push-Benachrichtigungen zu aktivieren.', fr: 'Ajoutez d’abord cette application à l’écran d’accueil pour activer les notifications push.', en: 'Add this app to your home screen first to enable push notifications.', sw: 'Ongeza programu hii kwenye skrini yako ya mwanzo kwanza ili kuwasha arifa za push.' },
|
|
20
|
+
'PopupSurface.CLOSE': { de: 'Schliessen', fr: 'Fermer', en: 'Close', sw: 'Funga' },
|
|
21
|
+
'PopupSurface.TITLE': { de: 'Benachrichtigung', fr: 'Notification', en: 'Notification', sw: 'Arifa' },
|
|
20
22
|
};
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,9 @@ export { authTranslations } from './i18n/authTranslations';
|
|
|
33
33
|
export { NotificationSettings } from './notifications/NotificationSettings';
|
|
34
34
|
export * from './notifications/api';
|
|
35
35
|
export { NotificationsProvider, useNotifications } from './notifications/NotificationsProvider';
|
|
36
|
+
export { useRealtime } from './notifications/realtime';
|
|
36
37
|
export { NotificationBell } from './notifications/NotificationBell';
|
|
38
|
+
export { PopupSurface } from './notifications/PopupSurface';
|
|
37
39
|
export { getNotificationFeed, getUnreadCount, markNotifications } from './notifications/feedApi';
|
|
38
40
|
// --- 8. Onboarding ---
|
|
39
41
|
export * from './onboarding/api';
|
|
@@ -2,8 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { AuthContext } from '../auth/AuthContext';
|
|
4
4
|
import { getNotificationFeed, getUnreadCount, markNotifications } from './feedApi';
|
|
5
|
-
|
|
6
|
-
const MAX_BACKOFF_MS = 30000;
|
|
5
|
+
import { DEFAULT_ENVELOPE, RealtimeContext, useRealtimeCore } from './realtime';
|
|
7
6
|
const NotificationsContext = createContext(null);
|
|
8
7
|
function normalizeNotification(notification) {
|
|
9
8
|
var _a, _b, _c;
|
|
@@ -43,7 +42,6 @@ export function NotificationsProvider({ children, wsUrlBase }) {
|
|
|
43
42
|
const [notifications, setNotifications] = useState([]);
|
|
44
43
|
const [unreadCount, setUnreadCount] = useState(0);
|
|
45
44
|
const notificationsRef = useRef([]);
|
|
46
|
-
const socketRef = useRef(null);
|
|
47
45
|
const replaceNotifications = useCallback((nextNotifications) => {
|
|
48
46
|
notificationsRef.current = nextNotifications;
|
|
49
47
|
setNotifications(nextNotifications);
|
|
@@ -61,94 +59,79 @@ export function NotificationsProvider({ children, wsUrlBase }) {
|
|
|
61
59
|
setUnreadCount(nextUnreadCount);
|
|
62
60
|
return { notifications: nextNotifications, unreadCount: nextUnreadCount };
|
|
63
61
|
}, [authenticated, replaceNotifications]);
|
|
62
|
+
// Seeded gates the socket connect, not just `authenticated`: the prior single-purpose
|
|
63
|
+
// socket owner awaited the initial REST feed/unread-count fetch before opening the
|
|
64
|
+
// WebSocket, so a live push could never race an empty/incomplete `notificationsRef`.
|
|
65
|
+
// Preserved here rather than connecting immediately, since `refresh()`'s
|
|
66
|
+
// `replaceNotifications(...)` is unconditional and would silently drop a message that
|
|
67
|
+
// arrived and patched state before the initial REST response landed.
|
|
68
|
+
const [seeded, setSeeded] = useState(false);
|
|
69
|
+
const { subscribe } = useRealtimeCore({
|
|
70
|
+
active: authenticated && seeded,
|
|
71
|
+
wsUrl: getWebSocketUrl(wsUrlBase),
|
|
72
|
+
});
|
|
73
|
+
const handleRealtimeMessage = useCallback((data) => {
|
|
74
|
+
if (data.type === 'notification.status') {
|
|
75
|
+
let unreadDelta = 0;
|
|
76
|
+
const nextNotifications = notificationsRef.current.map((notification) => {
|
|
77
|
+
if (notification.notification_id !== data.notification_id)
|
|
78
|
+
return notification;
|
|
79
|
+
const wasUnread = !notification.seen && !notification.dismissed;
|
|
80
|
+
const patched = patchStatus(notification, data.status || {});
|
|
81
|
+
const isUnread = !patched.seen && !patched.dismissed;
|
|
82
|
+
if (wasUnread !== isUnread) {
|
|
83
|
+
unreadDelta += isUnread ? 1 : -1;
|
|
84
|
+
}
|
|
85
|
+
return patched;
|
|
86
|
+
});
|
|
87
|
+
replaceNotifications(nextNotifications);
|
|
88
|
+
if (unreadDelta) {
|
|
89
|
+
setUnreadCount((count) => Math.max(0, count + unreadDelta));
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const pushedNotification = normalizeNotificationPush(data);
|
|
94
|
+
// NOTIF-12 D2: a notification routed to more than one channel (e.g. chip
|
|
95
|
+
// + popup) arrives as multiple WS messages sharing one notification_id.
|
|
96
|
+
// Fold repeats into the existing feed entry (last-write-wins on content)
|
|
97
|
+
// instead of appending a duplicate and double-incrementing the badge.
|
|
98
|
+
const existingIndex = pushedNotification.notification_id == null
|
|
99
|
+
? -1
|
|
100
|
+
: notificationsRef.current.findIndex((notification) => notification.notification_id === pushedNotification.notification_id);
|
|
101
|
+
if (existingIndex !== -1) {
|
|
102
|
+
const nextNotifications = notificationsRef.current.map((notification, index) => (index === existingIndex
|
|
103
|
+
? Object.assign(Object.assign({}, notification), { notification_type: pushedNotification.notification_type, content: pushedNotification.content }) : notification));
|
|
104
|
+
replaceNotifications(nextNotifications);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
replaceNotifications([pushedNotification, ...notificationsRef.current]);
|
|
108
|
+
setUnreadCount((count) => count + 1);
|
|
109
|
+
}, [replaceNotifications]);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!authenticated)
|
|
112
|
+
return undefined;
|
|
113
|
+
return subscribe(DEFAULT_ENVELOPE, handleRealtimeMessage);
|
|
114
|
+
}, [authenticated, subscribe, handleRealtimeMessage]);
|
|
64
115
|
useEffect(() => {
|
|
65
116
|
if (!authenticated) {
|
|
66
117
|
replaceNotifications([]);
|
|
67
118
|
setUnreadCount(0);
|
|
119
|
+
setSeeded(false);
|
|
68
120
|
return undefined;
|
|
69
121
|
}
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
data = JSON.parse(event.data);
|
|
81
|
-
}
|
|
82
|
-
catch (_a) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (data.type === 'notification.status') {
|
|
86
|
-
let unreadDelta = 0;
|
|
87
|
-
patchNotifications((current) => current.map((notification) => {
|
|
88
|
-
if (notification.notification_id !== data.notification_id)
|
|
89
|
-
return notification;
|
|
90
|
-
const wasUnread = !notification.seen && !notification.dismissed;
|
|
91
|
-
const patched = patchStatus(notification, data.status || {});
|
|
92
|
-
const isUnread = !patched.seen && !patched.dismissed;
|
|
93
|
-
if (wasUnread !== isUnread) {
|
|
94
|
-
unreadDelta += isUnread ? 1 : -1;
|
|
95
|
-
}
|
|
96
|
-
return patched;
|
|
97
|
-
}));
|
|
98
|
-
if (unreadDelta) {
|
|
99
|
-
setUnreadCount((count) => Math.max(0, count + unreadDelta));
|
|
100
|
-
}
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const pushedNotification = normalizeNotificationPush(data);
|
|
104
|
-
patchNotifications((current) => [pushedNotification, ...current]);
|
|
105
|
-
setUnreadCount((count) => count + 1);
|
|
106
|
-
};
|
|
107
|
-
const connect = () => {
|
|
108
|
-
if (!active || socketRef.current)
|
|
109
|
-
return;
|
|
110
|
-
const socket = new WebSocket(getWebSocketUrl(wsUrlBase));
|
|
111
|
-
socketRef.current = socket;
|
|
112
|
-
socket.onopen = () => {
|
|
113
|
-
backoffMs = INITIAL_BACKOFF_MS;
|
|
114
|
-
};
|
|
115
|
-
socket.onmessage = handleMessage;
|
|
116
|
-
socket.onerror = () => {
|
|
117
|
-
socket.close();
|
|
118
|
-
};
|
|
119
|
-
socket.onclose = () => {
|
|
120
|
-
if (socketRef.current === socket) {
|
|
121
|
-
socketRef.current = null;
|
|
122
|
-
}
|
|
123
|
-
if (!active || reconnectTimer)
|
|
124
|
-
return;
|
|
125
|
-
reconnectTimer = setTimeout(() => {
|
|
126
|
-
reconnectTimer = null;
|
|
127
|
-
connect();
|
|
128
|
-
}, backoffMs);
|
|
129
|
-
backoffMs = Math.min(backoffMs * 2, MAX_BACKOFF_MS);
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
const seedAndConnect = async () => {
|
|
133
|
-
try {
|
|
134
|
-
await refresh();
|
|
135
|
-
}
|
|
136
|
-
catch (_a) {
|
|
137
|
-
// The live stream remains useful if the initial REST request is temporarily unavailable.
|
|
138
|
-
}
|
|
139
|
-
if (active)
|
|
140
|
-
connect();
|
|
141
|
-
};
|
|
142
|
-
seedAndConnect();
|
|
122
|
+
let cancelled = false;
|
|
123
|
+
refresh()
|
|
124
|
+
.catch(() => {
|
|
125
|
+
// The live stream remains useful if the initial REST request is temporarily unavailable.
|
|
126
|
+
})
|
|
127
|
+
.finally(() => {
|
|
128
|
+
if (!cancelled)
|
|
129
|
+
setSeeded(true);
|
|
130
|
+
});
|
|
143
131
|
return () => {
|
|
144
|
-
|
|
145
|
-
clearTimeout(reconnectTimer);
|
|
146
|
-
const socket = socketRef.current;
|
|
147
|
-
socketRef.current = null;
|
|
148
|
-
if (socket)
|
|
149
|
-
socket.close();
|
|
132
|
+
cancelled = true;
|
|
150
133
|
};
|
|
151
|
-
}, [authenticated, refresh, replaceNotifications
|
|
134
|
+
}, [authenticated, refresh, replaceNotifications]);
|
|
152
135
|
const mark = useCallback((action, ids) => {
|
|
153
136
|
const selectedIds = Array.isArray(ids) ? ids : [];
|
|
154
137
|
const selected = new Set(selectedIds);
|
|
@@ -176,14 +159,14 @@ export function NotificationsProvider({ children, wsUrlBase }) {
|
|
|
176
159
|
const markSeen = useCallback((ids) => mark('seen', ids), [mark]);
|
|
177
160
|
const markDismissed = useCallback((ids) => mark('dismissed', ids), [mark]);
|
|
178
161
|
const markDone = useCallback((ids) => mark('done', ids), [mark]);
|
|
179
|
-
return (_jsx(NotificationsContext.Provider, { value: {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
162
|
+
return (_jsx(RealtimeContext.Provider, { value: { subscribe }, children: _jsx(NotificationsContext.Provider, { value: {
|
|
163
|
+
notifications,
|
|
164
|
+
unreadCount,
|
|
165
|
+
markSeen,
|
|
166
|
+
markDismissed,
|
|
167
|
+
markDone,
|
|
168
|
+
refresh,
|
|
169
|
+
}, children: children }) }));
|
|
187
170
|
}
|
|
188
171
|
export function useNotifications() {
|
|
189
172
|
const context = useContext(NotificationsContext);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import Button from '@mui/material/Button';
|
|
5
|
+
import Stack from '@mui/material/Stack';
|
|
6
|
+
import Typography from '@mui/material/Typography';
|
|
7
|
+
import { useOnboarding } from '../onboarding/OnboardingProvider';
|
|
8
|
+
import { WizardDialogShell } from '../onboarding/WizardDialogShell';
|
|
9
|
+
import { useNotifications } from './NotificationsProvider';
|
|
10
|
+
import { DEFAULT_ENVELOPE, useRealtime } from './realtime';
|
|
11
|
+
function PopupStepComponent({ onDismiss, ctx }) {
|
|
12
|
+
const { t } = useTranslation();
|
|
13
|
+
const content = (ctx === null || ctx === void 0 ? void 0 : ctx.content) || {};
|
|
14
|
+
return (_jsxs(Stack, { spacing: 2, children: [content.body_key && (_jsx(Typography, { variant: "body1", children: t(content.body_key, content.params || {}) })), _jsx(Button, { onClick: onDismiss, sx: { alignSelf: 'flex-end' }, children: t('PopupSurface.CLOSE') })] }));
|
|
15
|
+
}
|
|
16
|
+
const POPUP_STEP = { blocking: false, Component: PopupStepComponent };
|
|
17
|
+
/**
|
|
18
|
+
* Renders popup-eligible notifications (NOTIF-12) through the onboarding
|
|
19
|
+
* wizard's dialog shell, reusing only the renderer (design D-F7) — status
|
|
20
|
+
* lives on NotificationRecipient via the existing feed/mark path, never in
|
|
21
|
+
* the onboarding progress store.
|
|
22
|
+
*
|
|
23
|
+
* Deliberately session-live only: it watches the raw realtime stream for
|
|
24
|
+
* `channel === "popup"` messages rather than the already-seeded feed list,
|
|
25
|
+
* since the feed carries no per-channel discriminator (see NotificationsProvider).
|
|
26
|
+
*/
|
|
27
|
+
export function PopupSurface() {
|
|
28
|
+
var _a;
|
|
29
|
+
const { t } = useTranslation();
|
|
30
|
+
const { markSeen, markDismissed } = useNotifications();
|
|
31
|
+
const { subscribe } = useRealtime();
|
|
32
|
+
const onboarding = useOnboarding();
|
|
33
|
+
const [queue, setQueue] = useState([]);
|
|
34
|
+
const seenIdsRef = useRef(new Set());
|
|
35
|
+
const handleRealtimeMessage = useCallback((data) => {
|
|
36
|
+
if (data.type === 'notification.status')
|
|
37
|
+
return;
|
|
38
|
+
if (data.channel !== 'popup')
|
|
39
|
+
return;
|
|
40
|
+
setQueue((previous) => {
|
|
41
|
+
var _a;
|
|
42
|
+
if (previous.some((item) => item.notification_id === data.notification_id))
|
|
43
|
+
return previous;
|
|
44
|
+
return [...previous, {
|
|
45
|
+
notification_id: data.notification_id,
|
|
46
|
+
// recipient_id is the id feed/mark/ actually resolves against
|
|
47
|
+
// (NotificationRecipient.pk, not Notification.pk). Fall back to
|
|
48
|
+
// notification_id only for an older dcm that predates it — matching
|
|
49
|
+
// NotificationsProvider's own normalizeNotificationPush precedent.
|
|
50
|
+
markId: (_a = data.recipient_id) !== null && _a !== void 0 ? _a : data.notification_id,
|
|
51
|
+
content: data.content || {},
|
|
52
|
+
}];
|
|
53
|
+
});
|
|
54
|
+
}, []);
|
|
55
|
+
useEffect(() => subscribe(DEFAULT_ENVELOPE, handleRealtimeMessage), [subscribe, handleRealtimeMessage]);
|
|
56
|
+
// Any active onboarding step — blocking or not — must win: OnboardingWizard
|
|
57
|
+
// renders its own dialog for as long as onboarding.activeSteps is non-empty,
|
|
58
|
+
// and two independent MUI Dialogs must never be mounted at once.
|
|
59
|
+
const onboardingActive = Boolean((_a = onboarding === null || onboarding === void 0 ? void 0 : onboarding.activeSteps) === null || _a === void 0 ? void 0 : _a.length);
|
|
60
|
+
const activePopup = queue[0];
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (!activePopup || onboardingActive)
|
|
63
|
+
return;
|
|
64
|
+
if (activePopup.markId == null)
|
|
65
|
+
return;
|
|
66
|
+
if (seenIdsRef.current.has(activePopup.notification_id))
|
|
67
|
+
return;
|
|
68
|
+
seenIdsRef.current.add(activePopup.notification_id);
|
|
69
|
+
markSeen([activePopup.markId]);
|
|
70
|
+
}, [activePopup, onboardingActive, markSeen]);
|
|
71
|
+
const dismissActivePopup = useCallback(() => {
|
|
72
|
+
if (!activePopup)
|
|
73
|
+
return;
|
|
74
|
+
if (activePopup.markId != null)
|
|
75
|
+
markDismissed([activePopup.markId]);
|
|
76
|
+
setQueue((previous) => previous.filter((item) => item.notification_id !== activePopup.notification_id));
|
|
77
|
+
}, [activePopup, markDismissed]);
|
|
78
|
+
if (!activePopup || onboardingActive)
|
|
79
|
+
return null;
|
|
80
|
+
return (_jsx(WizardDialogShell, { step: POPUP_STEP, stepIndex: 0, total: 1, onComplete: dismissActivePopup, onDismiss: dismissActivePopup, ctx: { content: activePopup.content }, title: activePopup.content.title_key
|
|
81
|
+
? t(activePopup.content.title_key, activePopup.content.params || {})
|
|
82
|
+
: t('PopupSurface.TITLE') }));
|
|
83
|
+
}
|
|
84
|
+
export default PopupSurface;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createContext, useCallback, useContext, useEffect, useRef } from 'react';
|
|
2
|
+
const INITIAL_BACKOFF_MS = 1000;
|
|
3
|
+
const MAX_BACKOFF_MS = 30000;
|
|
4
|
+
// Envelope discriminator for the notifications domain. A message with no
|
|
5
|
+
// `envelope` field (pre-NOTIF-13 dcm) is treated as this default so an
|
|
6
|
+
// un-bumped backend keeps working unchanged (backward-compat).
|
|
7
|
+
export const DEFAULT_ENVELOPE = 'notification';
|
|
8
|
+
const RealtimeContext = createContext(null);
|
|
9
|
+
export function useRealtime() {
|
|
10
|
+
const context = useContext(RealtimeContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('useRealtime must be used within a NotificationsProvider');
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
16
|
+
export { RealtimeContext };
|
|
17
|
+
/**
|
|
18
|
+
* Owns the single WebSocket connection and an envelope-keyed subscriber
|
|
19
|
+
* registry. Internal — consumed only by NotificationsProvider, which
|
|
20
|
+
* re-exposes `subscribe` via RealtimeContext so useRealtime() works without
|
|
21
|
+
* a separate provider apps have to mount.
|
|
22
|
+
*
|
|
23
|
+
* Backoff, reconnect, and cleanup semantics are unchanged from the prior
|
|
24
|
+
* single-purpose socket owner. `active`/`wsUrl` are primitives, so the
|
|
25
|
+
* effect does not re-run (and does not reconnect) on unrelated re-renders.
|
|
26
|
+
*/
|
|
27
|
+
export function useRealtimeCore({ active, wsUrl }) {
|
|
28
|
+
const socketRef = useRef(null);
|
|
29
|
+
const subscribersRef = useRef(new Map());
|
|
30
|
+
const subscribe = useCallback((envelope, handler) => {
|
|
31
|
+
const subscribers = subscribersRef.current;
|
|
32
|
+
if (!subscribers.has(envelope)) {
|
|
33
|
+
subscribers.set(envelope, new Set());
|
|
34
|
+
}
|
|
35
|
+
subscribers.get(envelope).add(handler);
|
|
36
|
+
return () => {
|
|
37
|
+
const handlers = subscribers.get(envelope);
|
|
38
|
+
if (!handlers)
|
|
39
|
+
return;
|
|
40
|
+
handlers.delete(handler);
|
|
41
|
+
if (handlers.size === 0) {
|
|
42
|
+
subscribers.delete(envelope);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!active)
|
|
48
|
+
return undefined;
|
|
49
|
+
let isActive = true;
|
|
50
|
+
let reconnectTimer = null;
|
|
51
|
+
let backoffMs = INITIAL_BACKOFF_MS;
|
|
52
|
+
const handleMessage = (event) => {
|
|
53
|
+
var _a;
|
|
54
|
+
let data;
|
|
55
|
+
try {
|
|
56
|
+
data = JSON.parse(event.data);
|
|
57
|
+
}
|
|
58
|
+
catch (_b) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const envelope = (_a = data.envelope) !== null && _a !== void 0 ? _a : DEFAULT_ENVELOPE;
|
|
62
|
+
const handlers = subscribersRef.current.get(envelope);
|
|
63
|
+
if (!handlers || handlers.size === 0)
|
|
64
|
+
return;
|
|
65
|
+
handlers.forEach((handler) => {
|
|
66
|
+
try {
|
|
67
|
+
handler(data);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error('Realtime subscriber error', error);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const connect = () => {
|
|
75
|
+
if (!isActive || socketRef.current)
|
|
76
|
+
return;
|
|
77
|
+
const socket = new WebSocket(wsUrl);
|
|
78
|
+
socketRef.current = socket;
|
|
79
|
+
socket.onopen = () => {
|
|
80
|
+
backoffMs = INITIAL_BACKOFF_MS;
|
|
81
|
+
};
|
|
82
|
+
socket.onmessage = handleMessage;
|
|
83
|
+
socket.onerror = () => {
|
|
84
|
+
socket.close();
|
|
85
|
+
};
|
|
86
|
+
socket.onclose = () => {
|
|
87
|
+
if (socketRef.current === socket) {
|
|
88
|
+
socketRef.current = null;
|
|
89
|
+
}
|
|
90
|
+
if (!isActive || reconnectTimer)
|
|
91
|
+
return;
|
|
92
|
+
reconnectTimer = setTimeout(() => {
|
|
93
|
+
reconnectTimer = null;
|
|
94
|
+
connect();
|
|
95
|
+
}, backoffMs);
|
|
96
|
+
backoffMs = Math.min(backoffMs * 2, MAX_BACKOFF_MS);
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
connect();
|
|
100
|
+
return () => {
|
|
101
|
+
isActive = false;
|
|
102
|
+
clearTimeout(reconnectTimer);
|
|
103
|
+
const socket = socketRef.current;
|
|
104
|
+
socketRef.current = null;
|
|
105
|
+
if (socket)
|
|
106
|
+
socket.close();
|
|
107
|
+
};
|
|
108
|
+
}, [active, wsUrl]);
|
|
109
|
+
return { subscribe };
|
|
110
|
+
}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
3
|
-
import { useTranslation } from 'react-i18next';
|
|
4
|
-
import Box from '@mui/material/Box';
|
|
5
|
-
import Dialog from '@mui/material/Dialog';
|
|
6
|
-
import DialogContent from '@mui/material/DialogContent';
|
|
7
|
-
import DialogTitle from '@mui/material/DialogTitle';
|
|
8
|
-
import LinearProgress from '@mui/material/LinearProgress';
|
|
9
|
-
import Typography from '@mui/material/Typography';
|
|
10
3
|
import { AuthContext } from '../auth/AuthContext';
|
|
11
4
|
import { useOnboarding } from './OnboardingProvider';
|
|
5
|
+
import { WizardDialogShell } from './WizardDialogShell';
|
|
12
6
|
export function OnboardingWizard() {
|
|
13
|
-
const { t } = useTranslation();
|
|
14
7
|
const onboarding = useOnboarding();
|
|
15
8
|
const authContext = useContext(AuthContext);
|
|
16
9
|
const [sessionDismissed, setSessionDismissed] = useState(() => new Set());
|
|
@@ -37,8 +30,6 @@ export function OnboardingWizard() {
|
|
|
37
30
|
return null;
|
|
38
31
|
const { dismissStep, ctx } = onboarding;
|
|
39
32
|
const total = totalRef.current || visibleSteps.length;
|
|
40
|
-
const progress = total > 1 ? Math.round((completed / total) * 100) : 0;
|
|
41
|
-
const StepComponent = currentStep.Component;
|
|
42
33
|
const completeCurrentStep = () => {
|
|
43
34
|
var _a, _b;
|
|
44
35
|
setSessionDismissed((previous) => new Set([...previous, currentStep.id]));
|
|
@@ -52,6 +43,6 @@ export function OnboardingWizard() {
|
|
|
52
43
|
dismissStep(currentStep.id);
|
|
53
44
|
completeCurrentStep();
|
|
54
45
|
};
|
|
55
|
-
return (
|
|
46
|
+
return (_jsx(WizardDialogShell, { step: currentStep, stepIndex: completed, total: total, onComplete: completeCurrentStep, onDismiss: dismissCurrentStep, ctx: ctx }));
|
|
56
47
|
}
|
|
57
48
|
export default OnboardingWizard;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import Box from '@mui/material/Box';
|
|
5
|
+
import Dialog from '@mui/material/Dialog';
|
|
6
|
+
import DialogContent from '@mui/material/DialogContent';
|
|
7
|
+
import DialogTitle from '@mui/material/DialogTitle';
|
|
8
|
+
import LinearProgress from '@mui/material/LinearProgress';
|
|
9
|
+
import Typography from '@mui/material/Typography';
|
|
10
|
+
/**
|
|
11
|
+
* Presentational dialog shell shared by OnboardingWizard and the popup
|
|
12
|
+
* notification surface (NOTIF-12). Owns only the dialog frame, the
|
|
13
|
+
* counter/progress header, and the onComplete/onDismiss/ctx child contract —
|
|
14
|
+
* step selection, dismissal persistence, and any progress store stay with
|
|
15
|
+
* the caller.
|
|
16
|
+
*/
|
|
17
|
+
export function WizardDialogShell({ step, stepIndex, total, onComplete, onDismiss, ctx, title }) {
|
|
18
|
+
const { t } = useTranslation();
|
|
19
|
+
const progress = total > 1 ? Math.round((stepIndex / total) * 100) : 0;
|
|
20
|
+
const StepComponent = step.Component;
|
|
21
|
+
// `title` lets a non-onboarding caller (e.g. the popup surface) supply its
|
|
22
|
+
// own header instead of the onboarding-specific step counter/"Setup" copy.
|
|
23
|
+
// Omitted by OnboardingWizard, so its header text is unchanged.
|
|
24
|
+
const headerLabel = title !== null && title !== void 0 ? title : (total > 1
|
|
25
|
+
? t('Onboarding.STEP_COUNTER', { current: stepIndex + 1, total })
|
|
26
|
+
: t('Onboarding.SETUP'));
|
|
27
|
+
return (_jsxs(Dialog, { open: true, fullWidth: true, maxWidth: "sm", disableEscapeKeyDown: step.blocking, onClose: step.blocking ? undefined : onDismiss, children: [_jsxs(DialogTitle, { sx: { pb: 0 }, children: [_jsx(Box, { sx: { display: 'flex', alignItems: 'center', justifyContent: 'space-between' }, children: _jsx(Typography, { variant: "subtitle2", color: "text.secondary", children: headerLabel }) }), total > 1 && _jsx(LinearProgress, { variant: "determinate", value: progress, sx: { mt: 1, borderRadius: 1 } })] }), _jsx(DialogContent, { sx: { pt: 2 }, children: _jsx(StepComponent, { onComplete: onComplete, onDismiss: onDismiss, ctx: ctx }) })] }));
|
|
28
|
+
}
|
|
29
|
+
export default WizardDialogShell;
|
package/package.json
CHANGED
|
@@ -17,4 +17,6 @@ export const notificationsTranslations = {
|
|
|
17
17
|
'NotificationSettings.PUSH_CONFLICT': { de: 'Dieses Gerät ist bereits mit einem anderen Konto für Push-Benachrichtigungen verbunden.', fr: 'Cet appareil est déjà associé à un autre compte pour les notifications push.', en: 'This device is already associated with another account for push notifications.', sw: 'Kifaa hiki tayari kimeunganishwa na akaunti nyingine kwa arifa za push.' },
|
|
18
18
|
'NotificationSettings.PUSH_NOT_SUPPORTED': { de: 'Push-Benachrichtigungen werden von diesem Browser nicht unterstützt.', fr: 'Les notifications push ne sont pas prises en charge par ce navigateur.', en: 'Push notifications are not supported by this browser.', sw: 'Arifa za push hazitumiki na kivinjari hiki.' },
|
|
19
19
|
'NotificationSettings.IOS_HINT': { de: 'Füge diese App zuerst zum Home-Bildschirm hinzu, um Push-Benachrichtigungen zu aktivieren.', fr: 'Ajoutez d’abord cette application à l’écran d’accueil pour activer les notifications push.', en: 'Add this app to your home screen first to enable push notifications.', sw: 'Ongeza programu hii kwenye skrini yako ya mwanzo kwanza ili kuwasha arifa za push.' },
|
|
20
|
+
'PopupSurface.CLOSE': { de: 'Schliessen', fr: 'Fermer', en: 'Close', sw: 'Funga' },
|
|
21
|
+
'PopupSurface.TITLE': { de: 'Benachrichtigung', fr: 'Notification', en: 'Notification', sw: 'Arifa' },
|
|
20
22
|
};
|
package/src/index.js
CHANGED
|
@@ -46,7 +46,9 @@ export { authTranslations } from './i18n/authTranslations';
|
|
|
46
46
|
export { NotificationSettings } from './notifications/NotificationSettings';
|
|
47
47
|
export * from './notifications/api';
|
|
48
48
|
export { NotificationsProvider, useNotifications } from './notifications/NotificationsProvider';
|
|
49
|
+
export { useRealtime } from './notifications/realtime';
|
|
49
50
|
export { NotificationBell } from './notifications/NotificationBell';
|
|
51
|
+
export { PopupSurface } from './notifications/PopupSurface';
|
|
50
52
|
export { getNotificationFeed, getUnreadCount, markNotifications } from './notifications/feedApi';
|
|
51
53
|
|
|
52
54
|
// --- 8. Onboarding ---
|