@micha.bigler/ui-core-micha 4.39.0 → 4.40.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.
- package/CHANGELOG.md +16 -0
- package/dist/i18n/authTranslations.js +3 -3
- package/dist/i18n/notificationsTranslations.js +19 -0
- package/dist/notifications/NotificationBell.js +5 -5
- package/dist/notifications/NotificationSettings.js +70 -3
- package/dist/notifications/NotificationsProvider.js +173 -13
- package/dist/notifications/api.js +16 -0
- package/dist/notifications/feedApi.js +15 -2
- package/dist/notifications/realtime.js +2 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.40.1 - UCM-AUTH-18
|
|
4
|
+
|
|
5
|
+
The English, French and Swahili signup password-too-short messages now match the existing local and server error wording.
|
|
6
|
+
|
|
7
|
+
## 4.40.0 - UCM-NOTIF-16
|
|
8
|
+
|
|
9
|
+
The notification bell pages through the inbox with a Load more control, offers a bulk mark-all-read
|
|
10
|
+
action when the backend advertises `capabilities.mark_all_seen`, reconciles the unread count from the
|
|
11
|
+
server and refreshes on the `notification.inbox_changed` realtime message. Notification state is keyed
|
|
12
|
+
by account, so a late response of a previous account never populates the next one. The notification
|
|
13
|
+
settings show a per-category channel matrix (inherit, enabled, disabled) from
|
|
14
|
+
`/api/notifications/preferences/channel-matrix/`. Requires django-core-micha 3.41.0 or newer for
|
|
15
|
+
paging, bulk marking and the matrix. Against an older backend the bell keeps the scoped
|
|
16
|
+
mark-loaded-as-read behaviour (no `capabilities.mark_all_seen`) and the matrix shows its retryable
|
|
17
|
+
load error. Existing context keys are unchanged.
|
|
18
|
+
|
|
3
19
|
## 4.39.0 - UCM-CHAT-20
|
|
4
20
|
|
|
5
21
|
Chat workspaces refresh managed model catalogues in the foreground and identify the source when
|
|
@@ -1833,9 +1833,9 @@ export const authTranslations = {
|
|
|
1833
1833
|
},
|
|
1834
1834
|
"Auth.PASSWORD_TOO_SHORT": {
|
|
1835
1835
|
"de": "Das Passwort muss mindestens 8 Zeichen lang sein.",
|
|
1836
|
-
"fr": "Le mot de passe doit
|
|
1837
|
-
"en": "
|
|
1838
|
-
"sw": "Nenosiri
|
|
1836
|
+
"fr": "Le mot de passe doit contenir au moins 8 caractères.",
|
|
1837
|
+
"en": "The password must be at least 8 characters long.",
|
|
1838
|
+
"sw": "Nenosiri linahitajika kuwa na angalau herufi 8."
|
|
1839
1839
|
},
|
|
1840
1840
|
"Auth.PASSWORD_MISMATCH": {
|
|
1841
1841
|
"de": "Die Passwörter stimmen nicht überein.",
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export const notificationsTranslations = {
|
|
2
2
|
'NotificationBell.TITLE': { de: 'Benachrichtigungen', fr: 'Notifications', en: 'Notifications', sw: 'Arifa' },
|
|
3
3
|
'NotificationBell.EMPTY': { de: 'Keine Benachrichtigungen vorhanden.', fr: 'Aucune notification.', en: 'No notifications.', sw: 'Hakuna arifa.' },
|
|
4
|
+
'NotificationBell.LOAD_MORE': { de: 'Mehr laden', fr: 'Charger plus', en: 'Load more', sw: 'Pakia zaidi' },
|
|
5
|
+
'NotificationBell.LOADING': { de: 'Wird geladen…', fr: 'Chargement…', en: 'Loading…', sw: 'Inapakia…' },
|
|
6
|
+
'NotificationBell.RETRY': { de: 'Erneut versuchen', fr: 'Réessayer', en: 'Retry', sw: 'Jaribu tena' },
|
|
7
|
+
'NotificationBell.LOAD_ERROR': { de: 'Benachrichtigungen konnten nicht geladen werden.', fr: 'Impossible de charger les notifications.', en: 'Could not load notifications.', sw: 'Arifa hazikuweza kupakiwa.' },
|
|
8
|
+
'NotificationBell.MARK_ERROR': { de: 'Änderung fehlgeschlagen. Bitte erneut versuchen.', fr: 'Échec de la modification. Réessayez.', en: 'Could not update notifications. Please retry.', sw: 'Arifa hazikuweza kusasishwa. Jaribu tena.' },
|
|
9
|
+
'NotificationBell.MARK_LOADED': { de: 'Geladene als gelesen markieren', fr: 'Marquer les notifications chargées comme lues', en: 'Mark loaded as read', sw: 'Weka zilizopakiwa kuwa zimesomwa' },
|
|
10
|
+
'NotificationBell.END': { de: 'Keine weiteren Benachrichtigungen.', fr: 'Aucune autre notification.', en: 'No more notifications.', sw: 'Hakuna arifa zaidi.' },
|
|
4
11
|
'NotificationBell.MARK_ALL': { de: 'Alle als gelesen markieren', fr: 'Tout marquer comme lu', en: 'Mark all as read', sw: 'Weka zote alama kuwa zimesomwa' },
|
|
5
12
|
'NotificationSettings.TITLE': { de: 'Benachrichtigungen', fr: 'Notifications', en: 'Notifications', sw: 'Arifa' },
|
|
6
13
|
'NotificationSettings.SUBTITLE': { de: 'Lege fest, wie du informiert werden möchtest.', fr: 'Choisissez comment vous souhaitez être informé.', en: 'Choose how you want to be notified.', sw: 'Chagua jinsi unavyotaka kuarifiwa.' },
|
|
@@ -27,6 +34,18 @@ export const notificationsTranslations = {
|
|
|
27
34
|
'NotificationSettings.SUBSCRIPTIONS_TITLE': { de: 'Abonnements', fr: 'Abonnements', en: 'Subscriptions', sw: 'Usajili' },
|
|
28
35
|
'NotificationSettings.SUBSCRIPTIONS_SUBTITLE': { de: 'Ereignisse, für die du dich freiwillig anmelden kannst.', fr: 'Événements auxquels vous pouvez vous inscrire volontairement.', en: 'Events you can opt in to receive.', sw: 'Matukio unayoweza kujiunga kupokea.' },
|
|
29
36
|
'NotificationSettings.SUBSCRIPTION_ERROR': { de: 'Abonnement konnte nicht aktualisiert werden.', fr: 'Impossible de mettre à jour l’abonnement.', en: 'Subscription could not be updated.', sw: 'Usajili haukuweza kusasishwa.' },
|
|
37
|
+
'NotificationSettings.MATRIX_TITLE': { de: 'Kategorien und Kanäle', fr: 'Catégories et canaux', en: 'Categories and channels', sw: 'Makundi na njia' },
|
|
38
|
+
'NotificationSettings.CHOICE_INHERIT': { de: 'Allgemeine Einstellung', fr: 'Réglage général', en: 'General setting', sw: 'Mpangilio wa jumla' },
|
|
39
|
+
'NotificationSettings.CHOICE_ON': { de: 'Ein', fr: 'Activé', en: 'On', sw: 'Washa' },
|
|
40
|
+
'NotificationSettings.CHOICE_OFF': { de: 'Aus', fr: 'Désactivé', en: 'Off', sw: 'Zima' },
|
|
41
|
+
'NotificationSettings.EFFECTIVE_ON': { de: 'Aktuell aktiviert', fr: 'Actuellement activé', en: 'Currently on', sw: 'Imewashwa kwa sasa' },
|
|
42
|
+
'NotificationSettings.EFFECTIVE_OFF': { de: 'Aktuell deaktiviert', fr: 'Actuellement désactivé', en: 'Currently off', sw: 'Imezimwa kwa sasa' },
|
|
43
|
+
'NotificationSettings.PUSH_DEVICE_UNAVAILABLE': { de: 'Push ist auf diesem Gerät nicht registriert.', fr: 'Les notifications push ne sont pas enregistrées sur cet appareil.', en: 'Push is not registered on this device.', sw: 'Push haijasajiliwa kwenye kifaa hiki.' },
|
|
44
|
+
'NotificationSettings.MATRIX_LOADING': { de: 'Einstellungen werden geladen…', fr: 'Chargement des paramètres…', en: 'Loading choices…', sw: 'Inapakia chaguo…' },
|
|
45
|
+
'NotificationSettings.MATRIX_SAVING': { de: 'Wird gespeichert…', fr: 'Enregistrement…', en: 'Saving…', sw: 'Inahifadhi…' },
|
|
46
|
+
'NotificationSettings.MATRIX_LOAD_ERROR': { de: 'Kanaleinstellungen konnten nicht geladen werden.', fr: 'Impossible de charger les choix de canaux.', en: 'Channel choices could not be loaded.', sw: 'Chaguo za njia hazikuweza kupakiwa.' },
|
|
47
|
+
'NotificationSettings.MATRIX_SAVE_ERROR': { de: 'Kanaleinstellung konnte nicht gespeichert werden. Bitte erneut auswählen.', fr: 'Impossible d’enregistrer le choix. Réessayez.', en: 'Channel choice could not be saved. Please choose again.', sw: 'Chaguo la njia halikuweza kuhifadhiwa. Chagua tena.' },
|
|
48
|
+
'NotificationSettings.RETRY': { de: 'Erneut versuchen', fr: 'Réessayer', en: 'Retry', sw: 'Jaribu tena' },
|
|
30
49
|
'PopupSurface.CLOSE': { de: 'Schliessen', fr: 'Fermer', en: 'Close', sw: 'Funga' },
|
|
31
50
|
'PopupSurface.TITLE': { de: 'Benachrichtigung', fr: 'Notification', en: 'Notification', sw: 'Arifa' },
|
|
32
51
|
};
|
|
@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
6
6
|
import { useNotifications } from './NotificationsProvider';
|
|
7
7
|
export function NotificationBell({ resolveLink }) {
|
|
8
8
|
const { t } = useTranslation();
|
|
9
|
-
const { notifications, unreadCount, markSeen } = useNotifications();
|
|
9
|
+
const { notifications, unreadCount, markSeen, markAllSeen, canMarkAll, marking, markError, loadMore, refresh, hasMore, loadingMore, feedError } = useNotifications();
|
|
10
10
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
11
11
|
const open = Boolean(anchorEl);
|
|
12
12
|
const unreadIds = notifications
|
|
@@ -15,12 +15,12 @@ export function NotificationBell({ resolveLink }) {
|
|
|
15
15
|
const handleItemClick = (notification) => {
|
|
16
16
|
var _a;
|
|
17
17
|
if (notification.id != null)
|
|
18
|
-
markSeen([notification.id]);
|
|
18
|
+
Promise.resolve(markSeen([notification.id])).catch(() => { });
|
|
19
19
|
setAnchorEl(null);
|
|
20
|
-
if (resolveLink && ((_a = notification.content) === null || _a === void 0 ? void 0 : _a.link))
|
|
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: {
|
|
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)
|
|
24
24
|
? t(notification.content.body_key, notification.content.params || {})
|
|
25
|
-
: undefined, slotProps: { primary: { fontWeight: notification.seen || notification.dismissed ? 'regular' : 'bold' } } }) }, (_d = notification.id) !== null && _d !== void 0 ? _d : notification.notification_id)); }) }))] }) })] }));
|
|
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,15 +1,21 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import Alert from '@mui/material/Alert';
|
|
5
|
+
import Button from '@mui/material/Button';
|
|
6
|
+
import FormControl from '@mui/material/FormControl';
|
|
7
|
+
import FormLabel from '@mui/material/FormLabel';
|
|
8
|
+
import Radio from '@mui/material/Radio';
|
|
9
|
+
import RadioGroup from '@mui/material/RadioGroup';
|
|
5
10
|
import Box from '@mui/material/Box';
|
|
6
11
|
import CircularProgress from '@mui/material/CircularProgress';
|
|
7
12
|
import Divider from '@mui/material/Divider';
|
|
8
13
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
9
14
|
import Switch from '@mui/material/Switch';
|
|
10
15
|
import Typography from '@mui/material/Typography';
|
|
16
|
+
import { AuthContext } from '../auth/AuthContext';
|
|
11
17
|
import NotificationsIcon from '@mui/icons-material/Notifications';
|
|
12
|
-
import { getNotificationPreferences, getVapidPublicKey, patchNotificationPreferences, removePushSubscription, savePushSubscription, setNotificationCategorySubscription, urlBase64ToUint8Array, } from './api';
|
|
18
|
+
import { getNotificationPreferences, getNotificationChannelMatrix, patchNotificationChannelChoice, getVapidPublicKey, patchNotificationPreferences, removePushSubscription, savePushSubscription, setNotificationCategorySubscription, urlBase64ToUint8Array, } from './api';
|
|
13
19
|
export const NOTIFICATION_SETTINGS_ALERT_SX = { mb: 2 };
|
|
14
20
|
export const NOTIFICATION_SETTINGS_HINT_ALERT_SX = { mb: 1.5 };
|
|
15
21
|
export const NOTIFICATION_SETTINGS_REACH_ALERT_SX = { mb: 1 };
|
|
@@ -53,6 +59,12 @@ function getIosInstallState() {
|
|
|
53
59
|
return isIos && !standalone;
|
|
54
60
|
}
|
|
55
61
|
export function NotificationSettings() {
|
|
62
|
+
var _a;
|
|
63
|
+
var _b;
|
|
64
|
+
const auth = useContext(AuthContext);
|
|
65
|
+
return _jsx(AccountNotificationSettings, {}, (_b = (_a = auth === null || auth === void 0 ? void 0 : auth.user) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : 'anonymous');
|
|
66
|
+
}
|
|
67
|
+
function AccountNotificationSettings() {
|
|
56
68
|
var _a, _b;
|
|
57
69
|
const { t } = useTranslation();
|
|
58
70
|
const [preferences, setPreferences] = useState(null);
|
|
@@ -64,6 +76,57 @@ export function NotificationSettings() {
|
|
|
64
76
|
const [error, setError] = useState('');
|
|
65
77
|
const [conflict, setConflict] = useState('');
|
|
66
78
|
const [savingSubscription, setSavingSubscription] = useState(null);
|
|
79
|
+
const [matrix, setMatrix] = useState([]);
|
|
80
|
+
const [matrixError, setMatrixError] = useState('');
|
|
81
|
+
const [matrixLoading, setMatrixLoading] = useState(true);
|
|
82
|
+
const [savingPair, setSavingPair] = useState(null);
|
|
83
|
+
const matrixVersion = useRef(0);
|
|
84
|
+
const active = useRef(true);
|
|
85
|
+
const refreshMatrix = async () => {
|
|
86
|
+
const version = ++matrixVersion.current;
|
|
87
|
+
setMatrixLoading(true);
|
|
88
|
+
setMatrixError('');
|
|
89
|
+
try {
|
|
90
|
+
const data = await getNotificationChannelMatrix();
|
|
91
|
+
if (active.current && version === matrixVersion.current)
|
|
92
|
+
setMatrix(data.results);
|
|
93
|
+
}
|
|
94
|
+
catch (_a) {
|
|
95
|
+
if (active.current && version === matrixVersion.current)
|
|
96
|
+
setMatrixError(t('NotificationSettings.MATRIX_LOAD_ERROR'));
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
if (active.current && version === matrixVersion.current)
|
|
100
|
+
setMatrixLoading(false);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
active.current = true;
|
|
105
|
+
refreshMatrix();
|
|
106
|
+
return () => { active.current = false; matrixVersion.current += 1; };
|
|
107
|
+
}, []);
|
|
108
|
+
const handleChoice = async (row, choice) => {
|
|
109
|
+
if (savingPair)
|
|
110
|
+
return;
|
|
111
|
+
const pair = `${row.category}:${row.channel}`;
|
|
112
|
+
++matrixVersion.current;
|
|
113
|
+
setMatrixLoading(false);
|
|
114
|
+
setSavingPair(pair);
|
|
115
|
+
setMatrixError('');
|
|
116
|
+
try {
|
|
117
|
+
const updated = await patchNotificationChannelChoice(row.category, row.channel, choice);
|
|
118
|
+
if (active.current)
|
|
119
|
+
setMatrix((current) => current.map((item) => (item.category === row.category && item.channel === row.channel ? updated : item)));
|
|
120
|
+
}
|
|
121
|
+
catch (_a) {
|
|
122
|
+
if (active.current)
|
|
123
|
+
setMatrixError(t('NotificationSettings.MATRIX_SAVE_ERROR'));
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
if (active.current)
|
|
127
|
+
setSavingPair(null);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
67
130
|
const pushSupported = getPushSupport();
|
|
68
131
|
const iosNeedsInstall = getIosInstallState();
|
|
69
132
|
useEffect(() => {
|
|
@@ -106,6 +169,8 @@ export function NotificationSettings() {
|
|
|
106
169
|
try {
|
|
107
170
|
const updated = await patchNotificationPreferences({ email_opt_in });
|
|
108
171
|
setPreferences(updated);
|
|
172
|
+
if (active.current)
|
|
173
|
+
refreshMatrix();
|
|
109
174
|
}
|
|
110
175
|
catch (_a) {
|
|
111
176
|
setError(t('NotificationSettings.SAVE_ERROR'));
|
|
@@ -134,6 +199,8 @@ export function NotificationSettings() {
|
|
|
134
199
|
await savePushSubscription(subscription.toJSON(), navigator.userAgent);
|
|
135
200
|
const updated = await patchNotificationPreferences({ push_opt_in: true });
|
|
136
201
|
setPreferences(updated);
|
|
202
|
+
if (active.current)
|
|
203
|
+
refreshMatrix();
|
|
137
204
|
setPushSubscribed(true);
|
|
138
205
|
}
|
|
139
206
|
catch (requestError) {
|
|
@@ -207,7 +274,7 @@ export function NotificationSettings() {
|
|
|
207
274
|
if (loading) {
|
|
208
275
|
return _jsx(Box, { sx: { display: 'flex', justifyContent: 'center', py: 4 }, children: _jsx(CircularProgress, {}) });
|
|
209
276
|
}
|
|
210
|
-
return (_jsxs(Box, { sx: { maxWidth: 520 }, children: [_jsxs(Typography, { variant: "h6", gutterBottom: true, sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: [_jsx(NotificationsIcon, {}), t('NotificationSettings.TITLE')] }), _jsx(Typography, { variant: "body2", color: "text.secondary", gutterBottom: true, children: t('NotificationSettings.SUBTITLE') }), error && _jsx(Alert, { severity: "error", sx: NOTIFICATION_SETTINGS_ALERT_SX, onClose: () => setError(''), children: error }), conflict && _jsx(Alert, { severity: "warning", sx: NOTIFICATION_SETTINGS_ALERT_SX, onClose: () => setConflict(''), children: conflict }), _jsx(Box, { sx: { py: 2 }, children: _jsx(FormControlLabel, { control: _jsx(Switch, { checked: Boolean(preferences === null || preferences === void 0 ? void 0 : preferences.email_opt_in), onChange: handleEmailToggle, disabled: savingEmail }), label: _jsxs(Box, { children: [_jsx(Typography, { variant: "body1", children: t('NotificationSettings.EMAIL_LABEL') }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('NotificationSettings.EMAIL_HINT') })] }), labelPlacement: "end", sx: NOTIFICATION_SETTINGS_FORM_CONTROL_SX }) }), _jsx(Divider, {}), _jsxs(Box, { sx: { py: 2 }, children: [iosNeedsInstall && _jsx(Alert, { severity: "info", sx: NOTIFICATION_SETTINGS_HINT_ALERT_SX, children: t('NotificationSettings.IOS_HINT') }), !pushSupported && !iosNeedsInstall && _jsx(Alert, { severity: "warning", sx: NOTIFICATION_SETTINGS_HINT_ALERT_SX, children: t('NotificationSettings.PUSH_NOT_SUPPORTED') }), _jsx(FormControlLabel, { control: (_jsx(Switch, { checked: pushSubscribed, onChange: (event) => (event.target.checked ? handleEnablePush() : handleDisablePush()), disabled: savingPush || !pushSupported || iosNeedsInstall })), label: _jsxs(Box, { children: [_jsx(Typography, { variant: "body1", children: t('NotificationSettings.PUSH_LABEL') }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('NotificationSettings.PUSH_HINT') })] }), labelPlacement: "end", sx: NOTIFICATION_SETTINGS_FORM_CONTROL_SX }), _jsx(FormControlLabel, { control: (_jsx(Switch, { checked: (preferences === null || preferences === void 0 ? void 0 : preferences.push_preview_opt_in) !== false, onChange: handlePreviewToggle, disabled: savingPreview || !(preferences === null || preferences === void 0 ? void 0 : preferences.push_opt_in) })), label: _jsxs(Box, { children: [_jsx(Typography, { variant: "body1", children: t('NotificationSettings.PUSH_PREVIEW_LABEL') }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('NotificationSettings.PUSH_PREVIEW_HINT') })] }), labelPlacement: "end", sx: NOTIFICATION_SETTINGS_PUSH_CONTROL_SX })] }), ((_a = preferences === null || preferences === void 0 ? void 0 : preferences.notification_types) === null || _a === void 0 ? void 0 : _a.length) > 0 && (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsxs(Box, { sx: { py: 2 }, children: [_jsx(Typography, { variant: "subtitle2", gutterBottom: true, children: t('NotificationSettings.REACH_TITLE') }), preferences.notification_types.map((notificationType) => {
|
|
277
|
+
return (_jsxs(Box, { sx: { maxWidth: 520 }, children: [_jsxs(Typography, { variant: "h6", gutterBottom: true, sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: [_jsx(NotificationsIcon, {}), t('NotificationSettings.TITLE')] }), _jsx(Typography, { variant: "body2", color: "text.secondary", gutterBottom: true, children: t('NotificationSettings.SUBTITLE') }), error && _jsx(Alert, { severity: "error", sx: NOTIFICATION_SETTINGS_ALERT_SX, onClose: () => setError(''), children: error }), conflict && _jsx(Alert, { severity: "warning", sx: NOTIFICATION_SETTINGS_ALERT_SX, onClose: () => setConflict(''), children: conflict }), _jsx(Box, { sx: { py: 2 }, children: _jsx(FormControlLabel, { control: _jsx(Switch, { checked: Boolean(preferences === null || preferences === void 0 ? void 0 : preferences.email_opt_in), onChange: handleEmailToggle, disabled: savingEmail }), label: _jsxs(Box, { children: [_jsx(Typography, { variant: "body1", children: t('NotificationSettings.EMAIL_LABEL') }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('NotificationSettings.EMAIL_HINT') })] }), labelPlacement: "end", sx: NOTIFICATION_SETTINGS_FORM_CONTROL_SX }) }), _jsx(Divider, {}), _jsxs(Box, { sx: { py: 2 }, children: [iosNeedsInstall && _jsx(Alert, { severity: "info", sx: NOTIFICATION_SETTINGS_HINT_ALERT_SX, children: t('NotificationSettings.IOS_HINT') }), !pushSupported && !iosNeedsInstall && _jsx(Alert, { severity: "warning", sx: NOTIFICATION_SETTINGS_HINT_ALERT_SX, children: t('NotificationSettings.PUSH_NOT_SUPPORTED') }), _jsx(FormControlLabel, { control: (_jsx(Switch, { checked: pushSubscribed, onChange: (event) => (event.target.checked ? handleEnablePush() : handleDisablePush()), disabled: savingPush || !pushSupported || iosNeedsInstall })), label: _jsxs(Box, { children: [_jsx(Typography, { variant: "body1", children: t('NotificationSettings.PUSH_LABEL') }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('NotificationSettings.PUSH_HINT') })] }), labelPlacement: "end", sx: NOTIFICATION_SETTINGS_FORM_CONTROL_SX }), _jsx(FormControlLabel, { control: (_jsx(Switch, { checked: (preferences === null || preferences === void 0 ? void 0 : preferences.push_preview_opt_in) !== false, onChange: handlePreviewToggle, disabled: savingPreview || !(preferences === null || preferences === void 0 ? void 0 : preferences.push_opt_in) })), label: _jsxs(Box, { children: [_jsx(Typography, { variant: "body1", children: t('NotificationSettings.PUSH_PREVIEW_LABEL') }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('NotificationSettings.PUSH_PREVIEW_HINT') })] }), labelPlacement: "end", sx: NOTIFICATION_SETTINGS_PUSH_CONTROL_SX })] }), _jsx(Divider, {}), _jsxs(Box, { sx: { py: 2 }, children: [matrixLoading && _jsx(Typography, { role: "status", children: t('NotificationSettings.MATRIX_LOADING') }), matrixError && _jsx(Alert, { severity: "error", action: _jsx(Button, { onClick: refreshMatrix, children: t('NotificationSettings.RETRY') }), children: matrixError }), matrix.length > 0 && _jsx(Typography, { variant: "subtitle2", gutterBottom: true, children: t('NotificationSettings.MATRIX_TITLE') }), matrix.map((row) => (_jsxs(Box, { sx: { py: 1, overflowWrap: 'anywhere' }, children: [_jsxs(FormControl, { component: "fieldset", "aria-busy": Boolean(savingPair), children: [_jsx(FormLabel, { component: "legend", children: row.label_key ? t(row.label_key, { defaultValue: row.label }) : row.label }), _jsxs(RadioGroup, { row: true, value: row.choice, onChange: (event) => handleChoice(row, event.target.value), children: [_jsx(FormControlLabel, { value: "inherit", control: _jsx(Radio, {}), label: t('NotificationSettings.CHOICE_INHERIT') }), _jsx(FormControlLabel, { value: "enabled", control: _jsx(Radio, {}), label: t('NotificationSettings.CHOICE_ON') }), _jsx(FormControlLabel, { value: "disabled", control: _jsx(Radio, {}), label: t('NotificationSettings.CHOICE_OFF') })] })] }), _jsx(Typography, { variant: "body2", color: "text.secondary", children: t(row.effective_enabled ? 'NotificationSettings.EFFECTIVE_ON' : 'NotificationSettings.EFFECTIVE_OFF') }), row.channel === 'push' && !pushSubscribed && _jsx(Typography, { variant: "body2", color: "text.secondary", children: t('NotificationSettings.PUSH_DEVICE_UNAVAILABLE') }), savingPair === `${row.category}:${row.channel}` && _jsx(Typography, { role: "status", children: t('NotificationSettings.MATRIX_SAVING') })] }, `${row.category}:${row.channel}`)))] }), ((_a = preferences === null || preferences === void 0 ? void 0 : preferences.notification_types) === null || _a === void 0 ? void 0 : _a.length) > 0 && (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsxs(Box, { sx: { py: 2 }, children: [_jsx(Typography, { variant: "subtitle2", gutterBottom: true, children: t('NotificationSettings.REACH_TITLE') }), preferences.notification_types.map((notificationType) => {
|
|
211
278
|
const labelKey = reachLabelKey(notificationType);
|
|
212
279
|
const reachText = t(labelKey);
|
|
213
280
|
// Reserve Alert (a colored banner) for the one case that is actually a
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
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
|
-
import { getNotificationFeed, getUnreadCount, markNotifications } from './feedApi';
|
|
4
|
+
import { getNotificationFeed, getUnreadCount, markNotifications, markAllNotificationsSeen } from './feedApi';
|
|
5
5
|
import { DEFAULT_ENVELOPE, RealtimeContext, useRealtimeCore } from './realtime';
|
|
6
6
|
const NotificationsContext = createContext(null);
|
|
7
7
|
function normalizeNotification(notification) {
|
|
@@ -37,30 +37,80 @@ function patchStatus(notification, status) {
|
|
|
37
37
|
done, seen_at: seen ? notification.seen_at || true : null, dismissed_at: dismissed ? notification.dismissed_at || true : null, done_at: done ? notification.done_at || true : null });
|
|
38
38
|
}
|
|
39
39
|
export function NotificationsProvider({ children, wsUrlBase }) {
|
|
40
|
+
return _jsx(NotificationsScope, { wsUrlBase: wsUrlBase, children: children });
|
|
41
|
+
}
|
|
42
|
+
function NotificationsScope({ children, wsUrlBase }) {
|
|
40
43
|
const auth = useContext(AuthContext);
|
|
41
44
|
const authenticated = Boolean(auth === null || auth === void 0 ? void 0 : auth.user);
|
|
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;
|
|
42
54
|
const bootstrapSeed = auth === null || auth === void 0 ? void 0 : auth.bootstrapNotificationSeed;
|
|
43
55
|
const consumeBootstrapSeed = auth === null || auth === void 0 ? void 0 : auth.consumeBootstrapNotificationSeed;
|
|
44
56
|
const [notifications, setNotifications] = useState([]);
|
|
45
57
|
const [unreadCount, setUnreadCount] = useState(0);
|
|
46
58
|
const notificationsRef = useRef([]);
|
|
59
|
+
const alive = useRef(true);
|
|
60
|
+
const nextRef = useRef(null);
|
|
61
|
+
const loadingRef = useRef(false);
|
|
62
|
+
const liveVersion = useRef(0);
|
|
63
|
+
const pageCount = useRef(1);
|
|
64
|
+
const pageVersion = useRef(0);
|
|
65
|
+
const pageEpoch = useRef(0);
|
|
66
|
+
const [next, setNext] = useState(null);
|
|
67
|
+
const [capable, setCapable] = useState(false);
|
|
68
|
+
const [loadingMore, setLoadingMore] = useState(false);
|
|
69
|
+
const [feedError, setFeedError] = useState(false);
|
|
70
|
+
const [markError, setMarkError] = useState(false);
|
|
71
|
+
const [marking, setMarking] = useState(false);
|
|
72
|
+
useEffect(() => { alive.current = true; return () => { alive.current = false; }; }, []);
|
|
73
|
+
const setContinuation = (value) => { nextRef.current = value || null; setNext(value || null); };
|
|
47
74
|
const replaceNotifications = useCallback((nextNotifications) => {
|
|
48
75
|
notificationsRef.current = nextNotifications;
|
|
49
76
|
setNotifications(nextNotifications);
|
|
50
77
|
}, []);
|
|
51
78
|
const refresh = useCallback(async () => {
|
|
79
|
+
var _a;
|
|
52
80
|
if (!authenticated) {
|
|
53
81
|
replaceNotifications([]);
|
|
54
82
|
setUnreadCount(0);
|
|
55
83
|
return { notifications: [], unreadCount: 0 };
|
|
56
84
|
}
|
|
85
|
+
const version = liveVersion.current;
|
|
86
|
+
const pagesVersion = pageVersion.current;
|
|
87
|
+
const targetPages = pageCount.current;
|
|
57
88
|
const [feed, unread] = await Promise.all([getNotificationFeed(), getUnreadCount()]);
|
|
58
|
-
|
|
89
|
+
let continuation = feed.next;
|
|
90
|
+
const rows = [...(feed.results || [])];
|
|
91
|
+
for (let page = 1; page < targetPages && continuation; page += 1) {
|
|
92
|
+
const result = await getNotificationFeed({ next: continuation });
|
|
93
|
+
rows.push(...(result.results || []));
|
|
94
|
+
continuation = result.next;
|
|
95
|
+
}
|
|
96
|
+
if (!isCurrent())
|
|
97
|
+
return;
|
|
98
|
+
if (version !== liveVersion.current || pagesVersion !== pageVersion.current)
|
|
99
|
+
return refresh();
|
|
100
|
+
const nextNotifications = [];
|
|
101
|
+
for (const row of rows.map(normalizeNotification)) {
|
|
102
|
+
const index = nextNotifications.findIndex((item) => item.id === row.id || (row.notification_id != null && item.notification_id === row.notification_id));
|
|
103
|
+
if (index < 0)
|
|
104
|
+
nextNotifications.push(row);
|
|
105
|
+
}
|
|
59
106
|
const nextUnreadCount = unread.count || 0;
|
|
60
107
|
replaceNotifications(nextNotifications);
|
|
108
|
+
setContinuation(continuation);
|
|
109
|
+
setCapable(((_a = feed.capabilities) === null || _a === void 0 ? void 0 : _a.mark_all_seen) === true);
|
|
110
|
+
setFeedError(false);
|
|
61
111
|
setUnreadCount(nextUnreadCount);
|
|
62
112
|
return { notifications: nextNotifications, unreadCount: nextUnreadCount };
|
|
63
|
-
}, [authenticated, replaceNotifications]);
|
|
113
|
+
}, [authenticated, accountGeneration, replaceNotifications]);
|
|
64
114
|
// Seeded gates the socket connect, not just `authenticated`: the prior single-purpose
|
|
65
115
|
// socket owner awaited the initial REST feed/unread-count fetch before opening the
|
|
66
116
|
// WebSocket, so a live push could never race an empty/incomplete `notificationsRef`.
|
|
@@ -73,6 +123,14 @@ export function NotificationsProvider({ children, wsUrlBase }) {
|
|
|
73
123
|
wsUrl: getWebSocketUrl(wsUrlBase),
|
|
74
124
|
});
|
|
75
125
|
const handleRealtimeMessage = useCallback((data) => {
|
|
126
|
+
if (!isCurrent())
|
|
127
|
+
return;
|
|
128
|
+
liveVersion.current += 1;
|
|
129
|
+
if (data.type === 'notification.inbox_changed') {
|
|
130
|
+
refresh().catch(() => { if (isCurrent())
|
|
131
|
+
setFeedError(true); });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
76
134
|
if (data.type === 'notification.status') {
|
|
77
135
|
let unreadDelta = 0;
|
|
78
136
|
const nextNotifications = notificationsRef.current.map((notification) => {
|
|
@@ -108,14 +166,27 @@ export function NotificationsProvider({ children, wsUrlBase }) {
|
|
|
108
166
|
}
|
|
109
167
|
replaceNotifications([pushedNotification, ...notificationsRef.current]);
|
|
110
168
|
setUnreadCount((count) => count + 1);
|
|
111
|
-
}, [replaceNotifications]);
|
|
169
|
+
}, [replaceNotifications, refresh, accountGeneration]);
|
|
112
170
|
useEffect(() => {
|
|
113
171
|
if (!authenticated)
|
|
114
172
|
return undefined;
|
|
115
173
|
return subscribe(DEFAULT_ENVELOPE, handleRealtimeMessage);
|
|
116
174
|
}, [authenticated, subscribe, handleRealtimeMessage]);
|
|
117
175
|
useEffect(() => {
|
|
118
|
-
var _a, _b, _c;
|
|
176
|
+
var _a, _b, _c, _d;
|
|
177
|
+
replaceNotifications([]);
|
|
178
|
+
setUnreadCount(0);
|
|
179
|
+
setContinuation(null);
|
|
180
|
+
setCapable(false);
|
|
181
|
+
setFeedError(false);
|
|
182
|
+
setMarkError(false);
|
|
183
|
+
setMarking(false);
|
|
184
|
+
setLoadingMore(false);
|
|
185
|
+
setSeeded(false);
|
|
186
|
+
pageCount.current = 1;
|
|
187
|
+
pageVersion.current += 1;
|
|
188
|
+
pageEpoch.current += 1;
|
|
189
|
+
loadingRef.current = false;
|
|
119
190
|
if (!authenticated) {
|
|
120
191
|
replaceNotifications([]);
|
|
121
192
|
setUnreadCount(0);
|
|
@@ -129,6 +200,8 @@ export function NotificationsProvider({ children, wsUrlBase }) {
|
|
|
129
200
|
notificationsRef.current = nextNotifications;
|
|
130
201
|
setNotifications(nextNotifications);
|
|
131
202
|
setUnreadCount((unread === null || unread === void 0 ? void 0 : unread.count) || 0);
|
|
203
|
+
setContinuation(feed === null || feed === void 0 ? void 0 : feed.next);
|
|
204
|
+
setCapable(((_d = feed === null || feed === void 0 ? void 0 : feed.capabilities) === null || _d === void 0 ? void 0 : _d.mark_all_seen) === true);
|
|
132
205
|
setSeeded(true);
|
|
133
206
|
consumeBootstrapSeed === null || consumeBootstrapSeed === void 0 ? void 0 : consumeBootstrapSeed();
|
|
134
207
|
return undefined;
|
|
@@ -136,18 +209,17 @@ export function NotificationsProvider({ children, wsUrlBase }) {
|
|
|
136
209
|
let cancelled = false;
|
|
137
210
|
refresh()
|
|
138
211
|
.catch(() => {
|
|
139
|
-
|
|
212
|
+
if (isCurrent())
|
|
213
|
+
setFeedError(true);
|
|
140
214
|
})
|
|
141
215
|
.finally(() => {
|
|
142
|
-
if (!cancelled)
|
|
216
|
+
if (!cancelled && isCurrent())
|
|
143
217
|
setSeeded(true);
|
|
144
218
|
});
|
|
145
219
|
return () => {
|
|
146
220
|
cancelled = true;
|
|
147
221
|
};
|
|
148
|
-
|
|
149
|
-
// a dependency would refetch on a user switch without logout, which is not today's behaviour.
|
|
150
|
-
}, [authenticated, refresh, replaceNotifications, consumeBootstrapSeed]);
|
|
222
|
+
}, [authenticated, accountGeneration, refresh, replaceNotifications, consumeBootstrapSeed]);
|
|
151
223
|
const mark = useCallback((action, ids) => {
|
|
152
224
|
const selectedIds = Array.isArray(ids) ? ids : [];
|
|
153
225
|
const selected = new Set(selectedIds);
|
|
@@ -170,18 +242,106 @@ export function NotificationsProvider({ children, wsUrlBase }) {
|
|
|
170
242
|
if (unreadDelta) {
|
|
171
243
|
setUnreadCount((count) => Math.max(0, count - unreadDelta));
|
|
172
244
|
}
|
|
173
|
-
|
|
174
|
-
|
|
245
|
+
setMarkError(false);
|
|
246
|
+
return markNotifications({ action, ids: selectedIds }).catch(async (error) => {
|
|
247
|
+
if (isCurrent()) {
|
|
248
|
+
setMarkError(true);
|
|
249
|
+
try {
|
|
250
|
+
await refresh();
|
|
251
|
+
}
|
|
252
|
+
catch (_a) {
|
|
253
|
+
if (isCurrent()) {
|
|
254
|
+
let restoredUnread = 0;
|
|
255
|
+
const restored = notificationsRef.current.map((row) => {
|
|
256
|
+
const original = current.find((item) => item.id === row.id && selected.has(item.id));
|
|
257
|
+
if (!original)
|
|
258
|
+
return row;
|
|
259
|
+
const wasUnread = !row.seen && !row.dismissed;
|
|
260
|
+
const isUnread = !original.seen && !original.dismissed;
|
|
261
|
+
restoredUnread += Number(isUnread) - Number(wasUnread);
|
|
262
|
+
return Object.assign(Object.assign({}, row), { seen: original.seen, seen_at: original.seen_at, dismissed: original.dismissed, dismissed_at: original.dismissed_at, done: original.done, done_at: original.done_at });
|
|
263
|
+
});
|
|
264
|
+
replaceNotifications(restored);
|
|
265
|
+
setUnreadCount((count) => Math.max(0, count + restoredUnread));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
throw error;
|
|
270
|
+
});
|
|
271
|
+
}, [replaceNotifications, refresh, accountGeneration]);
|
|
175
272
|
const markSeen = useCallback((ids) => mark('seen', ids), [mark]);
|
|
176
273
|
const markDismissed = useCallback((ids) => mark('dismissed', ids), [mark]);
|
|
177
274
|
const markDone = useCallback((ids) => mark('done', ids), [mark]);
|
|
275
|
+
const loadMore = useCallback(async () => {
|
|
276
|
+
if (!nextRef.current || loadingRef.current)
|
|
277
|
+
return;
|
|
278
|
+
loadingRef.current = true;
|
|
279
|
+
setLoadingMore(true);
|
|
280
|
+
setFeedError(false);
|
|
281
|
+
const epoch = pageEpoch.current;
|
|
282
|
+
try {
|
|
283
|
+
const page = await getNotificationFeed({ next: nextRef.current });
|
|
284
|
+
if (!isCurrent() || epoch !== pageEpoch.current)
|
|
285
|
+
return;
|
|
286
|
+
const merged = [...notificationsRef.current];
|
|
287
|
+
for (const row of (page.results || []).map(normalizeNotification)) {
|
|
288
|
+
const index = merged.findIndex((item) => item.id === row.id || (row.notification_id != null && item.notification_id === row.notification_id));
|
|
289
|
+
if (index < 0)
|
|
290
|
+
merged.push(row);
|
|
291
|
+
else
|
|
292
|
+
merged[index] = Object.assign(Object.assign(Object.assign({}, row), merged[index]), { id: row.id });
|
|
293
|
+
}
|
|
294
|
+
replaceNotifications(merged);
|
|
295
|
+
pageCount.current += 1;
|
|
296
|
+
pageVersion.current += 1;
|
|
297
|
+
setContinuation(page.next);
|
|
298
|
+
}
|
|
299
|
+
catch (_a) {
|
|
300
|
+
if (isCurrent() && epoch === pageEpoch.current)
|
|
301
|
+
setFeedError(true);
|
|
302
|
+
}
|
|
303
|
+
finally {
|
|
304
|
+
if (isCurrent() && epoch === pageEpoch.current) {
|
|
305
|
+
loadingRef.current = false;
|
|
306
|
+
setLoadingMore(false);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}, [replaceNotifications, accountGeneration]);
|
|
310
|
+
const markAllSeen = useCallback(async () => {
|
|
311
|
+
if (!capable || marking)
|
|
312
|
+
return;
|
|
313
|
+
setMarking(true);
|
|
314
|
+
setMarkError(false);
|
|
315
|
+
try {
|
|
316
|
+
await markAllNotificationsSeen();
|
|
317
|
+
if (isCurrent()) {
|
|
318
|
+
pageEpoch.current += 1;
|
|
319
|
+
loadingRef.current = false;
|
|
320
|
+
setLoadingMore(false);
|
|
321
|
+
await refresh();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
catch (_a) {
|
|
325
|
+
if (isCurrent()) {
|
|
326
|
+
setMarkError(true);
|
|
327
|
+
try {
|
|
328
|
+
await refresh();
|
|
329
|
+
}
|
|
330
|
+
catch (_b) { /* retain current state */ }
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
finally {
|
|
334
|
+
if (isCurrent())
|
|
335
|
+
setMarking(false);
|
|
336
|
+
}
|
|
337
|
+
}, [capable, marking, refresh, accountGeneration]);
|
|
178
338
|
return (_jsx(RealtimeContext.Provider, { value: { subscribe, onReconnect }, children: _jsx(NotificationsContext.Provider, { value: {
|
|
179
339
|
notifications,
|
|
180
340
|
unreadCount,
|
|
181
341
|
markSeen,
|
|
182
342
|
markDismissed,
|
|
183
343
|
markDone,
|
|
184
|
-
refresh,
|
|
344
|
+
refresh, loadMore, hasMore: Boolean(next), loadingMore, feedError, markError, marking, markAllSeen, canMarkAll: capable,
|
|
185
345
|
}, children: children }) }));
|
|
186
346
|
}
|
|
187
347
|
export function useNotifications() {
|
|
@@ -10,6 +10,22 @@ export async function patchNotificationPreferences(patch) {
|
|
|
10
10
|
const response = await apiClient.patch(PREFERENCES_URL, patch);
|
|
11
11
|
return response.data;
|
|
12
12
|
}
|
|
13
|
+
export async function getNotificationChannelMatrix() {
|
|
14
|
+
var _a;
|
|
15
|
+
try {
|
|
16
|
+
const response = await apiClient.get(`${PREFERENCES_URL}channel-matrix/`);
|
|
17
|
+
return response.data;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) === 404)
|
|
21
|
+
return { results: [] };
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function patchNotificationChannelChoice(category, channel, choice) {
|
|
26
|
+
const response = await apiClient.patch(`${PREFERENCES_URL}channel-matrix/`, { category, channel, choice });
|
|
27
|
+
return response.data;
|
|
28
|
+
}
|
|
13
29
|
export async function setNotificationCategorySubscription(category, subscribed) {
|
|
14
30
|
const response = await apiClient.post(SUBSCRIPTIONS_URL, { category, subscribed });
|
|
15
31
|
return response.data;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import apiClient from '../auth/apiClient';
|
|
2
|
-
export async function getNotificationFeed({ status } = {}) {
|
|
3
|
-
|
|
2
|
+
export async function getNotificationFeed({ status, next } = {}) {
|
|
3
|
+
var _a;
|
|
4
|
+
let url = '/api/notifications/feed/';
|
|
5
|
+
if (next) {
|
|
6
|
+
const base = new URL(((_a = apiClient.defaults) === null || _a === void 0 ? void 0 : _a.baseURL) || window.location.origin, window.location.origin);
|
|
7
|
+
const continuation = new URL(next, base);
|
|
8
|
+
if (continuation.origin !== base.origin)
|
|
9
|
+
throw new Error('Invalid notification continuation origin');
|
|
10
|
+
url = continuation.href;
|
|
11
|
+
}
|
|
12
|
+
const response = await apiClient.get(url, {
|
|
4
13
|
params: status ? { status } : undefined,
|
|
5
14
|
});
|
|
6
15
|
return response.data;
|
|
@@ -13,3 +22,7 @@ export async function markNotifications({ action, ids }) {
|
|
|
13
22
|
const response = await apiClient.post('/api/notifications/feed/mark/', { action, ids });
|
|
14
23
|
return response.data;
|
|
15
24
|
}
|
|
25
|
+
export async function markAllNotificationsSeen() {
|
|
26
|
+
const response = await apiClient.post('/api/notifications/feed/mark-all-seen/', {});
|
|
27
|
+
return response.data;
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micha.bigler/ui-core-micha",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.40.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -70,15 +70,15 @@
|
|
|
70
70
|
"@mui/icons-material": "^7.3.11",
|
|
71
71
|
"@mui/x-charts": "^8.29.3",
|
|
72
72
|
"@testing-library/react": "^16.3.3",
|
|
73
|
-
"@testing-library/user-event": "14.6.
|
|
74
|
-
"@vitejs/plugin-react": "^6.
|
|
75
|
-
"i18next": "^26.7.
|
|
73
|
+
"@testing-library/user-event": "14.6.9",
|
|
74
|
+
"@vitejs/plugin-react": "^6.3.0",
|
|
75
|
+
"i18next": "^26.7.2",
|
|
76
76
|
"jsdom": "^30.1.3",
|
|
77
|
-
"react-i18next": "^17.1.
|
|
77
|
+
"react-i18next": "^17.1.13",
|
|
78
78
|
"react-markdown": "^10.1.0",
|
|
79
79
|
"remark-gfm": "^4.0.1",
|
|
80
80
|
"typescript": "^7.0.2",
|
|
81
|
-
"vite": "^8.3.
|
|
81
|
+
"vite": "^8.3.7",
|
|
82
82
|
"vitest": "^5.1.0"
|
|
83
83
|
}
|
|
84
84
|
}
|