@liveblocks/react 3.7.0-preview1 → 3.7.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.
@@ -491,6 +491,9 @@ function makeUserThreadsQueryKey(query) {
491
491
  function makeAiChatsQueryKey(query) {
492
492
  return stableStringify(query ?? {});
493
493
  }
494
+ function makeInboxNotificationsQueryKey(query) {
495
+ return stableStringify(query ?? {});
496
+ }
494
497
  function usify(promise) {
495
498
  if ("status" in promise) {
496
499
  return promise;
@@ -919,7 +922,6 @@ var UmbrellaStore = class {
919
922
  // Notifications
920
923
  #notificationsLastRequestedAt = null;
921
924
  // Keeps track of when we successfully requested an inbox notifications update for the last time. Will be `null` as long as the first successful fetch hasn't happened yet.
922
- #notificationsPaginationState;
923
925
  // Room Threads
924
926
  #roomThreadsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
925
927
  // User Threads
@@ -932,21 +934,6 @@ var UmbrellaStore = class {
932
934
  this.#client = client[kInternal2].as();
933
935
  this.optimisticUpdates = createStore_forOptimistic(this.#client);
934
936
  this.permissionHints = createStore_forPermissionHints();
935
- this.#notificationsPaginationState = new PaginatedResource(
936
- async (cursor) => {
937
- const result = await this.#client.getInboxNotifications({ cursor });
938
- this.updateThreadifications(
939
- result.threads,
940
- result.inboxNotifications,
941
- result.subscriptions
942
- );
943
- if (this.#notificationsLastRequestedAt === null) {
944
- this.#notificationsLastRequestedAt = result.requestedAt;
945
- }
946
- const nextCursor = result.nextCursor;
947
- return nextCursor;
948
- }
949
- );
950
937
  const notificationSettingsFetcher = async () => {
951
938
  const result = await this.#client.getNotificationSettings();
952
939
  this.notificationSettings.update(result);
@@ -1076,25 +1063,46 @@ var UmbrellaStore = class {
1076
1063
  return { signal, waitUntilLoaded: resource.waitUntilLoaded };
1077
1064
  }
1078
1065
  );
1079
- const loadingNotifications = {
1080
- signal: DerivedSignal.from(() => {
1081
- const resource = this.#notificationsPaginationState;
1082
- const result = resource.get();
1083
- if (result.isLoading || result.error) {
1084
- return result;
1085
- }
1086
- const page = result.data;
1066
+ const loadingNotifications = new DefaultMap(
1067
+ (queryKey) => {
1068
+ const query = JSON.parse(queryKey);
1069
+ const resource = new PaginatedResource(async (cursor) => {
1070
+ const result = await this.#client.getInboxNotifications({
1071
+ cursor,
1072
+ query
1073
+ });
1074
+ this.updateThreadifications(
1075
+ result.threads,
1076
+ result.inboxNotifications,
1077
+ result.subscriptions
1078
+ );
1079
+ if (this.#notificationsLastRequestedAt === null) {
1080
+ this.#notificationsLastRequestedAt = result.requestedAt;
1081
+ }
1082
+ const nextCursor = result.nextCursor;
1083
+ return nextCursor;
1084
+ });
1085
+ const signal = DerivedSignal.from(() => {
1086
+ const result = resource.get();
1087
+ if (result.isLoading || result.error) {
1088
+ return result;
1089
+ }
1090
+ const page = result.data;
1091
+ return {
1092
+ isLoading: false,
1093
+ inboxNotifications: this.outputs.notifications.get().sortedNotifications,
1094
+ hasFetchedAll: page.hasFetchedAll,
1095
+ isFetchingMore: page.isFetchingMore,
1096
+ fetchMoreError: page.fetchMoreError,
1097
+ fetchMore: page.fetchMore
1098
+ };
1099
+ }, shallow2);
1087
1100
  return {
1088
- isLoading: false,
1089
- inboxNotifications: this.outputs.notifications.get().sortedNotifications,
1090
- hasFetchedAll: page.hasFetchedAll,
1091
- isFetchingMore: page.isFetchingMore,
1092
- fetchMoreError: page.fetchMoreError,
1093
- fetchMore: page.fetchMore
1101
+ signal,
1102
+ waitUntilLoaded: resource.waitUntilLoaded
1094
1103
  };
1095
- }),
1096
- waitUntilLoaded: this.#notificationsPaginationState.waitUntilLoaded
1097
- };
1104
+ }
1105
+ );
1098
1106
  const roomSubscriptionSettingsByRoomId = new DefaultMap(
1099
1107
  (roomId) => {
1100
1108
  const resource = new SinglePageResource(async () => {
@@ -2119,7 +2127,7 @@ function makeLiveblocksContextBundle(client) {
2119
2127
  const shared = createSharedContext(client);
2120
2128
  const bundle = {
2121
2129
  LiveblocksProvider: LiveblocksProvider2,
2122
- useInboxNotifications: () => useInboxNotifications_withClient(client, identity2, shallow3),
2130
+ useInboxNotifications: (options) => useInboxNotifications_withClient(client, identity2, shallow3, options),
2123
2131
  useUnreadInboxNotificationsCount: () => useUnreadInboxNotificationsCount_withClient(client),
2124
2132
  useMarkInboxNotificationAsRead: useMarkInboxNotificationAsRead2,
2125
2133
  useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
@@ -2138,7 +2146,7 @@ function makeLiveblocksContextBundle(client) {
2138
2146
  ...shared.classic,
2139
2147
  suspense: {
2140
2148
  LiveblocksProvider: LiveblocksProvider2,
2141
- useInboxNotifications: () => useInboxNotificationsSuspense_withClient(client),
2149
+ useInboxNotifications: (options) => useInboxNotificationsSuspense_withClient(client, options),
2142
2150
  useUnreadInboxNotificationsCount: () => useUnreadInboxNotificationsCountSuspense_withClient(client),
2143
2151
  useMarkInboxNotificationAsRead: useMarkInboxNotificationAsRead2,
2144
2152
  useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
@@ -2159,10 +2167,11 @@ function makeLiveblocksContextBundle(client) {
2159
2167
  };
2160
2168
  return bundle;
2161
2169
  }
2162
- function useInboxNotifications_withClient(client, selector, isEqual) {
2170
+ function useInboxNotifications_withClient(client, selector, isEqual, options) {
2163
2171
  const { store, notificationsPoller: poller } = getLiveblocksExtrasForClient(client);
2172
+ const queryKey = makeInboxNotificationsQueryKey(options?.query);
2164
2173
  useEffect4(
2165
- () => void store.outputs.loadingNotifications.waitUntilLoaded()
2174
+ () => void store.outputs.loadingNotifications.getOrCreate(queryKey).waitUntilLoaded()
2166
2175
  // NOTE: Deliberately *not* using a dependency array here!
2167
2176
  //
2168
2177
  // It is important to call waitUntil on *every* render.
@@ -2180,16 +2189,24 @@ function useInboxNotifications_withClient(client, selector, isEqual) {
2180
2189
  };
2181
2190
  }, [poller]);
2182
2191
  return useSignal(
2183
- store.outputs.loadingNotifications.signal,
2192
+ store.outputs.loadingNotifications.getOrCreate(queryKey).signal,
2184
2193
  selector,
2185
2194
  isEqual
2186
2195
  );
2187
2196
  }
2188
- function useInboxNotificationsSuspense_withClient(client) {
2197
+ function useInboxNotificationsSuspense_withClient(client, options) {
2189
2198
  ensureNotServerSide();
2190
2199
  const store = getLiveblocksExtrasForClient(client).store;
2191
- use(store.outputs.loadingNotifications.waitUntilLoaded());
2192
- const result = useInboxNotifications_withClient(client, identity2, shallow3);
2200
+ const queryKey = makeInboxNotificationsQueryKey(options?.query);
2201
+ use(
2202
+ store.outputs.loadingNotifications.getOrCreate(queryKey).waitUntilLoaded()
2203
+ );
2204
+ const result = useInboxNotifications_withClient(
2205
+ client,
2206
+ identity2,
2207
+ shallow3,
2208
+ options
2209
+ );
2193
2210
  assert(!result.error, "Did not expect error");
2194
2211
  assert(!result.isLoading, "Did not expect loading");
2195
2212
  return result;
@@ -2204,7 +2221,10 @@ function useUnreadInboxNotificationsCount_withClient(client) {
2204
2221
  function useUnreadInboxNotificationsCountSuspense_withClient(client) {
2205
2222
  ensureNotServerSide();
2206
2223
  const store = getLiveblocksExtrasForClient(client).store;
2207
- use(store.outputs.loadingNotifications.waitUntilLoaded());
2224
+ const queryKey = makeInboxNotificationsQueryKey(void 0);
2225
+ use(
2226
+ store.outputs.loadingNotifications.getOrCreate(queryKey).waitUntilLoaded()
2227
+ );
2208
2228
  const result = useUnreadInboxNotificationsCount_withClient(client);
2209
2229
  assert(!result.isLoading, "Did not expect loading");
2210
2230
  assert(!result.error, "Did not expect error");
@@ -2898,11 +2918,16 @@ function useUserThreadsSuspense_experimental(options = {}) {
2898
2918
  assert(!result.isLoading, "Did not expect loading");
2899
2919
  return result;
2900
2920
  }
2901
- function useInboxNotifications() {
2902
- return useInboxNotifications_withClient(useClient(), identity2, shallow3);
2921
+ function useInboxNotifications(options) {
2922
+ return useInboxNotifications_withClient(
2923
+ useClient(),
2924
+ identity2,
2925
+ shallow3,
2926
+ options
2927
+ );
2903
2928
  }
2904
- function useInboxNotificationsSuspense() {
2905
- return useInboxNotificationsSuspense_withClient(useClient());
2929
+ function useInboxNotificationsSuspense(options) {
2930
+ return useInboxNotificationsSuspense_withClient(useClient(), options);
2906
2931
  }
2907
2932
  function useInboxNotificationThread(inboxNotificationId) {
2908
2933
  return useInboxNotificationThread_withClient(
@@ -4758,4 +4783,4 @@ export {
4758
4783
  _useStorageRoot,
4759
4784
  _useUpdateMyPresence
4760
4785
  };
4761
- //# sourceMappingURL=chunk-LYWCKEAX.js.map
4786
+ //# sourceMappingURL=chunk-WGUV4Z4E.js.map