@notificationapi/react 0.0.32 → 0.0.33
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.
|
@@ -33,6 +33,7 @@ type Props = ({
|
|
|
33
33
|
initialLoadMaxAge?: Date;
|
|
34
34
|
playSoundOnNewNotification?: boolean;
|
|
35
35
|
newNotificationSoundPath?: string;
|
|
36
|
+
client?: typeof NotificationAPIClientSDK;
|
|
36
37
|
};
|
|
37
38
|
export declare const NotificationAPIProvider: React.FunctionComponent<PropsWithChildren<Props>> & {
|
|
38
39
|
useNotificationAPIContext: typeof useNotificationAPIContext;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx as B } from "react/jsx-runtime";
|
|
2
2
|
import { createContext as z, useState as N, useCallback as m, useMemo as F, useRef as k, useEffect as U, useContext as G } from "react";
|
|
3
|
-
const J = async (e, s, i, a, f, w,
|
|
4
|
-
const
|
|
3
|
+
const J = async (e, s, i, a, f, w, h) => {
|
|
4
|
+
const p = _(a, f, w), l = await fetch(
|
|
5
5
|
`https://${s}/${a}/users/${encodeURIComponent(
|
|
6
6
|
f
|
|
7
7
|
)}/${i}`,
|
|
8
8
|
{
|
|
9
9
|
method: e,
|
|
10
|
-
body: JSON.stringify(
|
|
10
|
+
body: JSON.stringify(h),
|
|
11
11
|
headers: {
|
|
12
|
-
Authorization: `Basic ${
|
|
12
|
+
Authorization: `Basic ${p}`
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
);
|
|
@@ -116,18 +116,18 @@ const J = async (e, s, i, a, f, w, p) => {
|
|
|
116
116
|
// e.g. identify simply maps to postUsers
|
|
117
117
|
getInAppNotifications: async (e) => {
|
|
118
118
|
const s = e.maxCountNeeded || n.config.getInAppDefaultCount, i = e.oldestNeeded || n.config.getInAppDefaultOldest;
|
|
119
|
-
let a = [], f = e.before, w = !0,
|
|
120
|
-
for (;
|
|
121
|
-
const
|
|
119
|
+
let a = [], f = e.before, w = !0, h = !0;
|
|
120
|
+
for (; h; ) {
|
|
121
|
+
const p = (await n.rest.getNotifications(
|
|
122
122
|
f,
|
|
123
123
|
s
|
|
124
124
|
)).notifications.filter(
|
|
125
125
|
(l) => !a.find((g) => g.id === l.id)
|
|
126
126
|
);
|
|
127
|
-
f =
|
|
127
|
+
f = p.reduce(
|
|
128
128
|
(l, g) => l < g.date ? l : g.date,
|
|
129
129
|
e.before
|
|
130
|
-
), a = [...a, ...
|
|
130
|
+
), a = [...a, ...p], w = p.length > 0, h = !0, (!w || a.length >= s || f < i) && (h = !1);
|
|
131
131
|
}
|
|
132
132
|
return {
|
|
133
133
|
items: a,
|
|
@@ -164,7 +164,7 @@ const J = async (e, s, i, a, f, w, p) => {
|
|
|
164
164
|
},
|
|
165
165
|
...e,
|
|
166
166
|
user: "userId" in e ? { id: e.userId } : e.user
|
|
167
|
-
}, [a, f] = N(), [w,
|
|
167
|
+
}, [a, f] = N(), [w, h] = N(), [p, l] = N(!1), [g, y] = N((/* @__PURE__ */ new Date()).toISOString()), [b, P] = N(!0), D = m(() => {
|
|
168
168
|
i.playSoundOnNewNotification && new Audio(i.newNotificationSoundPath).play().catch((r) => {
|
|
169
169
|
console.log("Failed to play new notification sound:", r);
|
|
170
170
|
});
|
|
@@ -175,7 +175,7 @@ const J = async (e, s, i, a, f, w, p) => {
|
|
|
175
175
|
...t
|
|
176
176
|
] : o));
|
|
177
177
|
}, []), u = F(() => {
|
|
178
|
-
const o = n.init({
|
|
178
|
+
const o = e.client ? e.client : n.init({
|
|
179
179
|
clientId: i.clientId,
|
|
180
180
|
userId: i.user.id,
|
|
181
181
|
hashedUserId: i.hashedUserId,
|
|
@@ -194,17 +194,18 @@ const J = async (e, s, i, a, f, w, p) => {
|
|
|
194
194
|
i.user.number,
|
|
195
195
|
i.hashedUserId,
|
|
196
196
|
S,
|
|
197
|
-
D
|
|
197
|
+
D,
|
|
198
|
+
e.client
|
|
198
199
|
]), O = m(
|
|
199
200
|
async (o, r) => {
|
|
200
201
|
const t = await u.rest.getNotifications(o, r);
|
|
201
202
|
y(t.oldestReceived), P(t.couldLoadMore), S(t.notifications);
|
|
202
203
|
},
|
|
203
204
|
[S, u.rest]
|
|
204
|
-
), v = k(b), C = k(
|
|
205
|
+
), v = k(b), C = k(p), x = k(g);
|
|
205
206
|
U(() => {
|
|
206
|
-
v.current = b, C.current =
|
|
207
|
-
}, [b,
|
|
207
|
+
v.current = b, C.current = p, x.current = g;
|
|
208
|
+
}, [b, p, g]);
|
|
208
209
|
const A = m(
|
|
209
210
|
async (o) => {
|
|
210
211
|
if (!(!o && (!v.current || C.current))) {
|
|
@@ -276,13 +277,13 @@ const J = async (e, s, i, a, f, w, p) => {
|
|
|
276
277
|
]), L = (o) => {
|
|
277
278
|
u.rest.postPreferences(o).then(() => {
|
|
278
279
|
u.getPreferences().then((r) => {
|
|
279
|
-
|
|
280
|
+
h(r);
|
|
280
281
|
});
|
|
281
282
|
});
|
|
282
283
|
};
|
|
283
284
|
U(() => {
|
|
284
|
-
f([]), l(!1),
|
|
285
|
-
|
|
285
|
+
f([]), l(!1), h(void 0), y((/* @__PURE__ */ new Date()).toISOString()), P(!0), A(!0), u.openWebSocket(), u.getPreferences().then((o) => {
|
|
286
|
+
h(o);
|
|
286
287
|
});
|
|
287
288
|
}, [u, A]);
|
|
288
289
|
const H = {
|