@liveblocks/react 2.2.3-alpha2 → 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/{chunk-OZDSOIGV.js → chunk-K5EDPAZP.js} +274 -158
- package/dist/chunk-K5EDPAZP.js.map +1 -0
- package/dist/{chunk-AKAI4UTH.mjs → chunk-N2EE2UOX.mjs} +269 -153
- package/dist/chunk-N2EE2UOX.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{suspense-Wplc32v5.d.mts → suspense-cGHXI2Em.d.mts} +55 -50
- package/dist/{suspense-Wplc32v5.d.ts → suspense-cGHXI2Em.d.ts} +55 -50
- package/dist/suspense.d.mts +1 -1
- package/dist/suspense.d.ts +1 -1
- package/dist/suspense.js +7 -3
- package/dist/suspense.js.map +1 -1
- package/dist/suspense.mjs +5 -1
- package/dist/suspense.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-AKAI4UTH.mjs.map +0 -1
- package/dist/chunk-OZDSOIGV.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
2
|
var PKG_NAME = "@liveblocks/react";
|
|
3
|
-
var PKG_VERSION = "2.
|
|
3
|
+
var PKG_VERSION = "2.3.0";
|
|
4
4
|
var PKG_FORMAT = "esm";
|
|
5
5
|
|
|
6
6
|
// src/ClientSideSuspense.tsx
|
|
@@ -15,9 +15,11 @@ function ClientSideSuspense(props) {
|
|
|
15
15
|
|
|
16
16
|
// src/liveblocks.tsx
|
|
17
17
|
import {
|
|
18
|
+
assert,
|
|
18
19
|
createClient,
|
|
19
20
|
kInternal,
|
|
20
21
|
makePoller,
|
|
22
|
+
memoizeOnSuccess,
|
|
21
23
|
raise,
|
|
22
24
|
shallow
|
|
23
25
|
} from "@liveblocks/core";
|
|
@@ -43,6 +45,7 @@ function selectedInboxNotifications(state) {
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
// src/lib/retry-error.ts
|
|
48
|
+
import { wait } from "@liveblocks/core";
|
|
46
49
|
var MAX_ERROR_RETRY_COUNT = 5;
|
|
47
50
|
var ERROR_RETRY_INTERVAL = 5e3;
|
|
48
51
|
function retryError(action, retryCount) {
|
|
@@ -52,6 +55,23 @@ function retryError(action, retryCount) {
|
|
|
52
55
|
void action();
|
|
53
56
|
}, timeout);
|
|
54
57
|
}
|
|
58
|
+
async function autoRetry(promiseFn, maxTries, backoff) {
|
|
59
|
+
const fallbackBackoff = backoff.length > 0 ? backoff[backoff.length - 1] : 0;
|
|
60
|
+
let attempt = 0;
|
|
61
|
+
while (true) {
|
|
62
|
+
attempt++;
|
|
63
|
+
const promise = promiseFn();
|
|
64
|
+
try {
|
|
65
|
+
return await promise;
|
|
66
|
+
} catch (err) {
|
|
67
|
+
if (attempt >= maxTries) {
|
|
68
|
+
throw new Error(`Failed after ${maxTries} attempts: ${String(err)}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const delay = backoff[attempt - 1] ?? fallbackBackoff;
|
|
72
|
+
await wait(delay);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
55
75
|
|
|
56
76
|
// src/lib/use-initial.ts
|
|
57
77
|
import { useCallback, useReducer } from "react";
|
|
@@ -83,6 +103,33 @@ function useInitialUnlessFunction(latestValue) {
|
|
|
83
103
|
}
|
|
84
104
|
}
|
|
85
105
|
|
|
106
|
+
// src/lib/use-polyfill.ts
|
|
107
|
+
var use = (
|
|
108
|
+
// React.use ||
|
|
109
|
+
(promise) => {
|
|
110
|
+
if (promise.status === "pending") {
|
|
111
|
+
throw promise;
|
|
112
|
+
} else if (promise.status === "fulfilled") {
|
|
113
|
+
return promise.value;
|
|
114
|
+
} else if (promise.status === "rejected") {
|
|
115
|
+
throw promise.reason;
|
|
116
|
+
} else {
|
|
117
|
+
promise.status = "pending";
|
|
118
|
+
promise.then(
|
|
119
|
+
(v) => {
|
|
120
|
+
promise.status = "fulfilled";
|
|
121
|
+
promise.value = v;
|
|
122
|
+
},
|
|
123
|
+
(e) => {
|
|
124
|
+
promise.status = "rejected";
|
|
125
|
+
promise.reason = e;
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
throw promise;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
|
|
86
133
|
// src/liveblocks.tsx
|
|
87
134
|
var ClientContext = createContext(null);
|
|
88
135
|
function missingUserError(userId) {
|
|
@@ -115,12 +162,6 @@ function selectorFor_useInboxNotifications(state) {
|
|
|
115
162
|
isLoading: false
|
|
116
163
|
};
|
|
117
164
|
}
|
|
118
|
-
function selectorFor_useInboxNotificationsSuspense(state) {
|
|
119
|
-
return {
|
|
120
|
-
inboxNotifications: selectedInboxNotifications(state),
|
|
121
|
-
isLoading: false
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
165
|
function selectUnreadInboxNotificationsCount(state) {
|
|
125
166
|
let count = 0;
|
|
126
167
|
for (const notification of selectedInboxNotifications(state)) {
|
|
@@ -148,10 +189,40 @@ function selectorFor_useUnreadInboxNotificationsCount(state) {
|
|
|
148
189
|
count: selectUnreadInboxNotificationsCount(state)
|
|
149
190
|
};
|
|
150
191
|
}
|
|
151
|
-
function
|
|
192
|
+
function selectorFor_useUser(state, userId) {
|
|
193
|
+
if (state === void 0 || state?.isLoading) {
|
|
194
|
+
return state ?? { isLoading: true };
|
|
195
|
+
}
|
|
196
|
+
if (state.error) {
|
|
197
|
+
return state;
|
|
198
|
+
}
|
|
199
|
+
if (!state.data) {
|
|
200
|
+
return {
|
|
201
|
+
isLoading: false,
|
|
202
|
+
error: missingUserError(userId)
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
isLoading: false,
|
|
207
|
+
user: state.data
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function selectorFor_useRoomInfo(state, roomId) {
|
|
211
|
+
if (state === void 0 || state?.isLoading) {
|
|
212
|
+
return state ?? { isLoading: true };
|
|
213
|
+
}
|
|
214
|
+
if (state.error) {
|
|
215
|
+
return state;
|
|
216
|
+
}
|
|
217
|
+
if (!state.data) {
|
|
218
|
+
return {
|
|
219
|
+
isLoading: false,
|
|
220
|
+
error: missingRoomInfoError(roomId)
|
|
221
|
+
};
|
|
222
|
+
}
|
|
152
223
|
return {
|
|
153
224
|
isLoading: false,
|
|
154
|
-
|
|
225
|
+
info: state.data
|
|
155
226
|
};
|
|
156
227
|
}
|
|
157
228
|
function getOrCreateContextBundle(client) {
|
|
@@ -174,93 +245,84 @@ function makeExtrasForClient(client) {
|
|
|
174
245
|
const internals = client[kInternal];
|
|
175
246
|
const store = internals.cacheStore;
|
|
176
247
|
const notifications = internals.notifications;
|
|
177
|
-
let fetchInboxNotifications$ = null;
|
|
178
248
|
let lastRequestedAt;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
249
|
+
async function fetchInboxNotifications() {
|
|
250
|
+
const since = lastRequestedAt !== void 0 ? { since: lastRequestedAt } : void 0;
|
|
251
|
+
const result = await notifications.getInboxNotifications(since);
|
|
252
|
+
store.updateThreadsAndNotifications(
|
|
253
|
+
result.threads,
|
|
254
|
+
result.inboxNotifications,
|
|
255
|
+
result.deletedThreads,
|
|
256
|
+
result.deletedInboxNotifications,
|
|
257
|
+
INBOX_NOTIFICATIONS_QUERY
|
|
258
|
+
);
|
|
259
|
+
if (lastRequestedAt === void 0 || lastRequestedAt < result.meta.requestedAt) {
|
|
260
|
+
lastRequestedAt = result.meta.requestedAt;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
let pollerSubscribers = 0;
|
|
264
|
+
const poller = makePoller(async () => {
|
|
265
|
+
try {
|
|
266
|
+
await waitUntilInboxNotificationsLoaded();
|
|
267
|
+
await fetchInboxNotifications();
|
|
268
|
+
} catch (err) {
|
|
269
|
+
console.warn(`Polling new inbox notifications failed: ${String(err)}`);
|
|
198
270
|
}
|
|
271
|
+
});
|
|
272
|
+
const waitUntilInboxNotificationsLoaded = memoizeOnSuccess(async () => {
|
|
199
273
|
store.setQueryState(INBOX_NOTIFICATIONS_QUERY, {
|
|
200
274
|
isLoading: true
|
|
201
275
|
});
|
|
202
276
|
try {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
result.inboxNotifications,
|
|
208
|
-
result.deletedThreads,
|
|
209
|
-
result.deletedInboxNotifications,
|
|
210
|
-
INBOX_NOTIFICATIONS_QUERY
|
|
277
|
+
await autoRetry(
|
|
278
|
+
() => fetchInboxNotifications(),
|
|
279
|
+
5,
|
|
280
|
+
[5e3, 5e3, 1e4, 15e3]
|
|
211
281
|
);
|
|
212
|
-
|
|
213
|
-
lastRequestedAt = result.meta.requestedAt;
|
|
214
|
-
}
|
|
215
|
-
poller.start(POLLING_INTERVAL);
|
|
216
|
-
} catch (er) {
|
|
217
|
-
fetchInboxNotifications$ = null;
|
|
218
|
-
retryError(() => {
|
|
219
|
-
void fetchInboxNotifications({
|
|
220
|
-
retryCount: retryCount + 1
|
|
221
|
-
});
|
|
222
|
-
}, retryCount);
|
|
282
|
+
} catch (err) {
|
|
223
283
|
store.setQueryState(INBOX_NOTIFICATIONS_QUERY, {
|
|
224
284
|
isLoading: false,
|
|
225
|
-
error:
|
|
285
|
+
error: err
|
|
226
286
|
});
|
|
287
|
+
throw err;
|
|
227
288
|
}
|
|
228
|
-
|
|
289
|
+
});
|
|
290
|
+
function loadInboxNotifications() {
|
|
291
|
+
void waitUntilInboxNotificationsLoaded().catch(() => {
|
|
292
|
+
});
|
|
229
293
|
}
|
|
230
|
-
|
|
231
|
-
function useSubscribeToInboxNotificationsEffect(options) {
|
|
232
|
-
const autoFetch = useInitial(options?.autoFetch ?? true);
|
|
294
|
+
function useEnableInboxNotificationsPolling() {
|
|
233
295
|
useEffect3(() => {
|
|
234
|
-
|
|
235
|
-
void fetchInboxNotifications();
|
|
236
|
-
}
|
|
237
|
-
inboxNotificationsSubscribers++;
|
|
296
|
+
pollerSubscribers++;
|
|
238
297
|
poller.start(POLLING_INTERVAL);
|
|
239
298
|
return () => {
|
|
240
|
-
if (
|
|
299
|
+
if (pollerSubscribers <= 0) {
|
|
241
300
|
console.warn(
|
|
242
301
|
`Internal unexpected behavior. Cannot decrease subscriber count for query "${INBOX_NOTIFICATIONS_QUERY}"`
|
|
243
302
|
);
|
|
244
303
|
return;
|
|
245
304
|
}
|
|
246
|
-
|
|
247
|
-
if (
|
|
305
|
+
pollerSubscribers--;
|
|
306
|
+
if (pollerSubscribers <= 0) {
|
|
248
307
|
poller.stop();
|
|
249
308
|
}
|
|
250
309
|
};
|
|
251
|
-
}, [
|
|
310
|
+
}, []);
|
|
252
311
|
}
|
|
253
312
|
return {
|
|
254
313
|
store,
|
|
255
314
|
notifications,
|
|
256
|
-
|
|
257
|
-
|
|
315
|
+
useEnableInboxNotificationsPolling,
|
|
316
|
+
waitUntilInboxNotificationsLoaded,
|
|
317
|
+
loadInboxNotifications
|
|
258
318
|
};
|
|
259
319
|
}
|
|
260
320
|
function makeLiveblocksContextBundle(client) {
|
|
261
321
|
const useInboxNotificationThread2 = (inboxNotificationId) => useInboxNotificationThread_withClient(client, inboxNotificationId);
|
|
262
322
|
const useMarkInboxNotificationAsRead2 = () => useMarkInboxNotificationAsRead_withClient(client);
|
|
263
323
|
const useMarkAllInboxNotificationsAsRead2 = () => useMarkAllInboxNotificationsAsRead_withClient(client);
|
|
324
|
+
const useDeleteInboxNotification2 = () => useDeleteInboxNotification_withClient(client);
|
|
325
|
+
const useDeleteAllInboxNotifications2 = () => useDeleteAllInboxNotifications_withClient(client);
|
|
264
326
|
function LiveblocksProvider2(props) {
|
|
265
327
|
useEnsureNoLiveblocksProvider();
|
|
266
328
|
return /* @__PURE__ */ React2.createElement(ClientContext.Provider, { value: client }, props.children);
|
|
@@ -272,6 +334,8 @@ function makeLiveblocksContextBundle(client) {
|
|
|
272
334
|
useUnreadInboxNotificationsCount: () => useUnreadInboxNotificationsCount_withClient(client),
|
|
273
335
|
useMarkInboxNotificationAsRead: useMarkInboxNotificationAsRead2,
|
|
274
336
|
useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
|
|
337
|
+
useDeleteInboxNotification: useDeleteInboxNotification2,
|
|
338
|
+
useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
|
|
275
339
|
useInboxNotificationThread: useInboxNotificationThread2,
|
|
276
340
|
...shared.classic,
|
|
277
341
|
suspense: {
|
|
@@ -280,6 +344,8 @@ function makeLiveblocksContextBundle(client) {
|
|
|
280
344
|
useUnreadInboxNotificationsCount: () => useUnreadInboxNotificationsCountSuspense_withClient(client),
|
|
281
345
|
useMarkInboxNotificationAsRead: useMarkInboxNotificationAsRead2,
|
|
282
346
|
useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
|
|
347
|
+
useDeleteInboxNotification: useDeleteInboxNotification2,
|
|
348
|
+
useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
|
|
283
349
|
useInboxNotificationThread: useInboxNotificationThread2,
|
|
284
350
|
...shared.suspense
|
|
285
351
|
}
|
|
@@ -287,8 +353,11 @@ function makeLiveblocksContextBundle(client) {
|
|
|
287
353
|
return bundle;
|
|
288
354
|
}
|
|
289
355
|
function useInboxNotifications_withClient(client) {
|
|
290
|
-
const { store,
|
|
291
|
-
|
|
356
|
+
const { loadInboxNotifications, store, useEnableInboxNotificationsPolling } = getExtrasForClient(client);
|
|
357
|
+
useEffect3(() => {
|
|
358
|
+
loadInboxNotifications();
|
|
359
|
+
}, [loadInboxNotifications]);
|
|
360
|
+
useEnableInboxNotificationsPolling();
|
|
292
361
|
return useSyncExternalStoreWithSelector(
|
|
293
362
|
store.subscribe,
|
|
294
363
|
store.get,
|
|
@@ -298,30 +367,19 @@ function useInboxNotifications_withClient(client) {
|
|
|
298
367
|
);
|
|
299
368
|
}
|
|
300
369
|
function useInboxNotificationsSuspense_withClient(client) {
|
|
301
|
-
const {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (query === void 0 || query.isLoading) {
|
|
308
|
-
throw fetchInboxNotifications();
|
|
309
|
-
}
|
|
310
|
-
if (query.error !== void 0) {
|
|
311
|
-
throw query.error;
|
|
312
|
-
}
|
|
313
|
-
useSubscribeToInboxNotificationsEffect({ autoFetch: false });
|
|
314
|
-
return useSyncExternalStoreWithSelector(
|
|
315
|
-
store.subscribe,
|
|
316
|
-
store.get,
|
|
317
|
-
store.get,
|
|
318
|
-
selectorFor_useInboxNotificationsSuspense,
|
|
319
|
-
shallow
|
|
320
|
-
);
|
|
370
|
+
const { waitUntilInboxNotificationsLoaded } = getExtrasForClient(client);
|
|
371
|
+
use(waitUntilInboxNotificationsLoaded());
|
|
372
|
+
const result = useInboxNotifications_withClient(client);
|
|
373
|
+
assert(!result.error, "Did not expect error");
|
|
374
|
+
assert(!result.isLoading, "Did not expect loading");
|
|
375
|
+
return result;
|
|
321
376
|
}
|
|
322
377
|
function useUnreadInboxNotificationsCount_withClient(client) {
|
|
323
|
-
const { store,
|
|
324
|
-
|
|
378
|
+
const { store, loadInboxNotifications, useEnableInboxNotificationsPolling } = getExtrasForClient(client);
|
|
379
|
+
useEffect3(() => {
|
|
380
|
+
loadInboxNotifications();
|
|
381
|
+
}, [loadInboxNotifications]);
|
|
382
|
+
useEnableInboxNotificationsPolling();
|
|
325
383
|
return useSyncExternalStoreWithSelector(
|
|
326
384
|
store.subscribe,
|
|
327
385
|
store.get,
|
|
@@ -331,23 +389,12 @@ function useUnreadInboxNotificationsCount_withClient(client) {
|
|
|
331
389
|
);
|
|
332
390
|
}
|
|
333
391
|
function useUnreadInboxNotificationsCountSuspense_withClient(client) {
|
|
334
|
-
const {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if (query === void 0 || query.isLoading) {
|
|
341
|
-
throw fetchInboxNotifications();
|
|
342
|
-
}
|
|
343
|
-
useSubscribeToInboxNotificationsEffect({ autoFetch: false });
|
|
344
|
-
return useSyncExternalStoreWithSelector(
|
|
345
|
-
store.subscribe,
|
|
346
|
-
store.get,
|
|
347
|
-
store.get,
|
|
348
|
-
selectorFor_useUnreadInboxNotificationsCountSuspense,
|
|
349
|
-
shallow
|
|
350
|
-
);
|
|
392
|
+
const { waitUntilInboxNotificationsLoaded } = getExtrasForClient(client);
|
|
393
|
+
use(waitUntilInboxNotificationsLoaded());
|
|
394
|
+
const result = useUnreadInboxNotificationsCount_withClient(client);
|
|
395
|
+
assert(!result.isLoading, "Did not expect loading");
|
|
396
|
+
assert(!result.error, "Did not expect error");
|
|
397
|
+
return result;
|
|
351
398
|
}
|
|
352
399
|
function useMarkInboxNotificationAsRead_withClient(client) {
|
|
353
400
|
return useCallback2(
|
|
@@ -407,7 +454,7 @@ function useMarkAllInboxNotificationsAsRead_withClient(client) {
|
|
|
407
454
|
const optimisticUpdateId = nanoid();
|
|
408
455
|
const readAt = /* @__PURE__ */ new Date();
|
|
409
456
|
store.pushOptimisticUpdate({
|
|
410
|
-
type: "mark-inbox-notifications-as-read",
|
|
457
|
+
type: "mark-all-inbox-notifications-as-read",
|
|
411
458
|
id: optimisticUpdateId,
|
|
412
459
|
readAt
|
|
413
460
|
});
|
|
@@ -439,6 +486,84 @@ function useMarkAllInboxNotificationsAsRead_withClient(client) {
|
|
|
439
486
|
);
|
|
440
487
|
}, [client]);
|
|
441
488
|
}
|
|
489
|
+
function useDeleteInboxNotification_withClient(client) {
|
|
490
|
+
return useCallback2(
|
|
491
|
+
(inboxNotificationId) => {
|
|
492
|
+
const { store, notifications } = getExtrasForClient(client);
|
|
493
|
+
const optimisticUpdateId = nanoid();
|
|
494
|
+
const deletedAt = /* @__PURE__ */ new Date();
|
|
495
|
+
store.pushOptimisticUpdate({
|
|
496
|
+
type: "delete-inbox-notification",
|
|
497
|
+
id: optimisticUpdateId,
|
|
498
|
+
inboxNotificationId,
|
|
499
|
+
deletedAt
|
|
500
|
+
});
|
|
501
|
+
notifications.deleteInboxNotification(inboxNotificationId).then(
|
|
502
|
+
() => {
|
|
503
|
+
store.set((state) => {
|
|
504
|
+
const existingNotification = state.inboxNotifications[inboxNotificationId];
|
|
505
|
+
if (existingNotification === void 0) {
|
|
506
|
+
return {
|
|
507
|
+
...state,
|
|
508
|
+
optimisticUpdates: state.optimisticUpdates.filter(
|
|
509
|
+
(update) => update.id !== optimisticUpdateId
|
|
510
|
+
)
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
const { [inboxNotificationId]: _, ...inboxNotifications } = state.inboxNotifications;
|
|
514
|
+
return {
|
|
515
|
+
...state,
|
|
516
|
+
inboxNotifications,
|
|
517
|
+
optimisticUpdates: state.optimisticUpdates.filter(
|
|
518
|
+
(update) => update.id !== optimisticUpdateId
|
|
519
|
+
)
|
|
520
|
+
};
|
|
521
|
+
});
|
|
522
|
+
},
|
|
523
|
+
() => {
|
|
524
|
+
store.set((state) => ({
|
|
525
|
+
...state,
|
|
526
|
+
optimisticUpdates: state.optimisticUpdates.filter(
|
|
527
|
+
(update) => update.id !== optimisticUpdateId
|
|
528
|
+
)
|
|
529
|
+
}));
|
|
530
|
+
}
|
|
531
|
+
);
|
|
532
|
+
},
|
|
533
|
+
[client]
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
function useDeleteAllInboxNotifications_withClient(client) {
|
|
537
|
+
return useCallback2(() => {
|
|
538
|
+
const { store, notifications } = getExtrasForClient(client);
|
|
539
|
+
const optimisticUpdateId = nanoid();
|
|
540
|
+
const deletedAt = /* @__PURE__ */ new Date();
|
|
541
|
+
store.pushOptimisticUpdate({
|
|
542
|
+
type: "delete-all-inbox-notifications",
|
|
543
|
+
id: optimisticUpdateId,
|
|
544
|
+
deletedAt
|
|
545
|
+
});
|
|
546
|
+
notifications.deleteAllInboxNotifications().then(
|
|
547
|
+
() => {
|
|
548
|
+
store.set((state) => ({
|
|
549
|
+
...state,
|
|
550
|
+
inboxNotifications: {},
|
|
551
|
+
optimisticUpdates: state.optimisticUpdates.filter(
|
|
552
|
+
(update) => update.id !== optimisticUpdateId
|
|
553
|
+
)
|
|
554
|
+
}));
|
|
555
|
+
},
|
|
556
|
+
() => {
|
|
557
|
+
store.set((state) => ({
|
|
558
|
+
...state,
|
|
559
|
+
optimisticUpdates: state.optimisticUpdates.filter(
|
|
560
|
+
(update) => update.id !== optimisticUpdateId
|
|
561
|
+
)
|
|
562
|
+
}));
|
|
563
|
+
}
|
|
564
|
+
);
|
|
565
|
+
}, [client]);
|
|
566
|
+
}
|
|
442
567
|
function useInboxNotificationThread_withClient(client, inboxNotificationId) {
|
|
443
568
|
const { store } = getExtrasForClient(client);
|
|
444
569
|
const selector = useCallback2(
|
|
@@ -472,17 +597,17 @@ function useUser_withClient(client, userId) {
|
|
|
472
597
|
useEffect3(() => {
|
|
473
598
|
void usersStore.get(userId);
|
|
474
599
|
}, [usersStore, userId]);
|
|
475
|
-
const
|
|
600
|
+
const selector = useCallback2(
|
|
601
|
+
(state) => selectorFor_useUser(state, userId),
|
|
602
|
+
[userId]
|
|
603
|
+
);
|
|
604
|
+
return useSyncExternalStoreWithSelector(
|
|
476
605
|
usersStore.subscribe,
|
|
477
606
|
getUserState,
|
|
478
|
-
getUserState
|
|
607
|
+
getUserState,
|
|
608
|
+
selector,
|
|
609
|
+
shallow
|
|
479
610
|
);
|
|
480
|
-
return state ? {
|
|
481
|
-
isLoading: state.isLoading,
|
|
482
|
-
user: state.data,
|
|
483
|
-
// Return an error if `undefined` was returned by `resolveUsers` for this user ID
|
|
484
|
-
error: !state.isLoading && !state.data && !state.error ? missingUserError(userId) : state.error
|
|
485
|
-
} : { isLoading: true };
|
|
486
611
|
}
|
|
487
612
|
function useUserSuspense_withClient(client, userId) {
|
|
488
613
|
const usersStore = client[kInternal].usersStore;
|
|
@@ -505,10 +630,13 @@ function useUserSuspense_withClient(client, userId) {
|
|
|
505
630
|
getUserState,
|
|
506
631
|
getUserState
|
|
507
632
|
);
|
|
633
|
+
assert(state !== void 0, "Unexpected missing state");
|
|
634
|
+
assert(!state.isLoading, "Unexpected loading state");
|
|
635
|
+
assert(!state.error, "Unexpected error state");
|
|
508
636
|
return {
|
|
509
637
|
isLoading: false,
|
|
510
|
-
user: state
|
|
511
|
-
error:
|
|
638
|
+
user: state.data,
|
|
639
|
+
error: void 0
|
|
512
640
|
};
|
|
513
641
|
}
|
|
514
642
|
function useRoomInfo_withClient(client, roomId) {
|
|
@@ -517,20 +645,20 @@ function useRoomInfo_withClient(client, roomId) {
|
|
|
517
645
|
() => roomsInfoStore.getState(roomId),
|
|
518
646
|
[roomsInfoStore, roomId]
|
|
519
647
|
);
|
|
648
|
+
const selector = useCallback2(
|
|
649
|
+
(state) => selectorFor_useRoomInfo(state, roomId),
|
|
650
|
+
[roomId]
|
|
651
|
+
);
|
|
520
652
|
useEffect3(() => {
|
|
521
653
|
void roomsInfoStore.get(roomId);
|
|
522
654
|
}, [roomsInfoStore, roomId]);
|
|
523
|
-
|
|
655
|
+
return useSyncExternalStoreWithSelector(
|
|
524
656
|
roomsInfoStore.subscribe,
|
|
525
657
|
getRoomInfoState,
|
|
526
|
-
getRoomInfoState
|
|
658
|
+
getRoomInfoState,
|
|
659
|
+
selector,
|
|
660
|
+
shallow
|
|
527
661
|
);
|
|
528
|
-
return state ? {
|
|
529
|
-
isLoading: state.isLoading,
|
|
530
|
-
info: state.data,
|
|
531
|
-
// Return an error if `undefined` was returned by `resolveRoomsInfo` for this room ID
|
|
532
|
-
error: !state.isLoading && !state.data && !state.error ? missingRoomInfoError(roomId) : state.error
|
|
533
|
-
} : { isLoading: true };
|
|
534
662
|
}
|
|
535
663
|
function useRoomInfoSuspense_withClient(client, roomId) {
|
|
536
664
|
const roomsInfoStore = client[kInternal].roomsInfoStore;
|
|
@@ -553,10 +681,14 @@ function useRoomInfoSuspense_withClient(client, roomId) {
|
|
|
553
681
|
getRoomInfoState,
|
|
554
682
|
getRoomInfoState
|
|
555
683
|
);
|
|
684
|
+
assert(state !== void 0, "Unexpected missing state");
|
|
685
|
+
assert(!state.isLoading, "Unexpected loading state");
|
|
686
|
+
assert(!state.error, "Unexpected error state");
|
|
687
|
+
assert(state.data !== void 0, "Unexpected missing room info data");
|
|
556
688
|
return {
|
|
557
689
|
isLoading: false,
|
|
558
|
-
info: state
|
|
559
|
-
error:
|
|
690
|
+
info: state.data,
|
|
691
|
+
error: void 0
|
|
560
692
|
};
|
|
561
693
|
}
|
|
562
694
|
function createSharedContext(client) {
|
|
@@ -641,6 +773,12 @@ function useMarkAllInboxNotificationsAsRead() {
|
|
|
641
773
|
function useMarkInboxNotificationAsRead() {
|
|
642
774
|
return useMarkInboxNotificationAsRead_withClient(useClient());
|
|
643
775
|
}
|
|
776
|
+
function useDeleteAllInboxNotifications() {
|
|
777
|
+
return useDeleteAllInboxNotifications_withClient(useClient());
|
|
778
|
+
}
|
|
779
|
+
function useDeleteInboxNotification() {
|
|
780
|
+
return useDeleteInboxNotification_withClient(useClient());
|
|
781
|
+
}
|
|
644
782
|
function useUnreadInboxNotificationsCount() {
|
|
645
783
|
return useUnreadInboxNotificationsCount_withClient(useClient());
|
|
646
784
|
}
|
|
@@ -777,6 +915,9 @@ function selectedThreads(roomId, state, options) {
|
|
|
777
915
|
}
|
|
778
916
|
const query = options.query;
|
|
779
917
|
if (!query) return true;
|
|
918
|
+
if (query.resolved !== void 0 && thread.resolved !== query.resolved) {
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
780
921
|
for (const key in query.metadata) {
|
|
781
922
|
const metadataValue = thread.metadata[key];
|
|
782
923
|
const filterValue = query.metadata[key];
|
|
@@ -851,33 +992,6 @@ function selectNotificationSettings(roomId, state) {
|
|
|
851
992
|
return nn(notificationSettings[roomId]);
|
|
852
993
|
}
|
|
853
994
|
|
|
854
|
-
// src/lib/use-polyfill.ts
|
|
855
|
-
var use = (
|
|
856
|
-
// React.use ||
|
|
857
|
-
(promise) => {
|
|
858
|
-
if (promise.status === "pending") {
|
|
859
|
-
throw promise;
|
|
860
|
-
} else if (promise.status === "fulfilled") {
|
|
861
|
-
return promise.value;
|
|
862
|
-
} else if (promise.status === "rejected") {
|
|
863
|
-
throw promise.reason;
|
|
864
|
-
} else {
|
|
865
|
-
promise.status = "pending";
|
|
866
|
-
promise.then(
|
|
867
|
-
(v) => {
|
|
868
|
-
promise.status = "fulfilled";
|
|
869
|
-
promise.value = v;
|
|
870
|
-
},
|
|
871
|
-
(e) => {
|
|
872
|
-
promise.status = "rejected";
|
|
873
|
-
promise.reason = e;
|
|
874
|
-
}
|
|
875
|
-
);
|
|
876
|
-
throw promise;
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
);
|
|
880
|
-
|
|
881
995
|
// src/use-scroll-to-comment-on-load-effect.ts
|
|
882
996
|
import * as React3 from "react";
|
|
883
997
|
function handleScrollToCommentOnLoad(shouldScrollOnLoad, state) {
|
|
@@ -2693,6 +2807,8 @@ export {
|
|
|
2693
2807
|
useInboxNotificationsSuspense,
|
|
2694
2808
|
useMarkAllInboxNotificationsAsRead,
|
|
2695
2809
|
useMarkInboxNotificationAsRead,
|
|
2810
|
+
useDeleteAllInboxNotifications,
|
|
2811
|
+
useDeleteInboxNotification,
|
|
2696
2812
|
useUnreadInboxNotificationsCount,
|
|
2697
2813
|
useUnreadInboxNotificationsCountSuspense,
|
|
2698
2814
|
useRoomInfo,
|
|
@@ -2754,4 +2870,4 @@ export {
|
|
|
2754
2870
|
_useStorageRoot,
|
|
2755
2871
|
_useUpdateMyPresence
|
|
2756
2872
|
};
|
|
2757
|
-
//# sourceMappingURL=chunk-
|
|
2873
|
+
//# sourceMappingURL=chunk-N2EE2UOX.mjs.map
|