@replyke/core 5.0.17 → 5.0.19
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/app-notifications/useAppNotificationsData.js +63 -49
- package/dist/cjs/hooks/app-notifications/useAppNotificationsData.js.map +1 -1
- package/dist/cjs/hooks/app-notifications/useFetchAppNotifications.js +51 -19
- package/dist/cjs/hooks/app-notifications/useFetchAppNotifications.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/esm/hooks/app-notifications/useAppNotificationsData.js +63 -49
- package/dist/esm/hooks/app-notifications/useAppNotificationsData.js.map +1 -1
- package/dist/esm/hooks/app-notifications/useFetchAppNotifications.js +52 -20
- package/dist/esm/hooks/app-notifications/useFetchAppNotifications.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -71,10 +71,12 @@ function useAppNotificationsData(_a) {
|
|
|
71
71
|
var _c = (0, react_1.useState)([]), appNotifications = _c[0], setAppNotifications = _c[1];
|
|
72
72
|
var _d = (0, react_1.useState)(0), unreadAppNotificationsCount = _d[0], setUnreadAppNotificationsCount = _d[1];
|
|
73
73
|
var _e = (0, react_1.useState)(1), page = _e[0], setPage = _e[1];
|
|
74
|
-
|
|
75
|
-
var _f = (0, react_1.useState)(true),
|
|
76
|
-
var
|
|
77
|
-
|
|
74
|
+
// Consolidate loading state management
|
|
75
|
+
var _f = (0, react_1.useState)(true), loading = _f[0], setLoading = _f[1];
|
|
76
|
+
var _g = (0, react_1.useState)(true), hasMore = _g[0], setHasMore = _g[1];
|
|
77
|
+
// Track initialization to prevent multiple initial loads
|
|
78
|
+
var initializedRef = (0, react_1.useRef)(false);
|
|
79
|
+
var requestInFlightRef = (0, react_1.useRef)(false);
|
|
78
80
|
var fetchAppNotifications = (0, useFetchAppNotifications_1.default)();
|
|
79
81
|
var countUnreadNotifications = (0, useCountUnreadNotifications_1.default)();
|
|
80
82
|
var markNotificationAsRead = (0, useMarkNotificationAsRead_1.default)();
|
|
@@ -83,46 +85,46 @@ function useAppNotificationsData(_a) {
|
|
|
83
85
|
return __generator(this, function (_a) {
|
|
84
86
|
switch (_a.label) {
|
|
85
87
|
case 0:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
// Prevent concurrent reset calls
|
|
89
|
+
if (requestInFlightRef.current)
|
|
90
|
+
return [2 /*return*/];
|
|
91
|
+
_a.label = 1;
|
|
92
|
+
case 1:
|
|
93
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
94
|
+
requestInFlightRef.current = true;
|
|
95
|
+
setLoading(true);
|
|
96
|
+
setHasMore(true);
|
|
91
97
|
setPage(1);
|
|
92
98
|
setAppNotifications([]);
|
|
93
99
|
return [4 /*yield*/, fetchAppNotifications({
|
|
94
100
|
page: 1,
|
|
95
101
|
limit: limit,
|
|
96
102
|
})];
|
|
97
|
-
case
|
|
103
|
+
case 2:
|
|
98
104
|
newAppNotifications = _a.sent();
|
|
99
105
|
if (newAppNotifications) {
|
|
100
106
|
completeNotifications = (0, addNotificationsMessages_1.default)(newAppNotifications, notificationTemplates);
|
|
101
107
|
setAppNotifications(completeNotifications);
|
|
102
|
-
|
|
103
|
-
hasMore.current = false;
|
|
104
|
-
setHasMoreState(false);
|
|
105
|
-
}
|
|
108
|
+
setHasMore(newAppNotifications.length >= limit);
|
|
106
109
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
err_1 = _a.sent();
|
|
110
|
-
(0, handleError_1.handleError)(err_1, "Failed to refesh notifications:");
|
|
111
|
-
return [3 /*break*/, 4];
|
|
110
|
+
initializedRef.current = true;
|
|
111
|
+
return [3 /*break*/, 5];
|
|
112
112
|
case 3:
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
err_1 = _a.sent();
|
|
114
|
+
(0, handleError_1.handleError)(err_1, "Failed to refresh notifications:");
|
|
115
|
+
return [3 /*break*/, 5];
|
|
116
|
+
case 4:
|
|
117
|
+
setLoading(false);
|
|
118
|
+
requestInFlightRef.current = false;
|
|
115
119
|
return [7 /*endfinally*/];
|
|
116
|
-
case
|
|
120
|
+
case 5: return [2 /*return*/];
|
|
117
121
|
}
|
|
118
122
|
});
|
|
119
123
|
}); }, [fetchAppNotifications, limit, notificationTemplates]);
|
|
120
124
|
var loadMore = function () {
|
|
121
|
-
if (loading
|
|
125
|
+
if (loading || !hasMore || requestInFlightRef.current)
|
|
122
126
|
return;
|
|
123
|
-
setPage(function (prevPage) {
|
|
124
|
-
return prevPage + 1;
|
|
125
|
-
});
|
|
127
|
+
setPage(function (prevPage) { return prevPage + 1; });
|
|
126
128
|
};
|
|
127
129
|
var handleMarkNotificationAsRead = function (notificationId) { return __awaiter(_this, void 0, void 0, function () {
|
|
128
130
|
var err_2;
|
|
@@ -148,6 +150,12 @@ function useAppNotificationsData(_a) {
|
|
|
148
150
|
}
|
|
149
151
|
});
|
|
150
152
|
}); };
|
|
153
|
+
// Initialize notifications on mount only
|
|
154
|
+
(0, react_1.useEffect)(function () {
|
|
155
|
+
if (!initializedRef.current) {
|
|
156
|
+
resetAppNotifications();
|
|
157
|
+
}
|
|
158
|
+
}, []);
|
|
151
159
|
// Check how many unread notifications we have
|
|
152
160
|
(0, react_1.useEffect)(function () {
|
|
153
161
|
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -164,9 +172,6 @@ function useAppNotificationsData(_a) {
|
|
|
164
172
|
});
|
|
165
173
|
}); })();
|
|
166
174
|
}, [countUnreadNotifications]);
|
|
167
|
-
(0, react_1.useEffect)(function () {
|
|
168
|
-
resetAppNotifications === null || resetAppNotifications === void 0 ? void 0 : resetAppNotifications();
|
|
169
|
-
}, [resetAppNotifications]);
|
|
170
175
|
// useEffect to get a new batch of app notifications
|
|
171
176
|
(0, react_1.useEffect)(function () {
|
|
172
177
|
var loadMoreNotifications = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -174,48 +179,57 @@ function useAppNotificationsData(_a) {
|
|
|
174
179
|
return __generator(this, function (_a) {
|
|
175
180
|
switch (_a.label) {
|
|
176
181
|
case 0:
|
|
177
|
-
|
|
178
|
-
|
|
182
|
+
// Prevent concurrent requests and ensure we're initialized
|
|
183
|
+
if (requestInFlightRef.current || !initializedRef.current)
|
|
184
|
+
return [2 /*return*/];
|
|
185
|
+
_a.label = 1;
|
|
186
|
+
case 1:
|
|
187
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
188
|
+
requestInFlightRef.current = true;
|
|
189
|
+
setLoading(true);
|
|
179
190
|
return [4 /*yield*/, fetchAppNotifications({
|
|
180
191
|
page: page,
|
|
181
192
|
limit: limit,
|
|
182
193
|
})];
|
|
183
|
-
case
|
|
194
|
+
case 2:
|
|
184
195
|
newAppNotifications = _a.sent();
|
|
185
196
|
if (newAppNotifications) {
|
|
186
197
|
completeNotifications_1 = (0, addNotificationsMessages_1.default)(newAppNotifications, notificationTemplates);
|
|
187
198
|
setAppNotifications(function (prevEntities) {
|
|
188
199
|
return __spreadArray(__spreadArray([], prevEntities, true), completeNotifications_1, true);
|
|
189
200
|
});
|
|
190
|
-
|
|
191
|
-
hasMore.current = false;
|
|
192
|
-
}
|
|
201
|
+
setHasMore(newAppNotifications.length >= limit);
|
|
193
202
|
}
|
|
194
|
-
return [3 /*break*/,
|
|
195
|
-
case
|
|
203
|
+
return [3 /*break*/, 5];
|
|
204
|
+
case 3:
|
|
196
205
|
err_3 = _a.sent();
|
|
197
206
|
(0, handleError_1.handleError)(err_3, "Loading more app notifications failed:");
|
|
198
|
-
return [3 /*break*/,
|
|
199
|
-
case
|
|
200
|
-
|
|
207
|
+
return [3 /*break*/, 5];
|
|
208
|
+
case 4:
|
|
209
|
+
setLoading(false);
|
|
210
|
+
requestInFlightRef.current = false;
|
|
201
211
|
return [7 /*endfinally*/];
|
|
202
|
-
case
|
|
212
|
+
case 5: return [2 /*return*/];
|
|
203
213
|
}
|
|
204
214
|
});
|
|
205
215
|
}); };
|
|
206
|
-
//
|
|
207
|
-
|
|
208
|
-
// Maybe we can do something with debounce? So it will only allow the page state to increase by 1 until it finsihed loading?
|
|
209
|
-
// EDIT: 've added it back aftr checking that indeed this is the issue. Let's keep it safe and find a way to fix it after
|
|
210
|
-
if (page > 1 && hasMore.current && !loading.current) {
|
|
216
|
+
// Only load more pages after initial load (page > 1) and when we have more data
|
|
217
|
+
if (page > 1 && hasMore && !loading && initializedRef.current) {
|
|
211
218
|
loadMoreNotifications();
|
|
212
219
|
}
|
|
213
|
-
}, [page]);
|
|
220
|
+
}, [page, hasMore, loading, fetchAppNotifications, limit, notificationTemplates]);
|
|
221
|
+
// Cleanup on unmount
|
|
222
|
+
(0, react_1.useEffect)(function () {
|
|
223
|
+
return function () {
|
|
224
|
+
requestInFlightRef.current = false;
|
|
225
|
+
initializedRef.current = false;
|
|
226
|
+
};
|
|
227
|
+
}, []);
|
|
214
228
|
return {
|
|
215
229
|
appNotifications: appNotifications,
|
|
216
230
|
unreadAppNotificationsCount: unreadAppNotificationsCount,
|
|
217
|
-
loading:
|
|
218
|
-
hasMore:
|
|
231
|
+
loading: loading,
|
|
232
|
+
hasMore: hasMore,
|
|
219
233
|
loadMore: loadMore,
|
|
220
234
|
markNotificationAsRead: handleMarkNotificationAsRead,
|
|
221
235
|
resetAppNotifications: resetAppNotifications,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAppNotificationsData.js","sourceRoot":"","sources":["../../../../src/hooks/app-notifications/useAppNotificationsData.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAiE;AACjE,wFAAkE;AAClE,8FAAwE;AAKxE,0FAAoE;AACpE,uDAAsD;AACtD,oGAA8E;AAiB9E,SAAS,uBAAuB,CAAC,EAGF;IAH/B,
|
|
1
|
+
{"version":3,"file":"useAppNotificationsData.js","sourceRoot":"","sources":["../../../../src/hooks/app-notifications/useAppNotificationsData.t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BAAmB,EACnB,qBAAqB,CACtB,CAAC;4BAEF,mBAAmB,CAAC,UAAC,YAAY;gCAC/B,uCAAW,YAAY,SAAK,uBAAqB,QAAE;4BACrD,CAAC,CAAC,CAAC;4BAEH,UAAU,CAAC,mBAAmB,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;wBAClD,CAAC;;;;wBAED,IAAA,yBAAW,EAAC,KAAG,EAAE,wCAAwC,CAAC,CAAC;;;wBAE3D,UAAU,CAAC,KAAK,CAAC,CAAC;wBAClB,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;;;;;aAEtC,CAAC;QAEF,gFAAgF;QAChF,IAAI,IAAI,GAAG,CAAC,IAAI,OAAO,IAAI,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC;YAC9D,qBAAqB,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAElF,qBAAqB;IACrB,IAAA,iBAAS,EAAC;QACR,OAAO;YACL,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;YACnC,cAAc,CAAC,OAAO,GAAG,KAAK,CAAC;QACjC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,gBAAgB,kBAAA;QAChB,2BAA2B,6BAAA;QAC3B,OAAO,SAAA;QACP,OAAO,SAAA;QACP,QAAQ,UAAA;QACR,sBAAsB,EAAE,4BAA4B;QACpD,qBAAqB,uBAAA;KACtB,CAAC;AACJ,CAAC;AAED,kBAAe,uBAAuB,CAAC"}
|
|
@@ -43,36 +43,68 @@ var react_1 = require("react");
|
|
|
43
43
|
var useAxiosPrivate_1 = __importDefault(require("../../config/useAxiosPrivate"));
|
|
44
44
|
var useProject_1 = __importDefault(require("../projects/useProject"));
|
|
45
45
|
var useUser_1 = __importDefault(require("../users/useUser"));
|
|
46
|
+
// Cache for deduplicating concurrent requests
|
|
47
|
+
var requestCache = new Map();
|
|
46
48
|
function useFetchAppNotifications() {
|
|
47
49
|
var _this = this;
|
|
48
50
|
var axios = (0, useAxiosPrivate_1.default)();
|
|
49
51
|
var projectId = (0, useProject_1.default)().projectId;
|
|
50
52
|
var user = (0, useUser_1.default)().user;
|
|
53
|
+
var abortControllerRef = (0, react_1.useRef)(null);
|
|
51
54
|
var fetchAppNotifications = (0, react_1.useCallback)(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
52
|
-
var
|
|
55
|
+
var cacheKey, requestPromise;
|
|
53
56
|
var page = _b.page, limit = _b.limit;
|
|
54
57
|
return __generator(this, function (_c) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!user) {
|
|
58
|
-
throw new Error("No authenticated user");
|
|
59
|
-
}
|
|
60
|
-
if (!projectId) {
|
|
61
|
-
throw new Error("No projectId available.");
|
|
62
|
-
}
|
|
63
|
-
return [4 /*yield*/, axios.get("/".concat(projectId, "/app-notifications"), {
|
|
64
|
-
params: {
|
|
65
|
-
page: page,
|
|
66
|
-
limit: limit,
|
|
67
|
-
},
|
|
68
|
-
withCredentials: true,
|
|
69
|
-
})];
|
|
70
|
-
case 1:
|
|
71
|
-
response = _c.sent();
|
|
72
|
-
return [2 /*return*/, response.data];
|
|
58
|
+
if (!user) {
|
|
59
|
+
throw new Error("No authenticated user");
|
|
73
60
|
}
|
|
61
|
+
if (!projectId) {
|
|
62
|
+
throw new Error("No projectId available.");
|
|
63
|
+
}
|
|
64
|
+
cacheKey = "".concat(projectId, "-").concat(page, "-").concat(limit);
|
|
65
|
+
// Return existing request if in progress
|
|
66
|
+
if (requestCache.has(cacheKey)) {
|
|
67
|
+
return [2 /*return*/, requestCache.get(cacheKey)];
|
|
68
|
+
}
|
|
69
|
+
// Cancel any previous request
|
|
70
|
+
if (abortControllerRef.current) {
|
|
71
|
+
abortControllerRef.current.abort();
|
|
72
|
+
}
|
|
73
|
+
// Create new abort controller
|
|
74
|
+
abortControllerRef.current = new AbortController();
|
|
75
|
+
requestPromise = axios.get("/".concat(projectId, "/app-notifications"), {
|
|
76
|
+
params: {
|
|
77
|
+
page: page,
|
|
78
|
+
limit: limit,
|
|
79
|
+
},
|
|
80
|
+
withCredentials: true,
|
|
81
|
+
signal: abortControllerRef.current.signal,
|
|
82
|
+
}).then(function (response) {
|
|
83
|
+
// Clean up cache entry on successful completion
|
|
84
|
+
requestCache.delete(cacheKey);
|
|
85
|
+
return response.data;
|
|
86
|
+
}).catch(function (error) {
|
|
87
|
+
// Clean up cache entry on error
|
|
88
|
+
requestCache.delete(cacheKey);
|
|
89
|
+
// Don't throw if request was aborted
|
|
90
|
+
if (error.name === 'AbortError') {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
throw error;
|
|
94
|
+
});
|
|
95
|
+
// Store request in cache
|
|
96
|
+
requestCache.set(cacheKey, requestPromise);
|
|
97
|
+
return [2 /*return*/, requestPromise];
|
|
74
98
|
});
|
|
75
99
|
}); }, [projectId, axios, user]);
|
|
100
|
+
// Cleanup on unmount
|
|
101
|
+
(0, react_1.useEffect)(function () {
|
|
102
|
+
return function () {
|
|
103
|
+
if (abortControllerRef.current) {
|
|
104
|
+
abortControllerRef.current.abort();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}, []);
|
|
76
108
|
return fetchAppNotifications;
|
|
77
109
|
}
|
|
78
110
|
exports.default = useFetchAppNotifications;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchAppNotifications.js","sourceRoot":"","sources":["../../../../src/hooks/app-notifications/useFetchAppNotifications.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"useFetchAppNotifications.js","sourceRoot":"","sources":["../../../../src/hooks/app-notifications/useFetchAppNotifications.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;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oBACJ,KAAK,OAAA;iBACN;gBACD,eAAe,EAAE,IAAI;gBACrB,MAAM,EAAE,kBAAkB,CAAC,OAAO,CAAC,MAAM;aAC1C,CACF,CAAC,IAAI,CAAC,UAAA,QAAQ;gBACb,gDAAgD;gBAChD,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC9B,OAAO,QAAQ,CAAC,IAAgC,CAAC;YACnD,CAAC,CAAC,CAAC,KAAK,CAAC,UAAA,KAAK;gBACZ,gCAAgC;gBAChC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC9B,qCAAqC;gBACrC,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;oBAChC,OAAO,EAAE,CAAC;gBACZ,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC,CAAC,CAAC;YAEH,yBAAyB;YACzB,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;YAE3C,sBAAO,cAAc,EAAC;;SACvB,EACD,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CACzB,CAAC;IAEF,qBAAqB;IACrB,IAAA,iBAAS,EAAC;QACR,OAAO;YACL,IAAI,kBAAkB,CAAC,OAAO,EAAE,CAAC;gBAC/B,kBAAkB,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACrC,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,kBAAe,wBAAwB,CAAC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export { useCreateReport } from "./hooks/reports";
|
|
|
17
17
|
export { useGetMetadata } from "./hooks/utils";
|
|
18
18
|
export { useUploadFile } from "./hooks/storage";
|
|
19
19
|
export type { EntityCommentsTree } from "./interfaces/EntityCommentsTree";
|
|
20
|
-
export type { UserFull, User } from "./interfaces/models/User";
|
|
20
|
+
export type { UserFull, User, AuthUser } from "./interfaces/models/User";
|
|
21
21
|
export * as AppNotification from "./interfaces/models/AppNotification";
|
|
22
22
|
export type { Entity } from "./interfaces/models/Entity";
|
|
23
23
|
export type { List } from "./interfaces/models/List";
|
|
@@ -66,10 +66,12 @@ function useAppNotificationsData(_a) {
|
|
|
66
66
|
var _c = useState([]), appNotifications = _c[0], setAppNotifications = _c[1];
|
|
67
67
|
var _d = useState(0), unreadAppNotificationsCount = _d[0], setUnreadAppNotificationsCount = _d[1];
|
|
68
68
|
var _e = useState(1), page = _e[0], setPage = _e[1];
|
|
69
|
-
|
|
70
|
-
var _f = useState(true),
|
|
71
|
-
var
|
|
72
|
-
|
|
69
|
+
// Consolidate loading state management
|
|
70
|
+
var _f = useState(true), loading = _f[0], setLoading = _f[1];
|
|
71
|
+
var _g = useState(true), hasMore = _g[0], setHasMore = _g[1];
|
|
72
|
+
// Track initialization to prevent multiple initial loads
|
|
73
|
+
var initializedRef = useRef(false);
|
|
74
|
+
var requestInFlightRef = useRef(false);
|
|
73
75
|
var fetchAppNotifications = useFetchAppNotifications();
|
|
74
76
|
var countUnreadNotifications = useCountUnreadNotifications();
|
|
75
77
|
var markNotificationAsRead = useMarkNotificationAsRead();
|
|
@@ -78,46 +80,46 @@ function useAppNotificationsData(_a) {
|
|
|
78
80
|
return __generator(this, function (_a) {
|
|
79
81
|
switch (_a.label) {
|
|
80
82
|
case 0:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
// Prevent concurrent reset calls
|
|
84
|
+
if (requestInFlightRef.current)
|
|
85
|
+
return [2 /*return*/];
|
|
86
|
+
_a.label = 1;
|
|
87
|
+
case 1:
|
|
88
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
89
|
+
requestInFlightRef.current = true;
|
|
90
|
+
setLoading(true);
|
|
91
|
+
setHasMore(true);
|
|
86
92
|
setPage(1);
|
|
87
93
|
setAppNotifications([]);
|
|
88
94
|
return [4 /*yield*/, fetchAppNotifications({
|
|
89
95
|
page: 1,
|
|
90
96
|
limit: limit,
|
|
91
97
|
})];
|
|
92
|
-
case
|
|
98
|
+
case 2:
|
|
93
99
|
newAppNotifications = _a.sent();
|
|
94
100
|
if (newAppNotifications) {
|
|
95
101
|
completeNotifications = addNotificationsMessages(newAppNotifications, notificationTemplates);
|
|
96
102
|
setAppNotifications(completeNotifications);
|
|
97
|
-
|
|
98
|
-
hasMore.current = false;
|
|
99
|
-
setHasMoreState(false);
|
|
100
|
-
}
|
|
103
|
+
setHasMore(newAppNotifications.length >= limit);
|
|
101
104
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
err_1 = _a.sent();
|
|
105
|
-
handleError(err_1, "Failed to refesh notifications:");
|
|
106
|
-
return [3 /*break*/, 4];
|
|
105
|
+
initializedRef.current = true;
|
|
106
|
+
return [3 /*break*/, 5];
|
|
107
107
|
case 3:
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
err_1 = _a.sent();
|
|
109
|
+
handleError(err_1, "Failed to refresh notifications:");
|
|
110
|
+
return [3 /*break*/, 5];
|
|
111
|
+
case 4:
|
|
112
|
+
setLoading(false);
|
|
113
|
+
requestInFlightRef.current = false;
|
|
110
114
|
return [7 /*endfinally*/];
|
|
111
|
-
case
|
|
115
|
+
case 5: return [2 /*return*/];
|
|
112
116
|
}
|
|
113
117
|
});
|
|
114
118
|
}); }, [fetchAppNotifications, limit, notificationTemplates]);
|
|
115
119
|
var loadMore = function () {
|
|
116
|
-
if (loading
|
|
120
|
+
if (loading || !hasMore || requestInFlightRef.current)
|
|
117
121
|
return;
|
|
118
|
-
setPage(function (prevPage) {
|
|
119
|
-
return prevPage + 1;
|
|
120
|
-
});
|
|
122
|
+
setPage(function (prevPage) { return prevPage + 1; });
|
|
121
123
|
};
|
|
122
124
|
var handleMarkNotificationAsRead = function (notificationId) { return __awaiter(_this, void 0, void 0, function () {
|
|
123
125
|
var err_2;
|
|
@@ -143,6 +145,12 @@ function useAppNotificationsData(_a) {
|
|
|
143
145
|
}
|
|
144
146
|
});
|
|
145
147
|
}); };
|
|
148
|
+
// Initialize notifications on mount only
|
|
149
|
+
useEffect(function () {
|
|
150
|
+
if (!initializedRef.current) {
|
|
151
|
+
resetAppNotifications();
|
|
152
|
+
}
|
|
153
|
+
}, []);
|
|
146
154
|
// Check how many unread notifications we have
|
|
147
155
|
useEffect(function () {
|
|
148
156
|
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -159,9 +167,6 @@ function useAppNotificationsData(_a) {
|
|
|
159
167
|
});
|
|
160
168
|
}); })();
|
|
161
169
|
}, [countUnreadNotifications]);
|
|
162
|
-
useEffect(function () {
|
|
163
|
-
resetAppNotifications === null || resetAppNotifications === void 0 ? void 0 : resetAppNotifications();
|
|
164
|
-
}, [resetAppNotifications]);
|
|
165
170
|
// useEffect to get a new batch of app notifications
|
|
166
171
|
useEffect(function () {
|
|
167
172
|
var loadMoreNotifications = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -169,48 +174,57 @@ function useAppNotificationsData(_a) {
|
|
|
169
174
|
return __generator(this, function (_a) {
|
|
170
175
|
switch (_a.label) {
|
|
171
176
|
case 0:
|
|
172
|
-
|
|
173
|
-
|
|
177
|
+
// Prevent concurrent requests and ensure we're initialized
|
|
178
|
+
if (requestInFlightRef.current || !initializedRef.current)
|
|
179
|
+
return [2 /*return*/];
|
|
180
|
+
_a.label = 1;
|
|
181
|
+
case 1:
|
|
182
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
183
|
+
requestInFlightRef.current = true;
|
|
184
|
+
setLoading(true);
|
|
174
185
|
return [4 /*yield*/, fetchAppNotifications({
|
|
175
186
|
page: page,
|
|
176
187
|
limit: limit,
|
|
177
188
|
})];
|
|
178
|
-
case
|
|
189
|
+
case 2:
|
|
179
190
|
newAppNotifications = _a.sent();
|
|
180
191
|
if (newAppNotifications) {
|
|
181
192
|
completeNotifications_1 = addNotificationsMessages(newAppNotifications, notificationTemplates);
|
|
182
193
|
setAppNotifications(function (prevEntities) {
|
|
183
194
|
return __spreadArray(__spreadArray([], prevEntities, true), completeNotifications_1, true);
|
|
184
195
|
});
|
|
185
|
-
|
|
186
|
-
hasMore.current = false;
|
|
187
|
-
}
|
|
196
|
+
setHasMore(newAppNotifications.length >= limit);
|
|
188
197
|
}
|
|
189
|
-
return [3 /*break*/,
|
|
190
|
-
case
|
|
198
|
+
return [3 /*break*/, 5];
|
|
199
|
+
case 3:
|
|
191
200
|
err_3 = _a.sent();
|
|
192
201
|
handleError(err_3, "Loading more app notifications failed:");
|
|
193
|
-
return [3 /*break*/,
|
|
194
|
-
case
|
|
195
|
-
|
|
202
|
+
return [3 /*break*/, 5];
|
|
203
|
+
case 4:
|
|
204
|
+
setLoading(false);
|
|
205
|
+
requestInFlightRef.current = false;
|
|
196
206
|
return [7 /*endfinally*/];
|
|
197
|
-
case
|
|
207
|
+
case 5: return [2 /*return*/];
|
|
198
208
|
}
|
|
199
209
|
});
|
|
200
210
|
}); };
|
|
201
|
-
//
|
|
202
|
-
|
|
203
|
-
// Maybe we can do something with debounce? So it will only allow the page state to increase by 1 until it finsihed loading?
|
|
204
|
-
// EDIT: 've added it back aftr checking that indeed this is the issue. Let's keep it safe and find a way to fix it after
|
|
205
|
-
if (page > 1 && hasMore.current && !loading.current) {
|
|
211
|
+
// Only load more pages after initial load (page > 1) and when we have more data
|
|
212
|
+
if (page > 1 && hasMore && !loading && initializedRef.current) {
|
|
206
213
|
loadMoreNotifications();
|
|
207
214
|
}
|
|
208
|
-
}, [page]);
|
|
215
|
+
}, [page, hasMore, loading, fetchAppNotifications, limit, notificationTemplates]);
|
|
216
|
+
// Cleanup on unmount
|
|
217
|
+
useEffect(function () {
|
|
218
|
+
return function () {
|
|
219
|
+
requestInFlightRef.current = false;
|
|
220
|
+
initializedRef.current = false;
|
|
221
|
+
};
|
|
222
|
+
}, []);
|
|
209
223
|
return {
|
|
210
224
|
appNotifications: appNotifications,
|
|
211
225
|
unreadAppNotificationsCount: unreadAppNotificationsCount,
|
|
212
|
-
loading:
|
|
213
|
-
hasMore:
|
|
226
|
+
loading: loading,
|
|
227
|
+
hasMore: hasMore,
|
|
214
228
|
loadMore: loadMore,
|
|
215
229
|
markNotificationAsRead: handleMarkNotificationAsRead,
|
|
216
230
|
resetAppNotifications: resetAppNotifications,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAppNotificationsData.js","sourceRoot":"","sources":["../../../../src/hooks/app-notifications/useAppNotificationsData.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,2BAA2B,MAAM,+BAA+B,CAAC;AAKxE,OAAO,yBAAyB,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,wBAAwB,MAAM,wCAAwC,CAAC;AAiB9E,SAAS,uBAAuB,CAAC,EAGF;IAH/B,
|
|
1
|
+
{"version":3,"file":"useAppNotificationsData.js","sourceRoot":"","sources":["../../../../src/hooks/app-notifications/useAppNotificationsData.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,2BAA2B,MAAM,+BAA+B,CAAC;AAKxE,OAAO,yBAAyB,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,wBAAwB,MAAM,wCAAwC,CAAC;AAiB9E,SAAS,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kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;;;;;aAEtC,CAAC;QAEF,gFAAgF;QAChF,IAAI,IAAI,GAAG,CAAC,IAAI,OAAO,IAAI,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC;YAC9D,qBAAqB,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAElF,qBAAqB;IACrB,SAAS,CAAC;QACR,OAAO;YACL,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;YACnC,cAAc,CAAC,OAAO,GAAG,KAAK,CAAC;QACjC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,gBAAgB,kBAAA;QAChB,2BAA2B,6BAAA;QAC3B,OAAO,SAAA;QACP,OAAO,SAAA;QACP,QAAQ,UAAA;QACR,sBAAsB,EAAE,4BAA4B;QACpD,qBAAqB,uBAAA;KACtB,CAAC;AACJ,CAAC;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -34,40 +34,72 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
import { useCallback } from "react";
|
|
37
|
+
import { useCallback, useRef, useEffect } from "react";
|
|
38
38
|
import useAxiosPrivate from "../../config/useAxiosPrivate";
|
|
39
39
|
import useProject from "../projects/useProject";
|
|
40
40
|
import useUser from "../users/useUser";
|
|
41
|
+
// Cache for deduplicating concurrent requests
|
|
42
|
+
var requestCache = new Map();
|
|
41
43
|
function useFetchAppNotifications() {
|
|
42
44
|
var _this = this;
|
|
43
45
|
var axios = useAxiosPrivate();
|
|
44
46
|
var projectId = useProject().projectId;
|
|
45
47
|
var user = useUser().user;
|
|
48
|
+
var abortControllerRef = useRef(null);
|
|
46
49
|
var fetchAppNotifications = useCallback(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
47
|
-
var
|
|
50
|
+
var cacheKey, requestPromise;
|
|
48
51
|
var page = _b.page, limit = _b.limit;
|
|
49
52
|
return __generator(this, function (_c) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (!user) {
|
|
53
|
-
throw new Error("No authenticated user");
|
|
54
|
-
}
|
|
55
|
-
if (!projectId) {
|
|
56
|
-
throw new Error("No projectId available.");
|
|
57
|
-
}
|
|
58
|
-
return [4 /*yield*/, axios.get("/".concat(projectId, "/app-notifications"), {
|
|
59
|
-
params: {
|
|
60
|
-
page: page,
|
|
61
|
-
limit: limit,
|
|
62
|
-
},
|
|
63
|
-
withCredentials: true,
|
|
64
|
-
})];
|
|
65
|
-
case 1:
|
|
66
|
-
response = _c.sent();
|
|
67
|
-
return [2 /*return*/, response.data];
|
|
53
|
+
if (!user) {
|
|
54
|
+
throw new Error("No authenticated user");
|
|
68
55
|
}
|
|
56
|
+
if (!projectId) {
|
|
57
|
+
throw new Error("No projectId available.");
|
|
58
|
+
}
|
|
59
|
+
cacheKey = "".concat(projectId, "-").concat(page, "-").concat(limit);
|
|
60
|
+
// Return existing request if in progress
|
|
61
|
+
if (requestCache.has(cacheKey)) {
|
|
62
|
+
return [2 /*return*/, requestCache.get(cacheKey)];
|
|
63
|
+
}
|
|
64
|
+
// Cancel any previous request
|
|
65
|
+
if (abortControllerRef.current) {
|
|
66
|
+
abortControllerRef.current.abort();
|
|
67
|
+
}
|
|
68
|
+
// Create new abort controller
|
|
69
|
+
abortControllerRef.current = new AbortController();
|
|
70
|
+
requestPromise = axios.get("/".concat(projectId, "/app-notifications"), {
|
|
71
|
+
params: {
|
|
72
|
+
page: page,
|
|
73
|
+
limit: limit,
|
|
74
|
+
},
|
|
75
|
+
withCredentials: true,
|
|
76
|
+
signal: abortControllerRef.current.signal,
|
|
77
|
+
}).then(function (response) {
|
|
78
|
+
// Clean up cache entry on successful completion
|
|
79
|
+
requestCache.delete(cacheKey);
|
|
80
|
+
return response.data;
|
|
81
|
+
}).catch(function (error) {
|
|
82
|
+
// Clean up cache entry on error
|
|
83
|
+
requestCache.delete(cacheKey);
|
|
84
|
+
// Don't throw if request was aborted
|
|
85
|
+
if (error.name === 'AbortError') {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
throw error;
|
|
89
|
+
});
|
|
90
|
+
// Store request in cache
|
|
91
|
+
requestCache.set(cacheKey, requestPromise);
|
|
92
|
+
return [2 /*return*/, requestPromise];
|
|
69
93
|
});
|
|
70
94
|
}); }, [projectId, axios, user]);
|
|
95
|
+
// Cleanup on unmount
|
|
96
|
+
useEffect(function () {
|
|
97
|
+
return function () {
|
|
98
|
+
if (abortControllerRef.current) {
|
|
99
|
+
abortControllerRef.current.abort();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}, []);
|
|
71
103
|
return fetchAppNotifications;
|
|
72
104
|
}
|
|
73
105
|
export default useFetchAppNotifications;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchAppNotifications.js","sourceRoot":"","sources":["../../../../src/hooks/app-notifications/useFetchAppNotifications.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useFetchAppNotifications.js","sourceRoot":"","sources":["../../../../src/hooks/app-notifications/useFetchAppNotifications.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAC3D,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,OAAO,MAAM,kBAAkB,CAAC;AAEvC,8CAA8C;AA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A,QAAQ;gBACb,gDAAgD;gBAChD,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC9B,OAAO,QAAQ,CAAC,IAAgC,CAAC;YACnD,CAAC,CAAC,CAAC,KAAK,CAAC,UAAA,KAAK;gBACZ,gCAAgC;gBAChC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC9B,qCAAqC;gBACrC,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;oBAChC,OAAO,EAAE,CAAC;gBACZ,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC,CAAC,CAAC;YAEH,yBAAyB;YACzB,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;YAE3C,sBAAO,cAAc,EAAC;;SACvB,EACD,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CACzB,CAAC;IAEF,qBAAqB;IACrB,SAAS,CAAC;QACR,OAAO;YACL,IAAI,kBAAkB,CAAC,OAAO,EAAE,CAAC;gBAC/B,kBAAkB,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACrC,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,eAAe,wBAAwB,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export { useCreateReport } from "./hooks/reports";
|
|
|
17
17
|
export { useGetMetadata } from "./hooks/utils";
|
|
18
18
|
export { useUploadFile } from "./hooks/storage";
|
|
19
19
|
export type { EntityCommentsTree } from "./interfaces/EntityCommentsTree";
|
|
20
|
-
export type { UserFull, User } from "./interfaces/models/User";
|
|
20
|
+
export type { UserFull, User, AuthUser } from "./interfaces/models/User";
|
|
21
21
|
export * as AppNotification from "./interfaces/models/AppNotification";
|
|
22
22
|
export type { Entity } from "./interfaces/models/Entity";
|
|
23
23
|
export type { List } from "./interfaces/models/List";
|