@novu/react 3.4.0 → 3.5.0-rc.2
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/cjs/hooks/NovuProvider.cjs +1 -1
- package/dist/cjs/hooks/useNotifications.cjs +8 -7
- package/dist/cjs/hooks/useNotifications.cjs.map +1 -1
- package/dist/cjs/hooks/useNotifications.d.cts +1 -0
- package/dist/esm/hooks/NovuProvider.js +1 -1
- package/dist/esm/hooks/useNotifications.d.ts +1 -0
- package/dist/esm/hooks/useNotifications.js +8 -7
- package/dist/esm/hooks/useNotifications.js.map +1 -1
- package/package.json +9 -9
|
@@ -29,7 +29,7 @@ module.exports = __toCommonJS(NovuProvider_exports);
|
|
|
29
29
|
var import_js = require("@novu/js");
|
|
30
30
|
var import_react = require("react");
|
|
31
31
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
-
var version = "3.
|
|
32
|
+
var version = "3.5.0-rc.2";
|
|
33
33
|
var name = "@novu/react";
|
|
34
34
|
var baseUserAgent = `${name}@${version}`;
|
|
35
35
|
var NovuContext = (0, import_react.createContext)(void 0);
|
|
@@ -27,7 +27,7 @@ var import_react = require("react");
|
|
|
27
27
|
var import_js = require("@novu/js");
|
|
28
28
|
var import_NovuProvider = require("./NovuProvider.cjs");
|
|
29
29
|
var useNotifications = (props) => {
|
|
30
|
-
const { tags, read, archived = false, snoozed = false, limit, onSuccess, onError } = props || {};
|
|
30
|
+
const { tags, data: dataFilter, read, archived = false, snoozed = false, limit, onSuccess, onError } = props || {};
|
|
31
31
|
const filterRef = (0, import_react.useRef)(void 0);
|
|
32
32
|
const { notifications, on } = (0, import_NovuProvider.useNovu)();
|
|
33
33
|
const [data, setData] = (0, import_react.useState)();
|
|
@@ -51,14 +51,14 @@ var useNotifications = (props) => {
|
|
|
51
51
|
};
|
|
52
52
|
}, []);
|
|
53
53
|
(0, import_react.useEffect)(() => {
|
|
54
|
-
const newFilter = { tags, read, archived, snoozed };
|
|
54
|
+
const newFilter = { tags, data: dataFilter, read, archived, snoozed };
|
|
55
55
|
if (filterRef.current && (0, import_js.isSameFilter)(filterRef.current, newFilter)) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
notifications.clearCache({ filter: filterRef.current });
|
|
59
59
|
filterRef.current = newFilter;
|
|
60
60
|
fetchNotifications({ refetch: true });
|
|
61
|
-
}, [tags, read, archived, snoozed]);
|
|
61
|
+
}, [tags, dataFilter, read, archived, snoozed]);
|
|
62
62
|
const fetchNotifications = async (options) => {
|
|
63
63
|
if (options == null ? void 0 : options.refetch) {
|
|
64
64
|
setError(void 0);
|
|
@@ -68,6 +68,7 @@ var useNotifications = (props) => {
|
|
|
68
68
|
setIsFetching(true);
|
|
69
69
|
const response = await notifications.list({
|
|
70
70
|
tags,
|
|
71
|
+
data: dataFilter,
|
|
71
72
|
read,
|
|
72
73
|
archived,
|
|
73
74
|
snoozed,
|
|
@@ -86,7 +87,7 @@ var useNotifications = (props) => {
|
|
|
86
87
|
setIsFetching(false);
|
|
87
88
|
};
|
|
88
89
|
const refetch = () => {
|
|
89
|
-
notifications.clearCache({ filter: { tags, read, archived, snoozed } });
|
|
90
|
+
notifications.clearCache({ filter: { tags, read, archived, snoozed, data: dataFilter } });
|
|
90
91
|
return fetchNotifications({ refetch: true });
|
|
91
92
|
};
|
|
92
93
|
const fetchMore = async () => {
|
|
@@ -94,13 +95,13 @@ var useNotifications = (props) => {
|
|
|
94
95
|
return fetchNotifications();
|
|
95
96
|
};
|
|
96
97
|
const readAll = async () => {
|
|
97
|
-
return await notifications.readAll({ tags });
|
|
98
|
+
return await notifications.readAll({ tags, data: dataFilter });
|
|
98
99
|
};
|
|
99
100
|
const archiveAll = async () => {
|
|
100
|
-
return await notifications.archiveAll({ tags });
|
|
101
|
+
return await notifications.archiveAll({ tags, data: dataFilter });
|
|
101
102
|
};
|
|
102
103
|
const archiveAllRead = async () => {
|
|
103
|
-
return await notifications.archiveAllRead({ tags });
|
|
104
|
+
return await notifications.archiveAllRead({ tags, data: dataFilter });
|
|
104
105
|
};
|
|
105
106
|
return {
|
|
106
107
|
readAll,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/useNotifications.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\nimport { ListNotificationsResponse, Notification, NovuError, isSameFilter, NotificationFilter } from '@novu/js';\nimport { useNovu } from './NovuProvider';\n\nexport type UseNotificationsProps = {\n tags?: string[];\n read?: boolean;\n archived?: boolean;\n snoozed?: boolean;\n limit?: number;\n onSuccess?: (data: Notification[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UseNotificationsResult = {\n notifications?: Notification[];\n error?: NovuError;\n isLoading: boolean;\n isFetching: boolean;\n hasMore: boolean;\n readAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAllRead: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n refetch: () => Promise<void>;\n fetchMore: () => Promise<void>;\n};\n\nexport const useNotifications = (props?: UseNotificationsProps): UseNotificationsResult => {\n const { tags, read, archived = false, snoozed = false, limit, onSuccess, onError } = props || {};\n const filterRef = useRef<NotificationFilter | undefined>(undefined);\n const { notifications, on } = useNovu();\n const [data, setData] = useState<Array<Notification>>();\n const [error, setError] = useState<NovuError>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n const [hasMore, setHasMore] = useState(false);\n const length = data?.length;\n const after = length ? data[length - 1].id : undefined;\n\n const sync = (event: { data?: ListNotificationsResponse }) => {\n if (!event.data || (filterRef.current && !isSameFilter(filterRef.current, event.data.filter))) {\n return;\n }\n setData(event.data.notifications);\n setHasMore(event.data.hasMore);\n };\n\n useEffect(() => {\n const cleanup = on('notifications.list.updated', sync);\n\n return () => {\n cleanup();\n };\n }, []);\n\n useEffect(() => {\n const newFilter = { tags, read, archived, snoozed };\n if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {\n return;\n }\n notifications.clearCache({ filter: filterRef.current });\n filterRef.current = newFilter;\n\n fetchNotifications({ refetch: true });\n }, [tags, read, archived, snoozed]);\n\n const fetchNotifications = async (options?: { refetch: boolean }) => {\n if (options?.refetch) {\n setError(undefined);\n setIsLoading(true);\n setIsFetching(false);\n }\n setIsFetching(true);\n const response = await notifications.list({\n tags,\n read,\n archived,\n snoozed,\n limit,\n after: options?.refetch ? undefined : after,\n });\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else {\n onSuccess?.(response.data!.notifications);\n setData(response.data!.notifications);\n setHasMore(response.data!.hasMore);\n }\n setIsLoading(false);\n setIsFetching(false);\n };\n\n const refetch = () => {\n notifications.clearCache({ filter: { tags, read, archived, snoozed } });\n\n return fetchNotifications({ refetch: true });\n };\n\n const fetchMore = async () => {\n if (!hasMore || isFetching) return;\n\n return fetchNotifications();\n };\n\n const readAll = async () => {\n return await notifications.readAll({ tags });\n };\n\n const archiveAll = async () => {\n return await notifications.archiveAll({ tags });\n };\n\n const archiveAllRead = async () => {\n return await notifications.archiveAllRead({ tags });\n };\n\n return {\n readAll,\n archiveAll,\n archiveAllRead,\n notifications: data,\n error,\n isLoading,\n isFetching,\n refetch,\n fetchMore,\n hasMore,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4C;AAC5C,gBAAqG;AACrG,0BAAwB;
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useNotifications.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\nimport { ListNotificationsResponse, Notification, NovuError, isSameFilter, NotificationFilter } from '@novu/js';\nimport { useNovu } from './NovuProvider';\n\nexport type UseNotificationsProps = {\n tags?: string[];\n data?: Record<string, unknown>;\n read?: boolean;\n archived?: boolean;\n snoozed?: boolean;\n limit?: number;\n onSuccess?: (data: Notification[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UseNotificationsResult = {\n notifications?: Notification[];\n error?: NovuError;\n isLoading: boolean;\n isFetching: boolean;\n hasMore: boolean;\n readAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAllRead: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n refetch: () => Promise<void>;\n fetchMore: () => Promise<void>;\n};\n\nexport const useNotifications = (props?: UseNotificationsProps): UseNotificationsResult => {\n const { tags, data: dataFilter, read, archived = false, snoozed = false, limit, onSuccess, onError } = props || {};\n const filterRef = useRef<NotificationFilter | undefined>(undefined);\n const { notifications, on } = useNovu();\n const [data, setData] = useState<Array<Notification>>();\n const [error, setError] = useState<NovuError>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n const [hasMore, setHasMore] = useState(false);\n const length = data?.length;\n const after = length ? data[length - 1].id : undefined;\n\n const sync = (event: { data?: ListNotificationsResponse }) => {\n if (!event.data || (filterRef.current && !isSameFilter(filterRef.current, event.data.filter))) {\n return;\n }\n setData(event.data.notifications);\n setHasMore(event.data.hasMore);\n };\n\n useEffect(() => {\n const cleanup = on('notifications.list.updated', sync);\n\n return () => {\n cleanup();\n };\n }, []);\n\n useEffect(() => {\n const newFilter = { tags, data: dataFilter, read, archived, snoozed };\n if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {\n return;\n }\n notifications.clearCache({ filter: filterRef.current });\n filterRef.current = newFilter;\n\n fetchNotifications({ refetch: true });\n }, [tags, dataFilter, read, archived, snoozed]);\n\n const fetchNotifications = async (options?: { refetch: boolean }) => {\n if (options?.refetch) {\n setError(undefined);\n setIsLoading(true);\n setIsFetching(false);\n }\n setIsFetching(true);\n const response = await notifications.list({\n tags,\n data: dataFilter,\n read,\n archived,\n snoozed,\n limit,\n after: options?.refetch ? undefined : after,\n });\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else {\n onSuccess?.(response.data!.notifications);\n setData(response.data!.notifications);\n setHasMore(response.data!.hasMore);\n }\n setIsLoading(false);\n setIsFetching(false);\n };\n\n const refetch = () => {\n notifications.clearCache({ filter: { tags, read, archived, snoozed, data: dataFilter } });\n\n return fetchNotifications({ refetch: true });\n };\n\n const fetchMore = async () => {\n if (!hasMore || isFetching) return;\n\n return fetchNotifications();\n };\n\n const readAll = async () => {\n return await notifications.readAll({ tags, data: dataFilter });\n };\n\n const archiveAll = async () => {\n return await notifications.archiveAll({ tags, data: dataFilter });\n };\n\n const archiveAllRead = async () => {\n return await notifications.archiveAllRead({ tags, data: dataFilter });\n };\n\n return {\n readAll,\n archiveAll,\n archiveAllRead,\n notifications: data,\n error,\n isLoading,\n isFetching,\n refetch,\n fetchMore,\n hasMore,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4C;AAC5C,gBAAqG;AACrG,0BAAwB;AAmCjB,IAAM,mBAAmB,CAAC,UAA0D;AACzF,QAAM,EAAE,MAAM,MAAM,YAAY,MAAM,WAAW,OAAO,UAAU,OAAO,OAAO,WAAW,QAAQ,IAAI,SAAS,CAAC;AACjH,QAAM,gBAAY,qBAAuC,MAAS;AAClE,QAAM,EAAE,eAAe,GAAG,QAAI,6BAAQ;AACtC,QAAM,CAAC,MAAM,OAAO,QAAI,uBAA8B;AACtD,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAoB;AAC9C,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,IAAI;AAC/C,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,KAAK;AAClD,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,KAAK;AAC5C,QAAM,SAAS,6BAAM;AACrB,QAAM,QAAQ,SAAS,KAAK,SAAS,CAAC,EAAE,KAAK;AAE7C,QAAM,OAAO,CAAC,UAAgD;AAC5D,QAAI,CAAC,MAAM,QAAS,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M,WAAW,EAAE,CAAC;AAExF,WAAO,mBAAmB,EAAE,SAAS,KAAK,CAAC;AAAA,EAC7C;AAEA,QAAM,YAAY,YAAY;AAC5B,QAAI,CAAC,WAAW,WAAY;AAE5B,WAAO,mBAAmB;AAAA,EAC5B;AAEA,QAAM,UAAU,YAAY;AAC1B,WAAO,MAAM,cAAc,QAAQ,EAAE,MAAM,MAAM,WAAW,CAAC;AAAA,EAC/D;AAEA,QAAM,aAAa,YAAY;AAC7B,WAAO,MAAM,cAAc,WAAW,EAAE,MAAM,MAAM,WAAW,CAAC;AAAA,EAClE;AAEA,QAAM,iBAAiB,YAAY;AACjC,WAAO,MAAM,cAAc,eAAe,EAAE,MAAM,MAAM,WAAW,CAAC;AAAA,EACtE;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Novu } from "@novu/js";
|
|
3
3
|
import { createContext, useContext, useMemo } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
var version = "3.
|
|
5
|
+
var version = "3.5.0-rc.2";
|
|
6
6
|
var name = "@novu/react";
|
|
7
7
|
var baseUserAgent = `${name}@${version}`;
|
|
8
8
|
var NovuContext = createContext(void 0);
|
|
@@ -3,7 +3,7 @@ import { useState, useEffect, useRef } from "react";
|
|
|
3
3
|
import { isSameFilter } from "@novu/js";
|
|
4
4
|
import { useNovu } from "./NovuProvider.js";
|
|
5
5
|
var useNotifications = (props) => {
|
|
6
|
-
const { tags, read, archived = false, snoozed = false, limit, onSuccess, onError } = props || {};
|
|
6
|
+
const { tags, data: dataFilter, read, archived = false, snoozed = false, limit, onSuccess, onError } = props || {};
|
|
7
7
|
const filterRef = useRef(void 0);
|
|
8
8
|
const { notifications, on } = useNovu();
|
|
9
9
|
const [data, setData] = useState();
|
|
@@ -27,14 +27,14 @@ var useNotifications = (props) => {
|
|
|
27
27
|
};
|
|
28
28
|
}, []);
|
|
29
29
|
useEffect(() => {
|
|
30
|
-
const newFilter = { tags, read, archived, snoozed };
|
|
30
|
+
const newFilter = { tags, data: dataFilter, read, archived, snoozed };
|
|
31
31
|
if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
notifications.clearCache({ filter: filterRef.current });
|
|
35
35
|
filterRef.current = newFilter;
|
|
36
36
|
fetchNotifications({ refetch: true });
|
|
37
|
-
}, [tags, read, archived, snoozed]);
|
|
37
|
+
}, [tags, dataFilter, read, archived, snoozed]);
|
|
38
38
|
const fetchNotifications = async (options) => {
|
|
39
39
|
if (options?.refetch) {
|
|
40
40
|
setError(void 0);
|
|
@@ -44,6 +44,7 @@ var useNotifications = (props) => {
|
|
|
44
44
|
setIsFetching(true);
|
|
45
45
|
const response = await notifications.list({
|
|
46
46
|
tags,
|
|
47
|
+
data: dataFilter,
|
|
47
48
|
read,
|
|
48
49
|
archived,
|
|
49
50
|
snoozed,
|
|
@@ -62,7 +63,7 @@ var useNotifications = (props) => {
|
|
|
62
63
|
setIsFetching(false);
|
|
63
64
|
};
|
|
64
65
|
const refetch = () => {
|
|
65
|
-
notifications.clearCache({ filter: { tags, read, archived, snoozed } });
|
|
66
|
+
notifications.clearCache({ filter: { tags, read, archived, snoozed, data: dataFilter } });
|
|
66
67
|
return fetchNotifications({ refetch: true });
|
|
67
68
|
};
|
|
68
69
|
const fetchMore = async () => {
|
|
@@ -70,13 +71,13 @@ var useNotifications = (props) => {
|
|
|
70
71
|
return fetchNotifications();
|
|
71
72
|
};
|
|
72
73
|
const readAll = async () => {
|
|
73
|
-
return await notifications.readAll({ tags });
|
|
74
|
+
return await notifications.readAll({ tags, data: dataFilter });
|
|
74
75
|
};
|
|
75
76
|
const archiveAll = async () => {
|
|
76
|
-
return await notifications.archiveAll({ tags });
|
|
77
|
+
return await notifications.archiveAll({ tags, data: dataFilter });
|
|
77
78
|
};
|
|
78
79
|
const archiveAllRead = async () => {
|
|
79
|
-
return await notifications.archiveAllRead({ tags });
|
|
80
|
+
return await notifications.archiveAllRead({ tags, data: dataFilter });
|
|
80
81
|
};
|
|
81
82
|
return {
|
|
82
83
|
readAll,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/useNotifications.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\nimport { ListNotificationsResponse, Notification, NovuError, isSameFilter, NotificationFilter } from '@novu/js';\nimport { useNovu } from './NovuProvider';\n\nexport type UseNotificationsProps = {\n tags?: string[];\n read?: boolean;\n archived?: boolean;\n snoozed?: boolean;\n limit?: number;\n onSuccess?: (data: Notification[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UseNotificationsResult = {\n notifications?: Notification[];\n error?: NovuError;\n isLoading: boolean;\n isFetching: boolean;\n hasMore: boolean;\n readAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAllRead: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n refetch: () => Promise<void>;\n fetchMore: () => Promise<void>;\n};\n\nexport const useNotifications = (props?: UseNotificationsProps): UseNotificationsResult => {\n const { tags, read, archived = false, snoozed = false, limit, onSuccess, onError } = props || {};\n const filterRef = useRef<NotificationFilter | undefined>(undefined);\n const { notifications, on } = useNovu();\n const [data, setData] = useState<Array<Notification>>();\n const [error, setError] = useState<NovuError>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n const [hasMore, setHasMore] = useState(false);\n const length = data?.length;\n const after = length ? data[length - 1].id : undefined;\n\n const sync = (event: { data?: ListNotificationsResponse }) => {\n if (!event.data || (filterRef.current && !isSameFilter(filterRef.current, event.data.filter))) {\n return;\n }\n setData(event.data.notifications);\n setHasMore(event.data.hasMore);\n };\n\n useEffect(() => {\n const cleanup = on('notifications.list.updated', sync);\n\n return () => {\n cleanup();\n };\n }, []);\n\n useEffect(() => {\n const newFilter = { tags, read, archived, snoozed };\n if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {\n return;\n }\n notifications.clearCache({ filter: filterRef.current });\n filterRef.current = newFilter;\n\n fetchNotifications({ refetch: true });\n }, [tags, read, archived, snoozed]);\n\n const fetchNotifications = async (options?: { refetch: boolean }) => {\n if (options?.refetch) {\n setError(undefined);\n setIsLoading(true);\n setIsFetching(false);\n }\n setIsFetching(true);\n const response = await notifications.list({\n tags,\n read,\n archived,\n snoozed,\n limit,\n after: options?.refetch ? undefined : after,\n });\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else {\n onSuccess?.(response.data!.notifications);\n setData(response.data!.notifications);\n setHasMore(response.data!.hasMore);\n }\n setIsLoading(false);\n setIsFetching(false);\n };\n\n const refetch = () => {\n notifications.clearCache({ filter: { tags, read, archived, snoozed } });\n\n return fetchNotifications({ refetch: true });\n };\n\n const fetchMore = async () => {\n if (!hasMore || isFetching) return;\n\n return fetchNotifications();\n };\n\n const readAll = async () => {\n return await notifications.readAll({ tags });\n };\n\n const archiveAll = async () => {\n return await notifications.archiveAll({ tags });\n };\n\n const archiveAllRead = async () => {\n return await notifications.archiveAllRead({ tags });\n };\n\n return {\n readAll,\n archiveAll,\n archiveAllRead,\n notifications: data,\n error,\n isLoading,\n isFetching,\n refetch,\n fetchMore,\n hasMore,\n };\n};\n"],"mappings":";AAAA,SAAS,UAAU,WAAW,cAAc;AAC5C,SAA6D,oBAAwC;AACrG,SAAS,eAAe;
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useNotifications.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\nimport { ListNotificationsResponse, Notification, NovuError, isSameFilter, NotificationFilter } from '@novu/js';\nimport { useNovu } from './NovuProvider';\n\nexport type UseNotificationsProps = {\n tags?: string[];\n data?: Record<string, unknown>;\n read?: boolean;\n archived?: boolean;\n snoozed?: boolean;\n limit?: number;\n onSuccess?: (data: Notification[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UseNotificationsResult = {\n notifications?: Notification[];\n error?: NovuError;\n isLoading: boolean;\n isFetching: boolean;\n hasMore: boolean;\n readAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAllRead: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n refetch: () => Promise<void>;\n fetchMore: () => Promise<void>;\n};\n\nexport const useNotifications = (props?: UseNotificationsProps): UseNotificationsResult => {\n const { tags, data: dataFilter, read, archived = false, snoozed = false, limit, onSuccess, onError } = props || {};\n const filterRef = useRef<NotificationFilter | undefined>(undefined);\n const { notifications, on } = useNovu();\n const [data, setData] = useState<Array<Notification>>();\n const [error, setError] = useState<NovuError>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n const [hasMore, setHasMore] = useState(false);\n const length = data?.length;\n const after = length ? data[length - 1].id : undefined;\n\n const sync = (event: { data?: ListNotificationsResponse }) => {\n if (!event.data || (filterRef.current && !isSameFilter(filterRef.current, event.data.filter))) {\n return;\n }\n setData(event.data.notifications);\n setHasMore(event.data.hasMore);\n };\n\n useEffect(() => {\n const cleanup = on('notifications.list.updated', sync);\n\n return () => {\n cleanup();\n };\n }, []);\n\n useEffect(() => {\n const newFilter = { tags, data: dataFilter, read, archived, snoozed };\n if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {\n return;\n }\n notifications.clearCache({ filter: filterRef.current });\n filterRef.current = newFilter;\n\n fetchNotifications({ refetch: true });\n }, [tags, dataFilter, read, archived, snoozed]);\n\n const fetchNotifications = async (options?: { refetch: boolean }) => {\n if (options?.refetch) {\n setError(undefined);\n setIsLoading(true);\n setIsFetching(false);\n }\n setIsFetching(true);\n const response = await notifications.list({\n tags,\n data: dataFilter,\n read,\n archived,\n snoozed,\n limit,\n after: options?.refetch ? undefined : after,\n });\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else {\n onSuccess?.(response.data!.notifications);\n setData(response.data!.notifications);\n setHasMore(response.data!.hasMore);\n }\n setIsLoading(false);\n setIsFetching(false);\n };\n\n const refetch = () => {\n notifications.clearCache({ filter: { tags, read, archived, snoozed, data: dataFilter } });\n\n return fetchNotifications({ refetch: true });\n };\n\n const fetchMore = async () => {\n if (!hasMore || isFetching) return;\n\n return fetchNotifications();\n };\n\n const readAll = async () => {\n return await notifications.readAll({ tags, data: dataFilter });\n };\n\n const archiveAll = async () => {\n return await notifications.archiveAll({ tags, data: dataFilter });\n };\n\n const archiveAllRead = async () => {\n return await notifications.archiveAllRead({ tags, data: dataFilter });\n };\n\n return {\n readAll,\n archiveAll,\n archiveAllRead,\n notifications: data,\n error,\n isLoading,\n isFetching,\n refetch,\n fetchMore,\n hasMore,\n };\n};\n"],"mappings":";AAAA,SAAS,UAAU,WAAW,cAAc;AAC5C,SAA6D,oBAAwC;AACrG,SAAS,eAAe;AAmCjB,IAAM,mBAAmB,CAAC,UAA0D;AACzF,QAAM,EAAE,MAAM,MAAM,YAAY,MAAM,WAAW,OAAO,UAAU,OAAO,OAAO,WAAW,QAAQ,IAAI,SAAS,CAAC;AACjH,QAAM,YAAY,OAAuC,MAAS;AAClE,QAAM,EAAE,eAAe,GAAG,IAAI,QAAQ;AACtC,QAAM,CAAC,MAAM,OAAO,IAAI,SAA8B;AACtD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAoB;AAC9C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,IAAI;AAC/C,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,KAAK;AAClD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAC5C,QAAM,SAAS,MAAM;AACrB,QAAM,QAAQ,SAAS,KAAK,SAAS,CAAC,EAAE,KAAK;A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;AACpB,kBAAc,WAAW,EAAE,QAAQ,EAAE,MAAM,MAAM,UAAU,SAAS,MAAM,WAAW,EAAE,CAAC;AAExF,WAAO,mBAAmB,EAAE,SAAS,KAAK,CAAC;AAAA,EAC7C;AAEA,QAAM,YAAY,YAAY;AAC5B,QAAI,CAAC,WAAW,WAAY;AAE5B,WAAO,mBAAmB;AAAA,EAC5B;AAEA,QAAM,UAAU,YAAY;AAC1B,WAAO,MAAM,cAAc,QAAQ,EAAE,MAAM,MAAM,WAAW,CAAC;AAAA,EAC/D;AAEA,QAAM,aAAa,YAAY;AAC7B,WAAO,MAAM,cAAc,WAAW,EAAE,MAAM,MAAM,WAAW,CAAC;AAAA,EAClE;AAEA,QAAM,iBAAiB,YAAY;AACjC,WAAO,MAAM,cAAc,eAAe,EAAE,MAAM,MAAM,WAAW,CAAC;AAAA,EACtE;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novu/react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0-rc.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/novuhq/novu",
|
|
@@ -79,12 +79,6 @@
|
|
|
79
79
|
"publishConfig": {
|
|
80
80
|
"access": "public"
|
|
81
81
|
},
|
|
82
|
-
"scripts": {
|
|
83
|
-
"build:watch": "tsup --watch",
|
|
84
|
-
"build": "tsup && pnpm run check-exports",
|
|
85
|
-
"lint": "eslint src",
|
|
86
|
-
"check-exports": "attw --pack ."
|
|
87
|
-
},
|
|
88
82
|
"browserslist": {
|
|
89
83
|
"production": [
|
|
90
84
|
">0.2%",
|
|
@@ -116,11 +110,17 @@
|
|
|
116
110
|
}
|
|
117
111
|
},
|
|
118
112
|
"dependencies": {
|
|
119
|
-
"@novu/js": "
|
|
113
|
+
"@novu/js": "3.5.0-rc.2"
|
|
120
114
|
},
|
|
121
115
|
"nx": {
|
|
122
116
|
"tags": [
|
|
123
117
|
"type:package"
|
|
124
118
|
]
|
|
119
|
+
},
|
|
120
|
+
"scripts": {
|
|
121
|
+
"build:watch": "tsup --watch",
|
|
122
|
+
"build": "tsup && pnpm run check-exports",
|
|
123
|
+
"lint": "eslint src",
|
|
124
|
+
"check-exports": "attw --pack ."
|
|
125
125
|
}
|
|
126
|
-
}
|
|
126
|
+
}
|