@novu/react 2.2.0 → 2.3.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/dist/client/index.d.mts +21 -6
- package/dist/client/index.d.ts +21 -6
- package/dist/client/index.js +218 -154
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +217 -153
- package/dist/client/index.mjs.map +1 -1
- package/dist/index.d.mts +34 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +167 -0
- package/dist/index.mjs +157 -0
- package/dist/themes/index.d.mts +1 -0
- package/dist/themes/index.d.ts +1 -0
- package/dist/themes/index.js +21 -0
- package/dist/themes/index.js.map +1 -0
- package/dist/themes/index.mjs +3 -0
- package/dist/themes/index.mjs.map +1 -0
- package/package.json +19 -5
- package/themes/package.json +5 -0
package/dist/client/index.mjs
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
// src/components/Bell.tsx
|
|
2
|
-
import
|
|
2
|
+
import React2 from "react";
|
|
3
|
+
|
|
4
|
+
// src/components/Mounter.tsx
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
function Mounter({ mount }) {
|
|
8
|
+
const ref = useRef(null);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
let unmount;
|
|
11
|
+
const element = ref.current;
|
|
12
|
+
if (element && mount) {
|
|
13
|
+
const possibleUnmount = mount(element);
|
|
14
|
+
if (possibleUnmount) {
|
|
15
|
+
unmount = possibleUnmount;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return () => {
|
|
19
|
+
if (element && unmount) {
|
|
20
|
+
unmount(element);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}, [ref, mount]);
|
|
24
|
+
return /* @__PURE__ */ jsx("div", { ref });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/components/Renderer.tsx
|
|
28
|
+
import { useCallback, useState } from "react";
|
|
3
29
|
|
|
4
30
|
// src/utils/createContextAndHook.ts
|
|
5
31
|
import React from "react";
|
|
@@ -14,7 +40,7 @@ var createContextAndHook = (displayName, options) => {
|
|
|
14
40
|
Ctx.displayName = displayName;
|
|
15
41
|
const useCtx = () => {
|
|
16
42
|
const ctx = React.useContext(Ctx);
|
|
17
|
-
assertCtxFn(ctx, `Component must be wrapped with
|
|
43
|
+
assertCtxFn(ctx, `Component must be wrapped with ${Ctx.displayName}`);
|
|
18
44
|
return ctx.value;
|
|
19
45
|
};
|
|
20
46
|
const useCtxWithoutGuarantee = () => {
|
|
@@ -24,42 +50,65 @@ var createContextAndHook = (displayName, options) => {
|
|
|
24
50
|
return [Ctx, useCtx, useCtxWithoutGuarantee];
|
|
25
51
|
};
|
|
26
52
|
|
|
27
|
-
// src/context/
|
|
28
|
-
import { jsx } from "react/jsx-runtime";
|
|
29
|
-
var [RendererContext, useRendererContext] = createContextAndHook("RendererContext");
|
|
53
|
+
// src/context/RendererContext.tsx
|
|
54
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
55
|
+
var [RendererContext, useRendererContext, useUnsafeRendererContext] = createContextAndHook("RendererContext");
|
|
30
56
|
var RendererProvider = (props) => {
|
|
31
|
-
return /* @__PURE__ */
|
|
57
|
+
return /* @__PURE__ */ jsx2(RendererContext.Provider, { value: { value: props.value }, children: props.children });
|
|
32
58
|
};
|
|
33
59
|
|
|
34
|
-
// src/components/
|
|
35
|
-
import
|
|
36
|
-
import { jsx as
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
// src/components/Renderer.tsx
|
|
61
|
+
import { createPortal } from "react-dom";
|
|
62
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
63
|
+
var Renderer = (props) => {
|
|
64
|
+
const { children } = props;
|
|
65
|
+
const [mountedElements, setMountedElements] = useState(/* @__PURE__ */ new Map());
|
|
66
|
+
const mountElement = useCallback(
|
|
67
|
+
(el, mountedElement) => {
|
|
68
|
+
setMountedElements((prev) => {
|
|
69
|
+
const newMountedElements = new Map(prev);
|
|
70
|
+
newMountedElements.set(el, mountedElement);
|
|
71
|
+
return newMountedElements;
|
|
72
|
+
});
|
|
73
|
+
return () => {
|
|
74
|
+
setMountedElements((prev) => {
|
|
75
|
+
const newMountedElements = new Map(prev);
|
|
76
|
+
newMountedElements.delete(el);
|
|
77
|
+
return newMountedElements;
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
[setMountedElements]
|
|
82
|
+
);
|
|
83
|
+
return /* @__PURE__ */ jsxs(RendererProvider, { value: { mountElement }, children: [
|
|
84
|
+
[...mountedElements].map(([element, mountedElement]) => {
|
|
85
|
+
return createPortal(mountedElement, element);
|
|
86
|
+
}),
|
|
87
|
+
children
|
|
88
|
+
] });
|
|
89
|
+
};
|
|
90
|
+
var withRenderer = (WrappedComponent) => {
|
|
91
|
+
const HOC = (props) => {
|
|
92
|
+
return /* @__PURE__ */ jsx3(Renderer, { children: /* @__PURE__ */ jsx3(WrappedComponent, { ...props }) });
|
|
93
|
+
};
|
|
94
|
+
HOC.displayName = `WithRenderer(${WrappedComponent.displayName || WrappedComponent.name || "Component"})`;
|
|
95
|
+
return HOC;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/context/NovuUIContext.tsx
|
|
99
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
100
|
+
var [NovuUIContext, useNovuUIContext, useUnsafeNovuUIContext] = createContextAndHook("NovuUIContext");
|
|
101
|
+
var NovuUIProvider = (props) => {
|
|
102
|
+
return /* @__PURE__ */ jsx4(NovuUIContext.Provider, { value: { value: props.value }, children: props.children });
|
|
103
|
+
};
|
|
56
104
|
|
|
57
105
|
// src/components/Bell.tsx
|
|
58
|
-
import { jsx as
|
|
59
|
-
var
|
|
106
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
107
|
+
var _Bell = React2.memo((props) => {
|
|
60
108
|
const { renderBell } = props;
|
|
61
|
-
const { novuUI
|
|
62
|
-
const
|
|
109
|
+
const { novuUI } = useNovuUIContext();
|
|
110
|
+
const { mountElement } = useRendererContext();
|
|
111
|
+
const mount = React2.useCallback(
|
|
63
112
|
(element) => {
|
|
64
113
|
return novuUI.mountComponent({
|
|
65
114
|
name: "Bell",
|
|
@@ -69,56 +118,70 @@ var Bell = React3.memo((props) => {
|
|
|
69
118
|
},
|
|
70
119
|
[renderBell]
|
|
71
120
|
);
|
|
72
|
-
return /* @__PURE__ */
|
|
121
|
+
return /* @__PURE__ */ jsx5(Mounter, { mount });
|
|
73
122
|
});
|
|
123
|
+
var Bell = withRenderer(_Bell);
|
|
74
124
|
|
|
75
125
|
// src/components/Inbox.tsx
|
|
76
|
-
import
|
|
126
|
+
import React4, { useMemo as useMemo2 } from "react";
|
|
77
127
|
|
|
78
|
-
// src/
|
|
79
|
-
import {
|
|
80
|
-
import
|
|
81
|
-
import {
|
|
128
|
+
// src/hooks/NovuProvider.tsx
|
|
129
|
+
import { Novu } from "@novu/js";
|
|
130
|
+
import { createContext, useContext, useMemo } from "react";
|
|
131
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
132
|
+
var NovuContext = createContext(void 0);
|
|
133
|
+
var NovuProvider = ({
|
|
134
|
+
children,
|
|
135
|
+
applicationIdentifier,
|
|
136
|
+
subscriberId,
|
|
137
|
+
subscriberHash,
|
|
138
|
+
backendUrl,
|
|
139
|
+
socketUrl,
|
|
140
|
+
useCache
|
|
141
|
+
}) => {
|
|
142
|
+
const novu = useMemo(
|
|
143
|
+
() => new Novu({ applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache }),
|
|
144
|
+
[applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache]
|
|
145
|
+
);
|
|
146
|
+
return /* @__PURE__ */ jsx6(NovuContext.Provider, { value: novu, children });
|
|
147
|
+
};
|
|
148
|
+
var useNovu = () => {
|
|
149
|
+
const context = useContext(NovuContext);
|
|
150
|
+
if (!context) {
|
|
151
|
+
throw new Error("useNovu must be used within a <NovuProvider />");
|
|
152
|
+
}
|
|
153
|
+
return context;
|
|
154
|
+
};
|
|
155
|
+
var useUnsafeNovu = () => {
|
|
156
|
+
const context = useContext(NovuContext);
|
|
157
|
+
return context;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// src/components/NovuUI.tsx
|
|
161
|
+
import { NovuUI as NovuUIClass } from "@novu/js/ui";
|
|
162
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
82
163
|
|
|
83
164
|
// src/hooks/internal/useDataRef.ts
|
|
84
|
-
import { useRef } from "react";
|
|
165
|
+
import { useRef as useRef2 } from "react";
|
|
85
166
|
var useDataRef = (data) => {
|
|
86
|
-
const ref =
|
|
167
|
+
const ref = useRef2(data);
|
|
87
168
|
ref.current = data;
|
|
88
169
|
return ref;
|
|
89
170
|
};
|
|
90
171
|
|
|
91
|
-
// src/components/
|
|
92
|
-
import {
|
|
93
|
-
var
|
|
172
|
+
// src/components/NovuUI.tsx
|
|
173
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
174
|
+
var NovuUI = ({ options, novu, children }) => {
|
|
94
175
|
const optionsRef = useDataRef({ ...options, novu });
|
|
95
|
-
const [novuUI, setNovuUI] =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
(el, mountedElement) => {
|
|
99
|
-
setMountedElements((prev) => {
|
|
100
|
-
const newMountedElements = new Map(prev);
|
|
101
|
-
newMountedElements.set(el, mountedElement);
|
|
102
|
-
return newMountedElements;
|
|
103
|
-
});
|
|
104
|
-
return () => {
|
|
105
|
-
setMountedElements((prev) => {
|
|
106
|
-
const newMountedElements = new Map(prev);
|
|
107
|
-
newMountedElements.delete(el);
|
|
108
|
-
return newMountedElements;
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
[setMountedElements]
|
|
113
|
-
);
|
|
114
|
-
useEffect(() => {
|
|
115
|
-
const novu2 = new NovuUI(optionsRef.current);
|
|
176
|
+
const [novuUI, setNovuUI] = useState2();
|
|
177
|
+
useEffect2(() => {
|
|
178
|
+
const novu2 = new NovuUIClass(optionsRef.current);
|
|
116
179
|
setNovuUI(novu2);
|
|
117
180
|
return () => {
|
|
118
181
|
novu2.unmount();
|
|
119
182
|
};
|
|
120
183
|
}, []);
|
|
121
|
-
|
|
184
|
+
useEffect2(() => {
|
|
122
185
|
if (!novuUI) {
|
|
123
186
|
return;
|
|
124
187
|
}
|
|
@@ -127,25 +190,20 @@ var Renderer = ({ options, novu, children }) => {
|
|
|
127
190
|
novuUI.updateTabs(options.tabs);
|
|
128
191
|
novuUI.updateOptions(options.options);
|
|
129
192
|
novuUI.updateRouterPush(options.routerPush);
|
|
130
|
-
novuUI.updatePreferencesFilter(options.preferencesFilter);
|
|
131
193
|
}, [options]);
|
|
132
194
|
if (!novuUI) {
|
|
133
195
|
return null;
|
|
134
196
|
}
|
|
135
|
-
return /* @__PURE__ */
|
|
136
|
-
[...mountedElements].map(([element, mountedElement]) => {
|
|
137
|
-
return ReactDOM.createPortal(mountedElement, element);
|
|
138
|
-
}),
|
|
139
|
-
children
|
|
140
|
-
] });
|
|
197
|
+
return /* @__PURE__ */ jsx7(NovuUIProvider, { value: { novuUI }, children });
|
|
141
198
|
};
|
|
142
199
|
|
|
143
200
|
// src/components/Inbox.tsx
|
|
144
|
-
import { jsx as
|
|
145
|
-
var
|
|
201
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
202
|
+
var _DefaultInbox = (props) => {
|
|
146
203
|
const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } = props;
|
|
147
|
-
const { novuUI
|
|
148
|
-
const
|
|
204
|
+
const { novuUI } = useNovuUIContext();
|
|
205
|
+
const { mountElement } = useRendererContext();
|
|
206
|
+
const mount = React4.useCallback(
|
|
149
207
|
(element) => {
|
|
150
208
|
return novuUI.mountComponent({
|
|
151
209
|
name: "Inbox",
|
|
@@ -162,15 +220,16 @@ var DefaultInbox = (props) => {
|
|
|
162
220
|
},
|
|
163
221
|
[open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
|
|
164
222
|
);
|
|
165
|
-
return /* @__PURE__ */
|
|
223
|
+
return /* @__PURE__ */ jsx8(Mounter, { mount });
|
|
166
224
|
};
|
|
167
|
-
var
|
|
225
|
+
var DefaultInbox = withRenderer(_DefaultInbox);
|
|
226
|
+
var Inbox = React4.memo((props) => {
|
|
168
227
|
const { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl } = props;
|
|
169
228
|
const novu = useUnsafeNovu();
|
|
170
229
|
if (novu) {
|
|
171
|
-
return /* @__PURE__ */
|
|
230
|
+
return /* @__PURE__ */ jsx8(InboxChild, { ...props });
|
|
172
231
|
}
|
|
173
|
-
return /* @__PURE__ */
|
|
232
|
+
return /* @__PURE__ */ jsx8(
|
|
174
233
|
NovuProvider,
|
|
175
234
|
{
|
|
176
235
|
applicationIdentifier,
|
|
@@ -178,11 +237,11 @@ var Inbox = React5.memo((props) => {
|
|
|
178
237
|
subscriberHash,
|
|
179
238
|
backendUrl,
|
|
180
239
|
socketUrl,
|
|
181
|
-
children: /* @__PURE__ */
|
|
240
|
+
children: /* @__PURE__ */ jsx8(InboxChild, { ...props })
|
|
182
241
|
}
|
|
183
242
|
);
|
|
184
243
|
});
|
|
185
|
-
var InboxChild =
|
|
244
|
+
var InboxChild = React4.memo((props) => {
|
|
186
245
|
const {
|
|
187
246
|
localization,
|
|
188
247
|
appearance,
|
|
@@ -196,7 +255,7 @@ var InboxChild = React5.memo((props) => {
|
|
|
196
255
|
socketUrl
|
|
197
256
|
} = props;
|
|
198
257
|
const novu = useNovu();
|
|
199
|
-
const options =
|
|
258
|
+
const options = useMemo2(() => {
|
|
200
259
|
return {
|
|
201
260
|
localization,
|
|
202
261
|
appearance,
|
|
@@ -217,10 +276,10 @@ var InboxChild = React5.memo((props) => {
|
|
|
217
276
|
socketUrl
|
|
218
277
|
]);
|
|
219
278
|
if (isWithChildrenProps(props)) {
|
|
220
|
-
return /* @__PURE__ */
|
|
279
|
+
return /* @__PURE__ */ jsx8(NovuUI, { options, novu, children: props.children });
|
|
221
280
|
}
|
|
222
281
|
const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } = props;
|
|
223
|
-
return /* @__PURE__ */
|
|
282
|
+
return /* @__PURE__ */ jsx8(NovuUI, { options, novu, children: /* @__PURE__ */ jsx8(
|
|
224
283
|
DefaultInbox,
|
|
225
284
|
{
|
|
226
285
|
open,
|
|
@@ -237,26 +296,27 @@ function isWithChildrenProps(props) {
|
|
|
237
296
|
}
|
|
238
297
|
|
|
239
298
|
// src/components/Preferences.tsx
|
|
240
|
-
import
|
|
241
|
-
import { jsx as
|
|
299
|
+
import React5 from "react";
|
|
300
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
242
301
|
var Preferences = () => {
|
|
243
|
-
const { novuUI } =
|
|
244
|
-
const mount =
|
|
302
|
+
const { novuUI } = useNovuUIContext();
|
|
303
|
+
const mount = React5.useCallback((element) => {
|
|
245
304
|
return novuUI.mountComponent({
|
|
246
305
|
name: "Preferences",
|
|
247
306
|
element
|
|
248
307
|
});
|
|
249
308
|
}, []);
|
|
250
|
-
return /* @__PURE__ */
|
|
309
|
+
return /* @__PURE__ */ jsx9(Mounter, { mount });
|
|
251
310
|
};
|
|
252
311
|
|
|
253
312
|
// src/components/Notifications.tsx
|
|
254
|
-
import
|
|
255
|
-
import { jsx as
|
|
256
|
-
var
|
|
313
|
+
import React6 from "react";
|
|
314
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
315
|
+
var _Notifications = React6.memo((props) => {
|
|
257
316
|
const { onNotificationClick, onPrimaryActionClick, renderNotification, onSecondaryActionClick } = props;
|
|
258
|
-
const { novuUI
|
|
259
|
-
const
|
|
317
|
+
const { novuUI } = useNovuUIContext();
|
|
318
|
+
const { mountElement } = useRendererContext();
|
|
319
|
+
const mount = React6.useCallback(
|
|
260
320
|
(element) => {
|
|
261
321
|
return novuUI.mountComponent({
|
|
262
322
|
name: "Notifications",
|
|
@@ -271,53 +331,57 @@ var Notifications = React7.memo((props) => {
|
|
|
271
331
|
},
|
|
272
332
|
[renderNotification, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
|
|
273
333
|
);
|
|
274
|
-
return /* @__PURE__ */
|
|
334
|
+
return /* @__PURE__ */ jsx10(Mounter, { mount });
|
|
275
335
|
});
|
|
336
|
+
var Notifications = withRenderer(_Notifications);
|
|
276
337
|
|
|
277
|
-
// src/
|
|
278
|
-
import
|
|
279
|
-
import {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
const
|
|
292
|
-
() =>
|
|
293
|
-
|
|
338
|
+
// src/components/InboxContent.tsx
|
|
339
|
+
import React7 from "react";
|
|
340
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
341
|
+
var _InboxContent = React7.memo((props) => {
|
|
342
|
+
const {
|
|
343
|
+
onNotificationClick,
|
|
344
|
+
onPrimaryActionClick,
|
|
345
|
+
renderNotification,
|
|
346
|
+
onSecondaryActionClick,
|
|
347
|
+
initialPage,
|
|
348
|
+
hideNav
|
|
349
|
+
} = props;
|
|
350
|
+
const { novuUI } = useNovuUIContext();
|
|
351
|
+
const { mountElement } = useRendererContext();
|
|
352
|
+
const mount = React7.useCallback(
|
|
353
|
+
(element) => {
|
|
354
|
+
return novuUI.mountComponent({
|
|
355
|
+
name: "InboxContent",
|
|
356
|
+
element,
|
|
357
|
+
props: {
|
|
358
|
+
renderNotification: renderNotification ? (el, notification) => mountElement(el, renderNotification(notification)) : void 0,
|
|
359
|
+
onNotificationClick,
|
|
360
|
+
onPrimaryActionClick,
|
|
361
|
+
onSecondaryActionClick,
|
|
362
|
+
initialPage,
|
|
363
|
+
hideNav
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
},
|
|
367
|
+
[renderNotification, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
|
|
294
368
|
);
|
|
295
|
-
return /* @__PURE__ */
|
|
296
|
-
};
|
|
297
|
-
var
|
|
298
|
-
const context = useContext(NovuContext);
|
|
299
|
-
if (!context) {
|
|
300
|
-
throw new Error("useNovu must be used within a <NovuProvider />");
|
|
301
|
-
}
|
|
302
|
-
return context;
|
|
303
|
-
};
|
|
304
|
-
var useUnsafeNovu = () => {
|
|
305
|
-
const context = useContext(NovuContext);
|
|
306
|
-
return context;
|
|
307
|
-
};
|
|
369
|
+
return /* @__PURE__ */ jsx11(Mounter, { mount });
|
|
370
|
+
});
|
|
371
|
+
var InboxContent = withRenderer(_InboxContent);
|
|
308
372
|
|
|
309
373
|
// src/hooks/useNotifications.ts
|
|
310
|
-
import { useState as
|
|
374
|
+
import { useState as useState3, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
311
375
|
import { isSameFilter } from "@novu/js";
|
|
312
376
|
var useNotifications = (props) => {
|
|
313
377
|
const { tags, read, archived = false, limit, onSuccess, onError } = props || {};
|
|
314
|
-
const filterRef =
|
|
378
|
+
const filterRef = useRef3(void 0);
|
|
315
379
|
const { notifications, on, off } = useNovu();
|
|
316
|
-
const [data, setData] =
|
|
317
|
-
const [error, setError] =
|
|
318
|
-
const [isLoading, setIsLoading] =
|
|
319
|
-
const [isFetching, setIsFetching] =
|
|
320
|
-
const [hasMore, setHasMore] =
|
|
380
|
+
const [data, setData] = useState3();
|
|
381
|
+
const [error, setError] = useState3();
|
|
382
|
+
const [isLoading, setIsLoading] = useState3(true);
|
|
383
|
+
const [isFetching, setIsFetching] = useState3(false);
|
|
384
|
+
const [hasMore, setHasMore] = useState3(false);
|
|
321
385
|
const length = data?.length;
|
|
322
386
|
const after = length ? data[length - 1].id : void 0;
|
|
323
387
|
const sync = (event) => {
|
|
@@ -327,13 +391,13 @@ var useNotifications = (props) => {
|
|
|
327
391
|
setData(event.data.notifications);
|
|
328
392
|
setHasMore(event.data.hasMore);
|
|
329
393
|
};
|
|
330
|
-
|
|
394
|
+
useEffect3(() => {
|
|
331
395
|
on("notifications.list.updated", sync);
|
|
332
396
|
return () => {
|
|
333
397
|
off("notifications.list.updated", sync);
|
|
334
398
|
};
|
|
335
399
|
}, []);
|
|
336
|
-
|
|
400
|
+
useEffect3(() => {
|
|
337
401
|
const newFilter = { tags, read, archived };
|
|
338
402
|
if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {
|
|
339
403
|
return;
|
|
@@ -399,21 +463,21 @@ var useNotifications = (props) => {
|
|
|
399
463
|
};
|
|
400
464
|
|
|
401
465
|
// src/hooks/usePreferences.ts
|
|
402
|
-
import { useEffect as
|
|
466
|
+
import { useEffect as useEffect4, useState as useState4 } from "react";
|
|
403
467
|
var usePreferences = (props) => {
|
|
404
468
|
const { onSuccess, onError } = props || {};
|
|
405
|
-
const [data, setData] =
|
|
469
|
+
const [data, setData] = useState4();
|
|
406
470
|
const { preferences, on, off } = useNovu();
|
|
407
|
-
const [error, setError] =
|
|
408
|
-
const [isLoading, setIsLoading] =
|
|
409
|
-
const [isFetching, setIsFetching] =
|
|
471
|
+
const [error, setError] = useState4();
|
|
472
|
+
const [isLoading, setIsLoading] = useState4(true);
|
|
473
|
+
const [isFetching, setIsFetching] = useState4(false);
|
|
410
474
|
const sync = (event) => {
|
|
411
475
|
if (!event.data) {
|
|
412
476
|
return;
|
|
413
477
|
}
|
|
414
478
|
setData(event.data);
|
|
415
479
|
};
|
|
416
|
-
|
|
480
|
+
useEffect4(() => {
|
|
417
481
|
fetchPreferences();
|
|
418
482
|
on("preferences.list.updated", sync);
|
|
419
483
|
on("preferences.list.pending", sync);
|
|
@@ -450,11 +514,11 @@ var usePreferences = (props) => {
|
|
|
450
514
|
};
|
|
451
515
|
|
|
452
516
|
// src/hooks/useCounts.ts
|
|
453
|
-
import { useEffect as
|
|
517
|
+
import { useEffect as useEffect7, useState as useState6 } from "react";
|
|
454
518
|
import { areTagsEqual } from "@novu/js";
|
|
455
519
|
|
|
456
520
|
// src/hooks/internal/useWebsocketEvent.ts
|
|
457
|
-
import { useEffect as
|
|
521
|
+
import { useEffect as useEffect6 } from "react";
|
|
458
522
|
|
|
459
523
|
// src/utils/requestLock.ts
|
|
460
524
|
function requestLock(id, cb) {
|
|
@@ -481,18 +545,18 @@ function requestLock(id, cb) {
|
|
|
481
545
|
}
|
|
482
546
|
|
|
483
547
|
// src/hooks/internal/useBrowserTabsChannel.ts
|
|
484
|
-
import { useEffect as
|
|
548
|
+
import { useEffect as useEffect5, useState as useState5 } from "react";
|
|
485
549
|
var useBrowserTabsChannel = ({
|
|
486
550
|
channelName,
|
|
487
551
|
onMessage
|
|
488
552
|
}) => {
|
|
489
|
-
const [tabsChannel] =
|
|
553
|
+
const [tabsChannel] = useState5(
|
|
490
554
|
typeof BroadcastChannel !== "undefined" ? new BroadcastChannel(channelName) : void 0
|
|
491
555
|
);
|
|
492
556
|
const postMessage = (data) => {
|
|
493
557
|
tabsChannel?.postMessage(data);
|
|
494
558
|
};
|
|
495
|
-
|
|
559
|
+
useEffect5(() => {
|
|
496
560
|
const listener = (event) => {
|
|
497
561
|
onMessage(event.data);
|
|
498
562
|
};
|
|
@@ -515,7 +579,7 @@ var useWebSocketEvent = ({
|
|
|
515
579
|
onMessage(data);
|
|
516
580
|
postMessage(data);
|
|
517
581
|
};
|
|
518
|
-
|
|
582
|
+
useEffect6(() => {
|
|
519
583
|
const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {
|
|
520
584
|
novu.on(webSocketEvent, updateReadCount);
|
|
521
585
|
});
|
|
@@ -530,10 +594,10 @@ var useWebSocketEvent = ({
|
|
|
530
594
|
var useCounts = (props) => {
|
|
531
595
|
const { filters, onSuccess, onError } = props;
|
|
532
596
|
const { notifications } = useNovu();
|
|
533
|
-
const [error, setError] =
|
|
534
|
-
const [counts, setCounts] =
|
|
535
|
-
const [isLoading, setIsLoading] =
|
|
536
|
-
const [isFetching, setIsFetching] =
|
|
597
|
+
const [error, setError] = useState6();
|
|
598
|
+
const [counts, setCounts] = useState6();
|
|
599
|
+
const [isLoading, setIsLoading] = useState6(true);
|
|
600
|
+
const [isFetching, setIsFetching] = useState6(false);
|
|
537
601
|
const sync = async (notification) => {
|
|
538
602
|
const existingCounts = counts ?? new Array(filters.length).fill(void 0);
|
|
539
603
|
let countFiltersToFetch = [];
|
|
@@ -583,7 +647,7 @@ var useCounts = (props) => {
|
|
|
583
647
|
sync();
|
|
584
648
|
}
|
|
585
649
|
});
|
|
586
|
-
|
|
650
|
+
useEffect7(() => {
|
|
587
651
|
setError(void 0);
|
|
588
652
|
setIsLoading(true);
|
|
589
653
|
setIsFetching(false);
|
|
@@ -597,7 +661,7 @@ var useCounts = (props) => {
|
|
|
597
661
|
export {
|
|
598
662
|
Bell,
|
|
599
663
|
Inbox,
|
|
600
|
-
|
|
664
|
+
InboxContent,
|
|
601
665
|
Notifications,
|
|
602
666
|
NovuProvider,
|
|
603
667
|
Preferences,
|