@novu/react 2.1.2 → 2.3.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/dist/client/index.d.mts +25 -6
- package/dist/client/index.d.ts +25 -6
- package/dist/client/index.js +232 -155
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +231 -154
- package/dist/client/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +3 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +1 -1
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/server/server.d.mts +5 -1
- package/dist/server/server.d.ts +5 -1
- package/dist/server/server.js +1 -1
- package/dist/server/server.js.map +1 -1
- package/dist/server/server.mjs +1 -1
- package/dist/server/server.mjs.map +1 -1
- 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 +18 -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
|
}
|
|
@@ -131,20 +194,16 @@ var Renderer = ({ options, novu, children }) => {
|
|
|
131
194
|
if (!novuUI) {
|
|
132
195
|
return null;
|
|
133
196
|
}
|
|
134
|
-
return /* @__PURE__ */
|
|
135
|
-
[...mountedElements].map(([element, mountedElement]) => {
|
|
136
|
-
return ReactDOM.createPortal(mountedElement, element);
|
|
137
|
-
}),
|
|
138
|
-
children
|
|
139
|
-
] });
|
|
197
|
+
return /* @__PURE__ */ jsx7(NovuUIProvider, { value: { novuUI }, children });
|
|
140
198
|
};
|
|
141
199
|
|
|
142
200
|
// src/components/Inbox.tsx
|
|
143
|
-
import { jsx as
|
|
144
|
-
var
|
|
201
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
202
|
+
var _DefaultInbox = (props) => {
|
|
145
203
|
const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } = props;
|
|
146
|
-
const { novuUI
|
|
147
|
-
const
|
|
204
|
+
const { novuUI } = useNovuUIContext();
|
|
205
|
+
const { mountElement } = useRendererContext();
|
|
206
|
+
const mount = React4.useCallback(
|
|
148
207
|
(element) => {
|
|
149
208
|
return novuUI.mountComponent({
|
|
150
209
|
name: "Inbox",
|
|
@@ -161,15 +220,16 @@ var DefaultInbox = (props) => {
|
|
|
161
220
|
},
|
|
162
221
|
[open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
|
|
163
222
|
);
|
|
164
|
-
return /* @__PURE__ */
|
|
223
|
+
return /* @__PURE__ */ jsx8(Mounter, { mount });
|
|
165
224
|
};
|
|
166
|
-
var
|
|
225
|
+
var DefaultInbox = withRenderer(_DefaultInbox);
|
|
226
|
+
var Inbox = React4.memo((props) => {
|
|
167
227
|
const { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl } = props;
|
|
168
228
|
const novu = useUnsafeNovu();
|
|
169
229
|
if (novu) {
|
|
170
|
-
return /* @__PURE__ */
|
|
230
|
+
return /* @__PURE__ */ jsx8(InboxChild, { ...props });
|
|
171
231
|
}
|
|
172
|
-
return /* @__PURE__ */
|
|
232
|
+
return /* @__PURE__ */ jsx8(
|
|
173
233
|
NovuProvider,
|
|
174
234
|
{
|
|
175
235
|
applicationIdentifier,
|
|
@@ -177,15 +237,16 @@ var Inbox = React5.memo((props) => {
|
|
|
177
237
|
subscriberHash,
|
|
178
238
|
backendUrl,
|
|
179
239
|
socketUrl,
|
|
180
|
-
children: /* @__PURE__ */
|
|
240
|
+
children: /* @__PURE__ */ jsx8(InboxChild, { ...props })
|
|
181
241
|
}
|
|
182
242
|
);
|
|
183
243
|
});
|
|
184
|
-
var InboxChild =
|
|
244
|
+
var InboxChild = React4.memo((props) => {
|
|
185
245
|
const {
|
|
186
246
|
localization,
|
|
187
247
|
appearance,
|
|
188
248
|
tabs,
|
|
249
|
+
preferencesFilter,
|
|
189
250
|
routerPush,
|
|
190
251
|
applicationIdentifier,
|
|
191
252
|
subscriberId,
|
|
@@ -194,20 +255,31 @@ var InboxChild = React5.memo((props) => {
|
|
|
194
255
|
socketUrl
|
|
195
256
|
} = props;
|
|
196
257
|
const novu = useNovu();
|
|
197
|
-
const options =
|
|
258
|
+
const options = useMemo2(() => {
|
|
198
259
|
return {
|
|
199
260
|
localization,
|
|
200
261
|
appearance,
|
|
201
262
|
tabs,
|
|
263
|
+
preferencesFilter,
|
|
202
264
|
routerPush,
|
|
203
265
|
options: { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl }
|
|
204
266
|
};
|
|
205
|
-
}, [
|
|
267
|
+
}, [
|
|
268
|
+
localization,
|
|
269
|
+
appearance,
|
|
270
|
+
tabs,
|
|
271
|
+
preferencesFilter,
|
|
272
|
+
applicationIdentifier,
|
|
273
|
+
subscriberId,
|
|
274
|
+
subscriberHash,
|
|
275
|
+
backendUrl,
|
|
276
|
+
socketUrl
|
|
277
|
+
]);
|
|
206
278
|
if (isWithChildrenProps(props)) {
|
|
207
|
-
return /* @__PURE__ */
|
|
279
|
+
return /* @__PURE__ */ jsx8(NovuUI, { options, novu, children: props.children });
|
|
208
280
|
}
|
|
209
281
|
const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } = props;
|
|
210
|
-
return /* @__PURE__ */
|
|
282
|
+
return /* @__PURE__ */ jsx8(NovuUI, { options, novu, children: /* @__PURE__ */ jsx8(
|
|
211
283
|
DefaultInbox,
|
|
212
284
|
{
|
|
213
285
|
open,
|
|
@@ -224,26 +296,27 @@ function isWithChildrenProps(props) {
|
|
|
224
296
|
}
|
|
225
297
|
|
|
226
298
|
// src/components/Preferences.tsx
|
|
227
|
-
import
|
|
228
|
-
import { jsx as
|
|
299
|
+
import React5 from "react";
|
|
300
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
229
301
|
var Preferences = () => {
|
|
230
|
-
const { novuUI } =
|
|
231
|
-
const mount =
|
|
302
|
+
const { novuUI } = useNovuUIContext();
|
|
303
|
+
const mount = React5.useCallback((element) => {
|
|
232
304
|
return novuUI.mountComponent({
|
|
233
305
|
name: "Preferences",
|
|
234
306
|
element
|
|
235
307
|
});
|
|
236
308
|
}, []);
|
|
237
|
-
return /* @__PURE__ */
|
|
309
|
+
return /* @__PURE__ */ jsx9(Mounter, { mount });
|
|
238
310
|
};
|
|
239
311
|
|
|
240
312
|
// src/components/Notifications.tsx
|
|
241
|
-
import
|
|
242
|
-
import { jsx as
|
|
243
|
-
var
|
|
313
|
+
import React6 from "react";
|
|
314
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
315
|
+
var _Notifications = React6.memo((props) => {
|
|
244
316
|
const { onNotificationClick, onPrimaryActionClick, renderNotification, onSecondaryActionClick } = props;
|
|
245
|
-
const { novuUI
|
|
246
|
-
const
|
|
317
|
+
const { novuUI } = useNovuUIContext();
|
|
318
|
+
const { mountElement } = useRendererContext();
|
|
319
|
+
const mount = React6.useCallback(
|
|
247
320
|
(element) => {
|
|
248
321
|
return novuUI.mountComponent({
|
|
249
322
|
name: "Notifications",
|
|
@@ -258,53 +331,57 @@ var Notifications = React7.memo((props) => {
|
|
|
258
331
|
},
|
|
259
332
|
[renderNotification, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
|
|
260
333
|
);
|
|
261
|
-
return /* @__PURE__ */
|
|
334
|
+
return /* @__PURE__ */ jsx10(Mounter, { mount });
|
|
262
335
|
});
|
|
336
|
+
var Notifications = withRenderer(_Notifications);
|
|
263
337
|
|
|
264
|
-
// src/
|
|
265
|
-
import
|
|
266
|
-
import {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
const
|
|
279
|
-
() =>
|
|
280
|
-
|
|
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]
|
|
281
368
|
);
|
|
282
|
-
return /* @__PURE__ */
|
|
283
|
-
};
|
|
284
|
-
var
|
|
285
|
-
const context = useContext(NovuContext);
|
|
286
|
-
if (!context) {
|
|
287
|
-
throw new Error("useNovu must be used within a <NovuProvider />");
|
|
288
|
-
}
|
|
289
|
-
return context;
|
|
290
|
-
};
|
|
291
|
-
var useUnsafeNovu = () => {
|
|
292
|
-
const context = useContext(NovuContext);
|
|
293
|
-
return context;
|
|
294
|
-
};
|
|
369
|
+
return /* @__PURE__ */ jsx11(Mounter, { mount });
|
|
370
|
+
});
|
|
371
|
+
var InboxContent = withRenderer(_InboxContent);
|
|
295
372
|
|
|
296
373
|
// src/hooks/useNotifications.ts
|
|
297
|
-
import { useState as
|
|
374
|
+
import { useState as useState3, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
298
375
|
import { isSameFilter } from "@novu/js";
|
|
299
376
|
var useNotifications = (props) => {
|
|
300
377
|
const { tags, read, archived = false, limit, onSuccess, onError } = props || {};
|
|
301
|
-
const filterRef =
|
|
378
|
+
const filterRef = useRef3(void 0);
|
|
302
379
|
const { notifications, on, off } = useNovu();
|
|
303
|
-
const [data, setData] =
|
|
304
|
-
const [error, setError] =
|
|
305
|
-
const [isLoading, setIsLoading] =
|
|
306
|
-
const [isFetching, setIsFetching] =
|
|
307
|
-
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);
|
|
308
385
|
const length = data?.length;
|
|
309
386
|
const after = length ? data[length - 1].id : void 0;
|
|
310
387
|
const sync = (event) => {
|
|
@@ -314,13 +391,13 @@ var useNotifications = (props) => {
|
|
|
314
391
|
setData(event.data.notifications);
|
|
315
392
|
setHasMore(event.data.hasMore);
|
|
316
393
|
};
|
|
317
|
-
|
|
394
|
+
useEffect3(() => {
|
|
318
395
|
on("notifications.list.updated", sync);
|
|
319
396
|
return () => {
|
|
320
397
|
off("notifications.list.updated", sync);
|
|
321
398
|
};
|
|
322
399
|
}, []);
|
|
323
|
-
|
|
400
|
+
useEffect3(() => {
|
|
324
401
|
const newFilter = { tags, read, archived };
|
|
325
402
|
if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {
|
|
326
403
|
return;
|
|
@@ -386,21 +463,21 @@ var useNotifications = (props) => {
|
|
|
386
463
|
};
|
|
387
464
|
|
|
388
465
|
// src/hooks/usePreferences.ts
|
|
389
|
-
import { useEffect as
|
|
466
|
+
import { useEffect as useEffect4, useState as useState4 } from "react";
|
|
390
467
|
var usePreferences = (props) => {
|
|
391
468
|
const { onSuccess, onError } = props || {};
|
|
392
|
-
const [data, setData] =
|
|
469
|
+
const [data, setData] = useState4();
|
|
393
470
|
const { preferences, on, off } = useNovu();
|
|
394
|
-
const [error, setError] =
|
|
395
|
-
const [isLoading, setIsLoading] =
|
|
396
|
-
const [isFetching, setIsFetching] =
|
|
471
|
+
const [error, setError] = useState4();
|
|
472
|
+
const [isLoading, setIsLoading] = useState4(true);
|
|
473
|
+
const [isFetching, setIsFetching] = useState4(false);
|
|
397
474
|
const sync = (event) => {
|
|
398
475
|
if (!event.data) {
|
|
399
476
|
return;
|
|
400
477
|
}
|
|
401
478
|
setData(event.data);
|
|
402
479
|
};
|
|
403
|
-
|
|
480
|
+
useEffect4(() => {
|
|
404
481
|
fetchPreferences();
|
|
405
482
|
on("preferences.list.updated", sync);
|
|
406
483
|
on("preferences.list.pending", sync);
|
|
@@ -413,7 +490,7 @@ var usePreferences = (props) => {
|
|
|
413
490
|
}, []);
|
|
414
491
|
const fetchPreferences = async () => {
|
|
415
492
|
setIsFetching(true);
|
|
416
|
-
const response = await preferences.list();
|
|
493
|
+
const response = await preferences.list(props?.filter);
|
|
417
494
|
if (response.error) {
|
|
418
495
|
setError(response.error);
|
|
419
496
|
onError?.(response.error);
|
|
@@ -437,11 +514,11 @@ var usePreferences = (props) => {
|
|
|
437
514
|
};
|
|
438
515
|
|
|
439
516
|
// src/hooks/useCounts.ts
|
|
440
|
-
import { useEffect as
|
|
517
|
+
import { useEffect as useEffect7, useState as useState6 } from "react";
|
|
441
518
|
import { areTagsEqual } from "@novu/js";
|
|
442
519
|
|
|
443
520
|
// src/hooks/internal/useWebsocketEvent.ts
|
|
444
|
-
import { useEffect as
|
|
521
|
+
import { useEffect as useEffect6 } from "react";
|
|
445
522
|
|
|
446
523
|
// src/utils/requestLock.ts
|
|
447
524
|
function requestLock(id, cb) {
|
|
@@ -468,18 +545,18 @@ function requestLock(id, cb) {
|
|
|
468
545
|
}
|
|
469
546
|
|
|
470
547
|
// src/hooks/internal/useBrowserTabsChannel.ts
|
|
471
|
-
import { useEffect as
|
|
548
|
+
import { useEffect as useEffect5, useState as useState5 } from "react";
|
|
472
549
|
var useBrowserTabsChannel = ({
|
|
473
550
|
channelName,
|
|
474
551
|
onMessage
|
|
475
552
|
}) => {
|
|
476
|
-
const [tabsChannel] =
|
|
553
|
+
const [tabsChannel] = useState5(
|
|
477
554
|
typeof BroadcastChannel !== "undefined" ? new BroadcastChannel(channelName) : void 0
|
|
478
555
|
);
|
|
479
556
|
const postMessage = (data) => {
|
|
480
557
|
tabsChannel?.postMessage(data);
|
|
481
558
|
};
|
|
482
|
-
|
|
559
|
+
useEffect5(() => {
|
|
483
560
|
const listener = (event) => {
|
|
484
561
|
onMessage(event.data);
|
|
485
562
|
};
|
|
@@ -502,7 +579,7 @@ var useWebSocketEvent = ({
|
|
|
502
579
|
onMessage(data);
|
|
503
580
|
postMessage(data);
|
|
504
581
|
};
|
|
505
|
-
|
|
582
|
+
useEffect6(() => {
|
|
506
583
|
const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {
|
|
507
584
|
novu.on(webSocketEvent, updateReadCount);
|
|
508
585
|
});
|
|
@@ -517,10 +594,10 @@ var useWebSocketEvent = ({
|
|
|
517
594
|
var useCounts = (props) => {
|
|
518
595
|
const { filters, onSuccess, onError } = props;
|
|
519
596
|
const { notifications } = useNovu();
|
|
520
|
-
const [error, setError] =
|
|
521
|
-
const [counts, setCounts] =
|
|
522
|
-
const [isLoading, setIsLoading] =
|
|
523
|
-
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);
|
|
524
601
|
const sync = async (notification) => {
|
|
525
602
|
const existingCounts = counts ?? new Array(filters.length).fill(void 0);
|
|
526
603
|
let countFiltersToFetch = [];
|
|
@@ -570,7 +647,7 @@ var useCounts = (props) => {
|
|
|
570
647
|
sync();
|
|
571
648
|
}
|
|
572
649
|
});
|
|
573
|
-
|
|
650
|
+
useEffect7(() => {
|
|
574
651
|
setError(void 0);
|
|
575
652
|
setIsLoading(true);
|
|
576
653
|
setIsFetching(false);
|
|
@@ -584,7 +661,7 @@ var useCounts = (props) => {
|
|
|
584
661
|
export {
|
|
585
662
|
Bell,
|
|
586
663
|
Inbox,
|
|
587
|
-
|
|
664
|
+
InboxContent,
|
|
588
665
|
Notifications,
|
|
589
666
|
NovuProvider,
|
|
590
667
|
Preferences,
|