@postrun/react 0.1.0 → 0.2.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/index.cjs CHANGED
@@ -98,7 +98,8 @@ var profileKeys = {
98
98
  list: (query) => [...profileKeys.lists(), query ?? {}],
99
99
  // Nested under lists() so a create/update/delete invalidating lists() also
100
100
  // refreshes the infinite cache; distinct tail so the two cache shapes (a
101
- // single Page vs accumulated pages) never collide on one key.
101
+ // single Page vs accumulated pages) never collide on one key. The filter omits
102
+ // limit/offset — the infinite hook owns pagination, so they never key the cache.
102
103
  infinite: (query) => [...profileKeys.lists(), "infinite", query ?? {}],
103
104
  details: () => [...profileKeys.all, "detail"],
104
105
  detail: (id) => [...profileKeys.details(), id]
@@ -109,20 +110,28 @@ var postKeys = {
109
110
  list: (query) => [...postKeys.lists(), query ?? {}],
110
111
  // Nested under lists() so a create/update/delete invalidating lists() also
111
112
  // refreshes the infinite cache; distinct tail so the two cache shapes (a
112
- // single Page vs accumulated pages) never collide on one key.
113
+ // single Page vs accumulated pages) never collide on one key. The filter omits
114
+ // limit/offset — the infinite hook owns pagination, so they never key the cache.
113
115
  infinite: (query) => [...postKeys.lists(), "infinite", query ?? {}],
114
116
  details: () => [...postKeys.all, "detail"],
115
117
  detail: (id) => [...postKeys.details(), id]
116
118
  };
117
119
  var mediaKeys = {
118
120
  all: [ROOT, "media"],
121
+ lists: () => [...mediaKeys.all, "list"],
122
+ list: (query) => [...mediaKeys.lists(), query ?? {}],
123
+ // Nested under lists() so an upload/update/delete invalidating lists() also
124
+ // refreshes the infinite cache; distinct tail so the two cache shapes (a
125
+ // single Page vs accumulated pages) never collide on one key. The filter omits
126
+ // limit/offset — the infinite hook owns pagination, so they never key the cache.
127
+ infinite: (query) => [...mediaKeys.lists(), "infinite", query ?? {}],
119
128
  details: () => [...mediaKeys.all, "detail"],
120
129
  detail: (id) => [...mediaKeys.details(), id]
121
130
  };
122
131
  var connectionKeys = {
123
132
  all: [ROOT, "connections"],
124
133
  lists: () => [...connectionKeys.all, "list"],
125
- list: (profileId) => [...connectionKeys.lists(), profileId],
134
+ list: (profileId, filter) => [...connectionKeys.lists(), profileId, filter ?? {}],
126
135
  details: () => [...connectionKeys.all, "detail"],
127
136
  detail: (id) => [...connectionKeys.details(), id],
128
137
  accounts: (id) => [...connectionKeys.all, "accounts", id]
@@ -211,19 +220,23 @@ function useConnect() {
211
220
  path: { id: profileId },
212
221
  body: { platform }
213
222
  })).data;
214
- navigate(session.connect_url);
223
+ navigate(session.hosted_connect_url);
215
224
  return session;
216
225
  }
217
226
  },
218
227
  queryClient
219
228
  );
220
229
  }
221
- function useConnections(profileId) {
230
+ function useConnections(profileId, filter) {
222
231
  const { client, queryClient } = usePostrun();
223
232
  return reactQuery.useQuery(
224
233
  {
225
- queryKey: connectionKeys.list(profileId),
226
- queryFn: async () => (await js.connectionsListByProfile({ client, path: { id: profileId } })).data,
234
+ queryKey: connectionKeys.list(profileId, filter),
235
+ queryFn: async () => (await js.connectionsListByProfile({
236
+ client,
237
+ path: { id: profileId },
238
+ query: filter
239
+ })).data,
227
240
  enabled: Boolean(profileId)
228
241
  },
229
242
  queryClient
@@ -408,6 +421,7 @@ function useMediaUpload() {
408
421
  controller.signal
409
422
  );
410
423
  queryClient.setQueryData(mediaKeys.detail(created.id), settled);
424
+ void queryClient.invalidateQueries({ queryKey: mediaKeys.lists() });
411
425
  setMedia(settled);
412
426
  setStatus(settled.status === "failed" ? "failed" : "ready");
413
427
  return settled;
@@ -447,12 +461,33 @@ function useMedia(id) {
447
461
  queryClient
448
462
  );
449
463
  }
464
+ function useMediaList(query) {
465
+ const { client, queryClient } = usePostrun();
466
+ return reactQuery.useQuery(
467
+ {
468
+ queryKey: mediaKeys.list(query),
469
+ queryFn: async () => (await js.mediaList({ client, query })).data
470
+ },
471
+ queryClient
472
+ );
473
+ }
474
+ function useMediaInfinite(filters, options) {
475
+ const { client } = usePostrun();
476
+ return useInfiniteList({
477
+ queryKey: mediaKeys.infinite(filters),
478
+ limit: options?.pageSize,
479
+ fetchPage: async ({ limit, offset }) => (await js.mediaList({ client, query: { ...filters, limit, offset } })).data
480
+ });
481
+ }
450
482
  function useUpdateMedia() {
451
483
  const { client, queryClient } = usePostrun();
452
484
  return reactQuery.useMutation(
453
485
  {
454
486
  mutationFn: async ({ id, ...body }) => (await js.mediaUpdate({ client, path: { id }, body })).data,
455
- onSuccess: (result, { id }) => queryClient.setQueryData(mediaKeys.detail(id), result)
487
+ onSuccess: (result, { id }) => {
488
+ queryClient.setQueryData(mediaKeys.detail(id), result);
489
+ void queryClient.invalidateQueries({ queryKey: mediaKeys.lists() });
490
+ }
456
491
  },
457
492
  queryClient
458
493
  );
@@ -462,7 +497,10 @@ function useDeleteMedia() {
462
497
  return reactQuery.useMutation(
463
498
  {
464
499
  mutationFn: async (id) => (await js.mediaDelete({ client, path: { id } })).data,
465
- onSuccess: (_result, id) => queryClient.removeQueries({ queryKey: mediaKeys.detail(id) })
500
+ onSuccess: (_result, id) => {
501
+ queryClient.removeQueries({ queryKey: mediaKeys.detail(id) });
502
+ void queryClient.invalidateQueries({ queryKey: mediaKeys.lists() });
503
+ }
466
504
  },
467
505
  queryClient
468
506
  );
@@ -1309,6 +1347,8 @@ exports.useDisconnect = useDisconnect;
1309
1347
  exports.useDiscoverableAccounts = useDiscoverableAccounts;
1310
1348
  exports.useInfiniteList = useInfiniteList;
1311
1349
  exports.useMedia = useMedia;
1350
+ exports.useMediaInfinite = useMediaInfinite;
1351
+ exports.useMediaList = useMediaList;
1312
1352
  exports.useMediaUpload = useMediaUpload;
1313
1353
  exports.usePost = usePost;
1314
1354
  exports.usePostrun = usePostrun;