@bitsocial/bitsocial-react-hooks 0.1.38 → 0.1.39

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +13 -1
  3. package/dist/hooks/feeds/feeds.d.ts +1 -1
  4. package/dist/hooks/feeds/feeds.d.ts.map +1 -1
  5. package/dist/hooks/feeds/feeds.js +25 -38
  6. package/dist/hooks/feeds/feeds.js.map +1 -1
  7. package/dist/hooks/replies.d.ts.map +1 -1
  8. package/dist/hooks/replies.js +0 -1
  9. package/dist/hooks/replies.js.map +1 -1
  10. package/dist/index.d.ts +8 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +8 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/lib/page-sorts.d.ts +8 -0
  15. package/dist/lib/page-sorts.d.ts.map +1 -0
  16. package/dist/lib/page-sorts.js +37 -0
  17. package/dist/lib/page-sorts.js.map +1 -0
  18. package/dist/lib/serialize-feed-key.d.ts +2 -0
  19. package/dist/lib/serialize-feed-key.d.ts.map +1 -0
  20. package/dist/lib/serialize-feed-key.js +5 -0
  21. package/dist/lib/serialize-feed-key.js.map +1 -0
  22. package/dist/lib/validator.d.ts.map +1 -1
  23. package/dist/lib/validator.js +5 -37
  24. package/dist/lib/validator.js.map +1 -1
  25. package/dist/lib/wordfilters.d.ts +6 -0
  26. package/dist/lib/wordfilters.d.ts.map +1 -0
  27. package/dist/lib/wordfilters.js +113 -0
  28. package/dist/lib/wordfilters.js.map +1 -0
  29. package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
  30. package/dist/stores/accounts/accounts-actions.js +66 -0
  31. package/dist/stores/accounts/accounts-actions.js.map +1 -1
  32. package/dist/stores/communities-pages/communities-pages-store.d.ts +2 -2
  33. package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -1
  34. package/dist/stores/communities-pages/communities-pages-store.js +11 -6
  35. package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
  36. package/dist/stores/feeds/feed-sorter.d.ts +1 -1
  37. package/dist/stores/feeds/feed-sorter.d.ts.map +1 -1
  38. package/dist/stores/feeds/feed-sorter.js +28 -22
  39. package/dist/stores/feeds/feed-sorter.js.map +1 -1
  40. package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
  41. package/dist/stores/feeds/feeds-store.js +2 -6
  42. package/dist/stores/feeds/feeds-store.js.map +1 -1
  43. package/dist/stores/feeds/utils.d.ts.map +1 -1
  44. package/dist/stores/feeds/utils.js +10 -22
  45. package/dist/stores/feeds/utils.js.map +1 -1
  46. package/dist/stores/replies/replies-store.d.ts.map +1 -1
  47. package/dist/stores/replies/replies-store.js +22 -5
  48. package/dist/stores/replies/replies-store.js.map +1 -1
  49. package/dist/stores/replies/utils.d.ts +1 -1
  50. package/dist/stores/replies/utils.d.ts.map +1 -1
  51. package/dist/stores/replies/utils.js +16 -89
  52. package/dist/stores/replies/utils.js.map +1 -1
  53. package/dist/stores/replies-pages/replies-pages-store.d.ts +2 -2
  54. package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -1
  55. package/dist/stores/replies-pages/replies-pages-store.js +15 -5
  56. package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
  57. package/dist/types.d.ts +23 -3
  58. package/dist/types.d.ts.map +1 -1
  59. package/dist/types.js.map +1 -1
  60. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.1.39](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.38...v0.1.39) (2026-08-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * **hooks:** add wordfilters and custom page sorts ([#91](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/91)) ([086fde9](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/086fde9b5a4c621fe7e6e9124270958cc59c4b35))
7
+
8
+
9
+
1
10
  ## [0.1.38](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.37...v0.1.38) (2026-08-20)
2
11
 
3
12
 
package/README.md CHANGED
@@ -166,7 +166,9 @@ useBufferedFeeds({feedsOptions: UseFeedOptions[]}) // preload or buffer feeds in
166
166
  ```
167
167
 
168
168
  `useFeed().reset()` clears the current feed and refreshes the latest community snapshots before rebuilding it.
169
- `useFeed().expandTimeWindow(newerThan)` broadens `newerThan` in place for feeds whose derived sort type stays the same, so older posts can be appended without replacing the feed instance.
169
+ `useFeed().expandTimeWindow(newerThan)` broadens `newerThan` in place without constructing a different sort name, so older posts can be appended without replacing the feed instance.
170
+
171
+ Feed and reply sort names are defined by each community record, not by a fixed hooks allowlist. Omit `sortType` to use the preloaded page, or discover the published names with `getAvailablePostSortTypes(community)` and `getAvailableReplySortTypes(comment)`. A requested sort that is not published is not silently replaced with another sort. Hooks preserve protocol page order for unknown custom sorts because their scoring algorithm is not available to the client.
170
172
 
171
173
  #### Actions Hooks
172
174
 
@@ -188,6 +190,8 @@ useExportCommunity(options?: UseExportCommunityOptions): {
188
190
  }
189
191
  ```
190
192
 
193
+ Before `publishComment` or `publishCommentEdit` signs a publication, hooks load the community challenge configuration and apply compatible wordfilters. The current `@bitsocial/wordfilter-challenge` contract uses a JSON array of `{src, dst}` objects in `wordfilter/v1/rules` and an optional JSON array of paths in `wordfilter/v1/fieldNames`, both published through `publicOptions`. Hooks support the user-authored `content`, `title`, and `author.displayName` paths; structural and signing fields are never rewritten by community configuration. Matching is literal and case-insensitive, not regular-expression or Unicode-evasion matching. The transformed values are the values signed, published, and stored as the pending account publication. If composed rule sets do not stabilize within eight passes, publication stops before signing.
194
+
191
195
  #### States Hooks
192
196
 
193
197
  ```
@@ -201,6 +205,8 @@ useCommunitiesStates({communities?: CommunityIdentifier[]}): {states, peers}
201
205
  usePkcRpcSettings(): {pkcRpcSettings: {pkcOptions, challenges}, setPkcRpcSettings: Function}
202
206
  ```
203
207
 
208
+ Community edits preserve challenge `publicOptions` arrays, remote community records expose their published option values, and `usePkcRpcSettings` exposes each installed challenge's `optionInputs` metadata so clients can build challenge-specific configuration without hooks knowing each challenge schema.
209
+
204
210
  #### Actions with no hooks implementations yet
205
211
 
206
212
  ```
@@ -222,6 +228,12 @@ setPkcJs(PKC) // swap the underlying protocol client implementation, e.g. for mo
222
228
  deleteDatabases() // delete all databases, including all caches and accounts data
223
229
  deleteCaches() // delete the cached comments, cached communities and cached pages only, no accounts data
224
230
  createCrosspost(comment: Comment): Crosspost // build the immutable payload accepted by pkc-js
231
+ getAvailablePostSortTypes(community: Community): string[]
232
+ getAvailableReplySortTypes(comment: Comment): string[]
233
+ getPreloadedPostSortType(community: Community): string | undefined
234
+ getPreloadedReplySortType(comment: Comment): string | undefined
235
+ resolvePostSortType(community: Community, requestedSortType?: string): string | undefined
236
+ resolveReplySortType(comment: Comment, requestedSortType?: string): string | undefined
225
237
  ```
226
238
 
227
239
  `createCrosspost` requires a fully loaded comment with `comment.cid` and
@@ -1,7 +1,7 @@
1
1
  import { UseBufferedFeedsOptions, UseBufferedFeedsResult, UseFeedOptions, UseFeedResult } from "../../types.js";
2
2
  /**
3
3
  * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]
4
- * @param sortType - The sorting algo for the feed: 'hot' | 'new' | 'active' | 'topHour' | 'topDay' | 'topWeek' | 'topMonth' | 'topYear' | 'topAll' | 'controversialHour' | 'controversialDay' | 'controversialWeek' | 'controversialMonth' | 'controversialYear' | 'controversialAll'
4
+ * @param sortType - A sort name published by the community. Omit it to use the preloaded sort.
5
5
  * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
6
6
  * the active account.
7
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"feeds.d.ts","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,EACd,aAAa,EAEd,MAAM,aAAa,CAAC;AAUrB;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CAgL/D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,sBAAsB,CA0I1F"}
1
+ {"version":3,"file":"feeds.d.ts","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,EACd,aAAa,EAEd,MAAM,aAAa,CAAC;AAWrB;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CA4K/D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,sBAAsB,CAwI1F"}
@@ -13,14 +13,14 @@ import validator from "../../lib/validator.js";
13
13
  import Logger from "@pkcprotocol/pkc-logger";
14
14
  const log = Logger("bitsocial-react-hooks:feeds:hooks");
15
15
  import assert from "assert";
16
- import { deriveFeedSortType } from "../../lib/feed-sort-type.js";
17
16
  import useFeedsStore from "../../stores/feeds/index.js";
18
17
  import { addCommentModerationToComments } from "../../lib/utils/comment-moderation.js";
19
18
  import shallow from "zustand/shallow";
20
19
  import { getCommunityRefKeys, getUniqueSortedCommunityRefs, } from "../../lib/community-ref.js";
20
+ import { serializeFeedKey } from "../../lib/serialize-feed-key.js";
21
21
  /**
22
22
  * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]
23
- * @param sortType - The sorting algo for the feed: 'hot' | 'new' | 'active' | 'topHour' | 'topDay' | 'topWeek' | 'topMonth' | 'topYear' | 'topAll' | 'controversialHour' | 'controversialDay' | 'controversialWeek' | 'controversialMonth' | 'controversialYear' | 'controversialAll'
23
+ * @param sortType - A sort name published by the community. Omit it to use the preloaded sort.
24
24
  * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
25
25
  * the active account.
26
26
  */
@@ -28,8 +28,6 @@ export function useFeed(options) {
28
28
  assert(!options || typeof options === "object", `useFeed options argument '${options}' not an object`);
29
29
  const opts = options || {};
30
30
  let { communities, sortType, accountName, postsPerPage, filter, newerThan, accountComments, modQueue, } = opts;
31
- const requestedSortType = sortType || "hot";
32
- sortType = deriveFeedSortType(sortType, newerThan);
33
31
  validator.validateUseFeedArguments({
34
32
  communities,
35
33
  communityRefs: opts.communityRefs,
@@ -58,7 +56,7 @@ export function useFeed(options) {
58
56
  return;
59
57
  }
60
58
  const isBufferedFeed = false;
61
- addFeedToStore(feedName, uniqueCommunityRefs, uniqueCommunityKeys, sortType, account, isBufferedFeed, postsPerPage, filter, newerThan, accountComments, modQueue, requestedSortType).catch((error) => log.error("useFeed addFeedToStore error", { feedName, error }));
59
+ addFeedToStore(feedName, uniqueCommunityRefs, uniqueCommunityKeys, sortType, account, isBufferedFeed, postsPerPage, filter, newerThan, accountComments, modQueue).catch((error) => log.error("useFeed addFeedToStore error", { feedName, error }));
62
60
  }, [feedName]);
63
61
  const feedKey = feedName;
64
62
  const feed = useFeedsStore((state) => state.loadedFeeds[feedKey]);
@@ -176,7 +174,7 @@ export function useBufferedFeeds(options) {
176
174
  communities: feedOptions.communities,
177
175
  communityRefs: feedOptions.communityRefs,
178
176
  communityAddresses: feedOptions.communityAddresses,
179
- sortType: deriveFeedSortType(feedOptions.sortType, feedOptions.newerThan),
177
+ sortType: feedOptions.sortType,
180
178
  accountName,
181
179
  postsPerPage: feedOptions.postsPerPage,
182
180
  filter: feedOptions.filter,
@@ -186,7 +184,7 @@ export function useBufferedFeeds(options) {
186
184
  const normalizedCommunityRefs = getUniqueSortedCommunityRefs(feedOptions.communities || []);
187
185
  communityRefsArrays.push(normalizedCommunityRefs);
188
186
  communityKeysArrays.push(getCommunityRefKeys(normalizedCommunityRefs));
189
- sortTypes.push(deriveFeedSortType(feedOptions.sortType, feedOptions.newerThan));
187
+ sortTypes.push(feedOptions.sortType);
190
188
  postsPerPages.push(feedOptions.postsPerPage);
191
189
  filters.push(feedOptions.filter);
192
190
  newerThans.push(feedOptions.newerThan);
@@ -210,10 +208,8 @@ export function useBufferedFeeds(options) {
210
208
  }, shallow);
211
209
  // add feed to store
212
210
  useEffect(() => {
213
- var _a;
214
211
  for (const [i] of communityRefsArrays.entries()) {
215
212
  const sortType = sortTypes[i];
216
- const requestedSortType = ((_a = feedsOpts[i]) === null || _a === void 0 ? void 0 : _a.sortType) || sortType;
217
213
  const uniqueCommunityRefs = communityRefsArrays[i];
218
214
  const uniqueCommunityKeys = communityKeysArrays[i];
219
215
  validator.validateFeedSortType(sortType);
@@ -223,7 +219,7 @@ export function useBufferedFeeds(options) {
223
219
  }
224
220
  if (!bufferedFeeds[feedName]) {
225
221
  const isBufferedFeed = true;
226
- addFeedToStore(feedName, uniqueCommunityRefs, uniqueCommunityKeys, sortType, account, isBufferedFeed, undefined, undefined, undefined, undefined, undefined, requestedSortType).catch((error) => log.error("useBufferedFeeds addFeedToStore error", { feedName, error }));
222
+ addFeedToStore(feedName, uniqueCommunityRefs, uniqueCommunityKeys, sortType, account, isBufferedFeed, undefined, undefined, undefined, undefined, undefined).catch((error) => log.error("useBufferedFeeds addFeedToStore error", { feedName, error }));
227
223
  }
228
224
  }
229
225
  }, [feedNames]);
@@ -263,23 +259,17 @@ function useFeedName(accountId, sortType, uniqueCommunityKeys, postsPerPage, fil
263
259
  const accountCommentsNewerThan = accountComments === null || accountComments === void 0 ? void 0 : accountComments.newerThan;
264
260
  const accountCommentsAppend = accountComments === null || accountComments === void 0 ? void 0 : accountComments.append;
265
261
  return useMemo(() => {
266
- return (accountId +
267
- "-" +
268
- sortType +
269
- "-" +
270
- uniqueCommunityKeys +
271
- "-" +
272
- postsPerPage +
273
- "-" +
274
- filterKey +
275
- "-" +
276
- newerThan +
277
- "-" +
278
- accountCommentsNewerThan +
279
- "-" +
280
- accountCommentsAppend +
281
- "-" +
282
- modQueue);
262
+ return serializeFeedKey([
263
+ accountId,
264
+ sortType,
265
+ uniqueCommunityKeys,
266
+ postsPerPage,
267
+ filterKey,
268
+ newerThan,
269
+ accountCommentsNewerThan,
270
+ accountCommentsAppend,
271
+ modQueue,
272
+ ]);
283
273
  }, [
284
274
  accountId,
285
275
  sortType,
@@ -297,17 +287,14 @@ function useFeedNames(accountId, sortTypes, uniqueCommunityKeysArrays, postsPerP
297
287
  var _a;
298
288
  const feedNames = [];
299
289
  for (const [i] of sortTypes.entries()) {
300
- feedNames.push(accountId +
301
- "-" +
302
- sortTypes[i] +
303
- "-" +
304
- uniqueCommunityKeysArrays[i] +
305
- "-" +
306
- postsPerPages[i] +
307
- "-" +
308
- ((_a = filters[i]) === null || _a === void 0 ? void 0 : _a.key) +
309
- "-" +
310
- newerThans[i]);
290
+ feedNames.push(serializeFeedKey([
291
+ accountId,
292
+ sortTypes[i],
293
+ uniqueCommunityKeysArrays[i],
294
+ postsPerPages[i],
295
+ (_a = filters[i]) === null || _a === void 0 ? void 0 : _a.key,
296
+ newerThans[i],
297
+ ]));
311
298
  }
312
299
  return feedNames;
313
300
  }, [accountId, sortTypes, uniqueCommunityKeysArrays, postsPerPages, filters, newerThans]);
@@ -1 +1 @@
1
- {"version":3,"file":"feeds.js","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,mCAAmC,CAAC,CAAC;AACxD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAU9D,OAAO,aAAa,MAAM,oBAAoB,CAAC;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YACH,wBAAwB;YACxB,GAAG;YACH,qBAAqB;YACrB,GAAG;YACH,QAAQ,CACT,CAAC;IACJ,CAAC,EAAE;QACD,SAAS;QACT,QAAQ;QACR,mBAAmB;QACnB,YAAY;QACZ,SAAS;QACT,SAAS;QACT,wBAAwB;QACxB,qBAAqB;QACrB,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAQ,EAAE;KACrB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,YAAY,CACnB,SAAiB,EACjB,SAAmB,EACnB,yBAAqC,EACrC,aAAqC,EACrC,OAAuC,EACvC,UAAkC;IAElC,OAAO,OAAO,CAAC,GAAG,EAAE;;QAClB,MAAM,SAAS,GAAa,EAAE,CAAC;QAC/B,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;YACtC,SAAS,CAAC,IAAI,CACZ,SAAS;gBACP,GAAG;gBACH,SAAS,CAAC,CAAC,CAAC;gBACZ,GAAG;gBACH,yBAAyB,CAAC,CAAC,CAAC;gBAC5B,GAAG;gBACH,aAAa,CAAC,CAAC,CAAC;gBAChB,GAAG;iBACH,MAAA,OAAO,CAAC,CAAC,CAAC,0CAAE,GAAG,CAAA;gBACf,GAAG;gBACH,UAAU,CAAC,CAAC,CAAC,CAChB,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,yBAAyB,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport { useAccount } from \"../accounts\";\nimport validator from \"../../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:hooks\");\nimport assert from \"assert\";\nimport { deriveFeedSortType } from \"../../lib/feed-sort-type\";\nimport {\n Feed,\n Feeds,\n UseBufferedFeedsOptions,\n UseBufferedFeedsResult,\n UseFeedOptions,\n UseFeedResult,\n CommentsFilter,\n} from \"../../types\";\nimport useFeedsStore from \"../../stores/feeds\";\nimport { addCommentModerationToComments } from \"../../lib/utils/comment-moderation\";\nimport shallow from \"zustand/shallow\";\nimport {\n CommunityLookupRef,\n getCommunityRefKeys,\n getUniqueSortedCommunityRefs,\n} from \"../../lib/community-ref\";\n\n/**\n * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]\n * @param sortType - The sorting algo for the feed: 'hot' | 'new' | 'active' | 'topHour' | 'topDay' | 'topWeek' | 'topMonth' | 'topYear' | 'topAll' | 'controversialHour' | 'controversialDay' | 'controversialWeek' | 'controversialMonth' | 'controversialYear' | 'controversialAll'\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useFeed(options?: UseFeedOptions): UseFeedResult {\n assert(\n !options || typeof options === \"object\",\n `useFeed options argument '${options}' not an object`,\n );\n const opts = options || {};\n let {\n communities,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n } = opts;\n const requestedSortType = sortType || \"hot\";\n sortType = deriveFeedSortType(sortType, newerThan);\n\n validator.validateUseFeedArguments({\n communities,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n });\n const account = useAccount({ accountName });\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n const incrementFeedPageNumber = useFeedsStore((state) => state.incrementFeedPageNumber);\n const expandFeedTimeWindow = useFeedsStore((state) => state.expandFeedTimeWindow);\n const resetFeed = useFeedsStore((state) => state.resetFeed);\n const normalizedCommunityRefs = useMemo(() => communities || [], [communities]);\n const uniqueCommunityRefs = useUniqueSortedCommunityRefs(normalizedCommunityRefs);\n const uniqueCommunityKeys = useMemo(\n () => getCommunityRefKeys(uniqueCommunityRefs),\n [uniqueCommunityRefs],\n );\n const feedName = useFeedName(\n account?.id,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n );\n const [errors, setErrors] = useState<Error[]>([]);\n const communityKeysWithNewerPosts = useFeedsStore(\n (state) => state.feedsCommunityKeysWithNewerPosts[feedName],\n );\n\n // add feed to store\n useEffect(() => {\n if (!uniqueCommunityRefs.length || !account) {\n return;\n }\n const isBufferedFeed = false;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n requestedSortType,\n ).catch((error: unknown) => log.error(\"useFeed addFeedToStore error\", { feedName, error }));\n }, [feedName]);\n\n const feedKey = feedName;\n const feed = useFeedsStore((state) => state.loadedFeeds[feedKey]);\n const updatedFeed = useFeedsStore((state) => state.updatedFeeds[feedKey]);\n const bufferedFeed = useFeedsStore((state) => state.bufferedFeeds[feedKey]);\n let hasMore = useFeedsStore((state) => state.feedsHaveMore[feedKey]);\n if (!feedName || typeof hasMore !== \"boolean\") {\n hasMore = true;\n }\n if (!normalizedCommunityRefs.length) {\n hasMore = false;\n }\n\n const loadMore = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot load more feed not initalized yet\");\n }\n incrementFeedPageNumber(feedName);\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n const reset = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot reset feed not initalized yet\");\n }\n await resetFeed(feedName);\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n const expandTimeWindow = async (nextNewerThan?: number) => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot expand time window before feed initialized yet\");\n }\n expandFeedTimeWindow(feedName, nextNewerThan);\n } catch (e: any) {\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useFeed\", {\n feedLength: feed?.length || 0,\n hasMore,\n communities: normalizedCommunityRefs,\n communityKeys: uniqueCommunityKeys,\n sortType,\n account,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n const state = !hasMore ? \"succeeded\" : \"fetching-ipns\";\n const normalizedFeed = useMemo(() => addCommentModerationToComments(feed), [feed]);\n const normalizedBufferedFeed = useMemo(\n () => addCommentModerationToComments(bufferedFeed),\n [bufferedFeed],\n );\n const normalizedUpdatedFeed = useMemo(\n () => addCommentModerationToComments(updatedFeed),\n [updatedFeed],\n );\n\n return useMemo(\n () => ({\n feed: normalizedFeed,\n bufferedFeed: normalizedBufferedFeed,\n updatedFeed: normalizedUpdatedFeed,\n hasMore,\n communityKeysWithNewerPosts: communityKeysWithNewerPosts || [],\n loadMore,\n expandTimeWindow,\n reset,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n normalizedFeed,\n normalizedBufferedFeed,\n normalizedUpdatedFeed,\n feedName,\n hasMore,\n errors,\n communityKeysWithNewerPosts,\n ],\n );\n}\n\n/**\n * Use useBufferedFeeds to buffer multiple feeds in the background so what when\n * they are called by useFeed later, they are already preloaded.\n *\n * @param feedOptions - The options of the feed\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useBufferedFeeds(options?: UseBufferedFeedsOptions): UseBufferedFeedsResult {\n assert(\n !options || typeof options === \"object\",\n `useBufferedFeeds options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { feedsOptions = [], accountName } = opts;\n validator.validateUseBufferedFeedsArguments({ feedsOptions, accountName });\n const account = useAccount({ accountName });\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n\n // do a bunch of calculations to get feedsOptionsFlattened and feedNames\n const feedsOpts = feedsOptions;\n const {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n } = useMemo(() => {\n const communityRefsArrays: CommunityLookupRef[][] = [];\n const communityKeysArrays: string[][] = [];\n const sortTypes: string[] = [];\n const postsPerPages: (number | undefined)[] = [];\n const filters: (CommentsFilter | undefined)[] = [];\n const newerThans: (number | undefined)[] = [];\n for (const feedOptions of feedsOpts) {\n validator.validateUseFeedArguments({\n communities: feedOptions.communities,\n communityRefs: (feedOptions as any).communityRefs,\n communityAddresses: (feedOptions as any).communityAddresses,\n sortType: deriveFeedSortType(feedOptions.sortType, feedOptions.newerThan),\n accountName,\n postsPerPage: feedOptions.postsPerPage,\n filter: feedOptions.filter,\n newerThan: feedOptions.newerThan,\n accountComments: feedOptions.accountComments,\n });\n const normalizedCommunityRefs = getUniqueSortedCommunityRefs(feedOptions.communities || []);\n communityRefsArrays.push(normalizedCommunityRefs);\n communityKeysArrays.push(getCommunityRefKeys(normalizedCommunityRefs));\n sortTypes.push(deriveFeedSortType(feedOptions.sortType, feedOptions.newerThan));\n postsPerPages.push(feedOptions.postsPerPage);\n filters.push(feedOptions.filter);\n newerThans.push(feedOptions.newerThan);\n }\n return {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n };\n }, [feedsOpts]);\n const feedNames = useFeedNames(\n account?.id,\n sortTypes,\n communityKeysArrays,\n postsPerPages,\n filters,\n newerThans,\n );\n\n const bufferedFeeds = useFeedsStore((state) => {\n const bufferedFeeds: Feeds = {};\n for (const feedName of feedNames) {\n bufferedFeeds[feedName] = state.bufferedFeeds[feedName];\n }\n return bufferedFeeds;\n }, shallow);\n\n // add feed to store\n useEffect(() => {\n for (const [i] of communityRefsArrays.entries()) {\n const sortType = sortTypes[i];\n const requestedSortType = feedsOpts[i]?.sortType || sortType;\n const uniqueCommunityRefs = communityRefsArrays[i];\n const uniqueCommunityKeys = communityKeysArrays[i];\n validator.validateFeedSortType(sortType);\n const feedName = feedNames[i];\n if (!account || !uniqueCommunityRefs.length) {\n continue;\n }\n if (!bufferedFeeds[feedName]) {\n const isBufferedFeed = true;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n undefined,\n undefined,\n undefined,\n undefined,\n undefined,\n requestedSortType,\n ).catch((error: unknown) =>\n log.error(\"useBufferedFeeds addFeedToStore error\", { feedName, error }),\n );\n }\n }\n }, [feedNames]);\n\n // only give to the user the buffered feeds he requested\n const bufferedFeedsArray: Feed[] = useMemo(() => {\n const bufferedFeedsArray: Feed[] = [];\n for (const feedName of feedNames) {\n bufferedFeedsArray.push(addCommentModerationToComments(bufferedFeeds[feedName]));\n }\n return bufferedFeedsArray;\n }, [bufferedFeeds, feedNames]);\n\n if (account && feedsOptions?.length) {\n log(\"useBufferedFeeds\", {\n bufferedFeeds,\n feedsOptions,\n account,\n accountName,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n const state = \"fetching-ipns\";\n\n return useMemo(\n () => ({\n bufferedFeeds: bufferedFeedsArray,\n state,\n error: undefined,\n errors: [],\n }),\n [bufferedFeedsArray, feedsOptions],\n );\n}\n\nfunction useUniqueSortedCommunityRefs(communityRefs?: CommunityLookupRef[]) {\n return useMemo(() => {\n return getUniqueSortedCommunityRefs(communityRefs);\n }, [communityRefs]);\n}\n\nfunction useFeedName(\n accountId: string,\n sortType: string,\n uniqueCommunityKeys: string[],\n postsPerPage?: number,\n filter?: CommentsFilter,\n newerThan?: number,\n accountComments?: UseFeedOptions[\"accountComments\"],\n modQueue?: string[],\n) {\n const filterKey = filter?.key;\n const accountCommentsNewerThan = accountComments?.newerThan;\n const accountCommentsAppend = accountComments?.append;\n return useMemo(() => {\n return (\n accountId +\n \"-\" +\n sortType +\n \"-\" +\n uniqueCommunityKeys +\n \"-\" +\n postsPerPage +\n \"-\" +\n filterKey +\n \"-\" +\n newerThan +\n \"-\" +\n accountCommentsNewerThan +\n \"-\" +\n accountCommentsAppend +\n \"-\" +\n modQueue\n );\n }, [\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n modQueue?.toString(),\n ]);\n}\n\nfunction useFeedNames(\n accountId: string,\n sortTypes: string[],\n uniqueCommunityKeysArrays: string[][],\n postsPerPages: (number | undefined)[],\n filters: (CommentsFilter | undefined)[],\n newerThans: (number | undefined)[],\n) {\n return useMemo(() => {\n const feedNames: string[] = [];\n for (const [i] of sortTypes.entries()) {\n feedNames.push(\n accountId +\n \"-\" +\n sortTypes[i] +\n \"-\" +\n uniqueCommunityKeysArrays[i] +\n \"-\" +\n postsPerPages[i] +\n \"-\" +\n filters[i]?.key +\n \"-\" +\n newerThans[i],\n );\n }\n return feedNames;\n }, [accountId, sortTypes, uniqueCommunityKeysArrays, postsPerPages, filters, newerThans]);\n}\n"]}
1
+ {"version":3,"file":"feeds.js","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,mCAAmC,CAAC,CAAC;AACxD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAU5B,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAEL,mBAAmB,EACnB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CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;YACtC,SAAS,CAAC,IAAI,CACZ,gBAAgB,CAAC;gBACf,SAAS;gBACT,SAAS,CAAC,CAAC,CAAC;gBACZ,yBAAyB,CAAC,CAAC,CAAC;gBAC5B,aAAa,CAAC,CAAC,CAAC;gBAChB,MAAA,OAAO,CAAC,CAAC,CAAC,0CAAE,GAAG;gBACf,UAAU,CAAC,CAAC,CAAC;aACd,CAAC,CACH,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,yBAAyB,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport { useAccount } from \"../accounts\";\nimport validator from \"../../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:hooks\");\nimport assert from \"assert\";\nimport {\n Feed,\n Feeds,\n UseBufferedFeedsOptions,\n UseBufferedFeedsResult,\n UseFeedOptions,\n UseFeedResult,\n CommentsFilter,\n} from \"../../types\";\nimport useFeedsStore from \"../../stores/feeds\";\nimport { addCommentModerationToComments } from \"../../lib/utils/comment-moderation\";\nimport shallow from \"zustand/shallow\";\nimport {\n CommunityLookupRef,\n getCommunityRefKeys,\n getUniqueSortedCommunityRefs,\n} from \"../../lib/community-ref\";\nimport { serializeFeedKey } from \"../../lib/serialize-feed-key\";\n\n/**\n * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]\n * @param sortType - A sort name published by the community. Omit it to use the preloaded sort.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useFeed(options?: UseFeedOptions): UseFeedResult {\n assert(\n !options || typeof options === \"object\",\n `useFeed options argument '${options}' not an object`,\n );\n const opts = options || {};\n let {\n communities,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n } = opts;\n validator.validateUseFeedArguments({\n communities,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n });\n const account = useAccount({ accountName });\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n const incrementFeedPageNumber = useFeedsStore((state) => state.incrementFeedPageNumber);\n const expandFeedTimeWindow = useFeedsStore((state) => state.expandFeedTimeWindow);\n const resetFeed = useFeedsStore((state) => state.resetFeed);\n const normalizedCommunityRefs = useMemo(() => communities || [], [communities]);\n const uniqueCommunityRefs = useUniqueSortedCommunityRefs(normalizedCommunityRefs);\n const uniqueCommunityKeys = useMemo(\n () => getCommunityRefKeys(uniqueCommunityRefs),\n [uniqueCommunityRefs],\n );\n const feedName = useFeedName(\n account?.id,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n );\n const [errors, setErrors] = useState<Error[]>([]);\n const communityKeysWithNewerPosts = useFeedsStore(\n (state) => state.feedsCommunityKeysWithNewerPosts[feedName],\n );\n\n // add feed to store\n useEffect(() => {\n if (!uniqueCommunityRefs.length || !account) {\n return;\n }\n const isBufferedFeed = false;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n ).catch((error: unknown) => log.error(\"useFeed addFeedToStore error\", { feedName, error }));\n }, [feedName]);\n\n const feedKey = feedName;\n const feed = useFeedsStore((state) => state.loadedFeeds[feedKey]);\n const updatedFeed = useFeedsStore((state) => state.updatedFeeds[feedKey]);\n const bufferedFeed = useFeedsStore((state) => state.bufferedFeeds[feedKey]);\n let hasMore = useFeedsStore((state) => state.feedsHaveMore[feedKey]);\n if (!feedName || typeof hasMore !== \"boolean\") {\n hasMore = true;\n }\n if (!normalizedCommunityRefs.length) {\n hasMore = false;\n }\n\n const loadMore = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot load more feed not initalized yet\");\n }\n incrementFeedPageNumber(feedName);\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n const reset = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot reset feed not initalized yet\");\n }\n await resetFeed(feedName);\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n const expandTimeWindow = async (nextNewerThan?: number) => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot expand time window before feed initialized yet\");\n }\n expandFeedTimeWindow(feedName, nextNewerThan);\n } catch (e: any) {\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useFeed\", {\n feedLength: feed?.length || 0,\n hasMore,\n communities: normalizedCommunityRefs,\n communityKeys: uniqueCommunityKeys,\n sortType,\n account,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n const state = !hasMore ? \"succeeded\" : \"fetching-ipns\";\n const normalizedFeed = useMemo(() => addCommentModerationToComments(feed), [feed]);\n const normalizedBufferedFeed = useMemo(\n () => addCommentModerationToComments(bufferedFeed),\n [bufferedFeed],\n );\n const normalizedUpdatedFeed = useMemo(\n () => addCommentModerationToComments(updatedFeed),\n [updatedFeed],\n );\n\n return useMemo(\n () => ({\n feed: normalizedFeed,\n bufferedFeed: normalizedBufferedFeed,\n updatedFeed: normalizedUpdatedFeed,\n hasMore,\n communityKeysWithNewerPosts: communityKeysWithNewerPosts || [],\n loadMore,\n expandTimeWindow,\n reset,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n normalizedFeed,\n normalizedBufferedFeed,\n normalizedUpdatedFeed,\n feedName,\n hasMore,\n errors,\n communityKeysWithNewerPosts,\n ],\n );\n}\n\n/**\n * Use useBufferedFeeds to buffer multiple feeds in the background so what when\n * they are called by useFeed later, they are already preloaded.\n *\n * @param feedOptions - The options of the feed\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useBufferedFeeds(options?: UseBufferedFeedsOptions): UseBufferedFeedsResult {\n assert(\n !options || typeof options === \"object\",\n `useBufferedFeeds options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { feedsOptions = [], accountName } = opts;\n validator.validateUseBufferedFeedsArguments({ feedsOptions, accountName });\n const account = useAccount({ accountName });\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n\n // do a bunch of calculations to get feedsOptionsFlattened and feedNames\n const feedsOpts = feedsOptions;\n const {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n } = useMemo(() => {\n const communityRefsArrays: CommunityLookupRef[][] = [];\n const communityKeysArrays: string[][] = [];\n const sortTypes: (string | undefined)[] = [];\n const postsPerPages: (number | undefined)[] = [];\n const filters: (CommentsFilter | undefined)[] = [];\n const newerThans: (number | undefined)[] = [];\n for (const feedOptions of feedsOpts) {\n validator.validateUseFeedArguments({\n communities: feedOptions.communities,\n communityRefs: (feedOptions as any).communityRefs,\n communityAddresses: (feedOptions as any).communityAddresses,\n sortType: feedOptions.sortType,\n accountName,\n postsPerPage: feedOptions.postsPerPage,\n filter: feedOptions.filter,\n newerThan: feedOptions.newerThan,\n accountComments: feedOptions.accountComments,\n });\n const normalizedCommunityRefs = getUniqueSortedCommunityRefs(feedOptions.communities || []);\n communityRefsArrays.push(normalizedCommunityRefs);\n communityKeysArrays.push(getCommunityRefKeys(normalizedCommunityRefs));\n sortTypes.push(feedOptions.sortType);\n postsPerPages.push(feedOptions.postsPerPage);\n filters.push(feedOptions.filter);\n newerThans.push(feedOptions.newerThan);\n }\n return {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n };\n }, [feedsOpts]);\n const feedNames = useFeedNames(\n account?.id,\n sortTypes,\n communityKeysArrays,\n postsPerPages,\n filters,\n newerThans,\n );\n\n const bufferedFeeds = useFeedsStore((state) => {\n const bufferedFeeds: Feeds = {};\n for (const feedName of feedNames) {\n bufferedFeeds[feedName] = state.bufferedFeeds[feedName];\n }\n return bufferedFeeds;\n }, shallow);\n\n // add feed to store\n useEffect(() => {\n for (const [i] of communityRefsArrays.entries()) {\n const sortType = sortTypes[i];\n const uniqueCommunityRefs = communityRefsArrays[i];\n const uniqueCommunityKeys = communityKeysArrays[i];\n validator.validateFeedSortType(sortType);\n const feedName = feedNames[i];\n if (!account || !uniqueCommunityRefs.length) {\n continue;\n }\n if (!bufferedFeeds[feedName]) {\n const isBufferedFeed = true;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n undefined,\n undefined,\n undefined,\n undefined,\n undefined,\n ).catch((error: unknown) =>\n log.error(\"useBufferedFeeds addFeedToStore error\", { feedName, error }),\n );\n }\n }\n }, [feedNames]);\n\n // only give to the user the buffered feeds he requested\n const bufferedFeedsArray: Feed[] = useMemo(() => {\n const bufferedFeedsArray: Feed[] = [];\n for (const feedName of feedNames) {\n bufferedFeedsArray.push(addCommentModerationToComments(bufferedFeeds[feedName]));\n }\n return bufferedFeedsArray;\n }, [bufferedFeeds, feedNames]);\n\n if (account && feedsOptions?.length) {\n log(\"useBufferedFeeds\", {\n bufferedFeeds,\n feedsOptions,\n account,\n accountName,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n const state = \"fetching-ipns\";\n\n return useMemo(\n () => ({\n bufferedFeeds: bufferedFeedsArray,\n state,\n error: undefined,\n errors: [],\n }),\n [bufferedFeedsArray, feedsOptions],\n );\n}\n\nfunction useUniqueSortedCommunityRefs(communityRefs?: CommunityLookupRef[]) {\n return useMemo(() => {\n return getUniqueSortedCommunityRefs(communityRefs);\n }, [communityRefs]);\n}\n\nfunction useFeedName(\n accountId: string,\n sortType: string | undefined,\n uniqueCommunityKeys: string[],\n postsPerPage?: number,\n filter?: CommentsFilter,\n newerThan?: number,\n accountComments?: UseFeedOptions[\"accountComments\"],\n modQueue?: string[],\n) {\n const filterKey = filter?.key;\n const accountCommentsNewerThan = accountComments?.newerThan;\n const accountCommentsAppend = accountComments?.append;\n return useMemo(() => {\n return serializeFeedKey([\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n modQueue,\n ]);\n }, [\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n modQueue?.toString(),\n ]);\n}\n\nfunction useFeedNames(\n accountId: string,\n sortTypes: (string | undefined)[],\n uniqueCommunityKeysArrays: string[][],\n postsPerPages: (number | undefined)[],\n filters: (CommentsFilter | undefined)[],\n newerThans: (number | undefined)[],\n) {\n return useMemo(() => {\n const feedNames: string[] = [];\n for (const [i] of sortTypes.entries()) {\n feedNames.push(\n serializeFeedKey([\n accountId,\n sortTypes[i],\n uniqueCommunityKeysArrays[i],\n postsPerPages[i],\n filters[i]?.key,\n newerThans[i],\n ]),\n );\n }\n return feedNames;\n }, [accountId, sortTypes, uniqueCommunityKeysArrays, postsPerPages, filters, newerThans]);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"replies.d.ts","sourceRoot":"","sources":["../../src/hooks/replies.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAU/D,yHAAyH;AACzH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,CAE1E;AAED,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,gBAAgB,CAqMxE"}
1
+ {"version":3,"file":"replies.d.ts","sourceRoot":"","sources":["../../src/hooks/replies.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAU/D,yHAAyH;AACzH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,CAE1E;AAED,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,gBAAgB,CAoMxE"}
@@ -26,7 +26,6 @@ export function useReplies(options) {
26
26
  assert(!options || typeof options === "object", `useReplies options argument '${options}' not an object`);
27
27
  const opts = options !== null && options !== void 0 ? options : {};
28
28
  let { comment, sortType, accountName, onlyIfCached, flat, flatDepth, accountComments, repliesPerPage, filter, validateOptimistically, streamPage, } = opts;
29
- sortType = sortType || "best";
30
29
  flatDepth = typeof flatDepth === "number" ? flatDepth : 0;
31
30
  validateOptimistically = validateOptimistically !== false;
32
31
  const invalidFlatDepth = flat && typeof (comment === null || comment === void 0 ? void 0 : comment.depth) === "number" && flatDepth !== comment.depth;
@@ -1 +1 @@
1
- {"version":3,"file":"replies.js","sourceRoot":"","sources":["../../src/hooks/replies.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,qCAAqC,CAAC,CAAC;AAC1D,OAAO,MAAM,M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,eAAe,CAAC,EAC/C,YAAY,CACb,EACH,CAAC,eAAe,EAAE,YAAY,CAAC,CAChC,CAAC;IACF,MAAM,wBAAwB,GAAG,OAAO,CACtC,GAAG,EAAE,CACH,iCAAiC,CAC/B,8BAA8B,CAAC,cAAc,CAAC,EAC9C,YAAY,CACb,EACH,CAAC,cAAc,EAAE,YAAY,CAAC,CAC/B,CAAC;IAEF,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,OAAO,EAAE,iBAAiB;QAC1B,eAAe,EAAE,yBAAyB;QAC1C,cAAc,EAAE,wBAAwB;QACxC,OAAO;QACP,QAAQ;QACR,KAAK;QACL,KAAK;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,MAAM;KACP,CAAC,EACF;QACE,iBAAiB;QACjB,yBAAyB;QACzB,wBAAwB;QACxB,eAAe;QACf,OAAO;QACP,MAAM;KACP,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAQ,EAAE,CAAC;AAC3B,MAAM,aAAa,GAAG,GAAS,EAAE,kDAAE,CAAC,CAAA,CAAC","sourcesContent":["import { useEffect, useState, useMemo } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:replies:hooks\");\nimport assert from \"assert\";\nimport { UseRepliesOptions, UseRepliesResult } from \"../types\";\nimport { addCommentModerationToComments } from \"../lib/utils/comment-moderation\";\nimport useRepliesStore, {\n RepliesState,\n feedOptionsToFeedName,\n getRepliesFirstPageSkipValidation,\n} from \"../stores/replies\";\nimport useAccountsStore from \"../stores/accounts\";\nimport { addOptimisticVoteCountsToComments } from \"../lib/utils/optimistic-vote-counts\";\n\n/** Pure helper to append an error to the errors array; used for deterministic coverage of reset/loadMore catch paths. */\nexport function appendErrorToErrors(prevErrors: Error[], e: Error): Error[] {\n return [...prevErrors, e];\n}\n\nexport function useReplies(options?: UseRepliesOptions): UseRepliesResult {\n assert(\n !options || typeof options === \"object\",\n `useReplies options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n let {\n comment,\n sortType,\n accountName,\n onlyIfCached,\n flat,\n flatDepth,\n accountComments,\n repliesPerPage,\n filter,\n validateOptimistically,\n streamPage,\n } = opts;\n sortType = sortType || \"best\";\n flatDepth = typeof flatDepth === \"number\" ? flatDepth : 0;\n validateOptimistically = validateOptimistically !== false;\n const invalidFlatDepth =\n flat && typeof comment?.depth === \"number\" && flatDepth !== comment.depth;\n validator.validateUseRepliesArguments(\n comment,\n sortType,\n accountName,\n onlyIfCached,\n flat,\n accountComments,\n repliesPerPage,\n filter,\n );\n\n const [errors, setErrors] = useState<Error[]>([]);\n\n // add replies to store\n const account = useAccount({ accountName });\n const accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const feedOptions = {\n commentCid: comment?.cid,\n commentDepth: comment?.depth,\n postCid: comment?.postCid,\n sortType,\n accountId: account?.id,\n onlyIfCached,\n repliesPerPage,\n flat,\n accountComments,\n filter,\n streamPage,\n };\n const repliesFeedName = feedOptionsToFeedName(feedOptions);\n const addFeedToStoreOrUpdateComment = useRepliesStore(\n (state: RepliesState) => state.addFeedToStoreOrUpdateComment,\n );\n useEffect(() => {\n if (!comment?.cid || !account || invalidFlatDepth) {\n return;\n }\n addFeedToStoreOrUpdateComment(comment, feedOptions).catch((error: unknown) =>\n log.error(\"useReplies addFeedToStoreOrUpdateComment error\", {\n repliesFeedName,\n comment,\n feedOptions,\n error,\n }),\n );\n }, [repliesFeedName, comment]);\n\n let replies = useRepliesStore((state: RepliesState) => state.loadedFeeds[repliesFeedName || \"\"]);\n let bufferedReplies = useRepliesStore(\n (state: RepliesState) => state.bufferedFeeds[repliesFeedName || \"\"],\n );\n let updatedReplies = useRepliesStore(\n (state: RepliesState) => state.updatedFeeds[repliesFeedName || \"\"],\n );\n let hasMore = useRepliesStore(\n (state: RepliesState) => state.feedsHaveMore[repliesFeedName || \"\"],\n );\n hasMore = comment\n ? repliesFeedName && typeof hasMore === \"boolean\"\n ? hasMore\n : !onlyIfCached\n : false;\n\n const incrementFeedPageNumber = useRepliesStore(\n (state: RepliesState) => state.incrementFeedPageNumber,\n );\n let loadMore = async () => {\n try {\n if (!comment?.cid || !account) {\n throw Error(\"useReplies cannot load more replies not initalized yet\");\n }\n incrementFeedPageNumber(repliesFeedName);\n } catch (e: any) {\n await new Promise((r) => setTimeout(r, 50));\n setErrors(appendErrorToErrors(errors, e));\n }\n };\n\n const resetFeed = useRepliesStore((state: RepliesState) => state.resetFeed);\n let reset = async () => {\n try {\n if (!comment?.cid || !account) {\n throw Error(\"useReplies cannot reset replies not initalized yet\");\n }\n resetFeed(repliesFeedName);\n } catch (e: any) {\n await new Promise((r) => setTimeout(r, 50));\n setErrors(appendErrorToErrors(errors, e));\n }\n };\n\n // optimistically avoid the initial validation delay by using skipped validation until validated feed is loaded\n const skipValidation = useMemo(() => {\n if (validateOptimistically && !replies && comment?.cid && account?.id) {\n return getRepliesFirstPageSkipValidation(comment, feedOptions);\n }\n }, [validateOptimistically, replies, comment?.cid, account?.id, comment, repliesFeedName]);\n if (validateOptimistically && !replies && skipValidation?.replies?.length) {\n replies = skipValidation.replies;\n hasMore = skipValidation.hasMore;\n }\n\n // don't display nested replies when flat\n // to start flat replies at a depth other than 0, e.g. a twitter reply thread, change flatDepth\n if (invalidFlatDepth) {\n replies = emptyArray;\n bufferedReplies = emptyArray;\n updatedReplies = emptyArray;\n hasMore = false;\n loadMore = emptyFunction;\n reset = emptyFunction;\n }\n\n if (account && comment?.cid) {\n log(\"useReplies\", {\n repliesLength: replies?.length || 0,\n hasMore,\n comment,\n sortType,\n onlyIfCached,\n flat,\n flatDepth,\n repliesStoreOptions: useRepliesStore.getState().feedsOptions,\n repliesStore: useRepliesStore.getState(),\n invalidFlatDepth,\n });\n }\n\n const state = !hasMore ? \"succeeded\" : \"fetching\";\n const normalizedReplies = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(replies), accountVotes),\n [replies, accountVotes],\n );\n const normalizedBufferedReplies = useMemo(\n () =>\n addOptimisticVoteCountsToComments(\n addCommentModerationToComments(bufferedReplies),\n accountVotes,\n ),\n [bufferedReplies, accountVotes],\n );\n const normalizedUpdatedReplies = useMemo(\n () =>\n addOptimisticVoteCountsToComments(\n addCommentModerationToComments(updatedReplies),\n accountVotes,\n ),\n [updatedReplies, accountVotes],\n );\n\n return useMemo(\n () => ({\n replies: normalizedReplies,\n bufferedReplies: normalizedBufferedReplies,\n updatedReplies: normalizedUpdatedReplies,\n hasMore,\n loadMore,\n reset,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n normalizedReplies,\n normalizedBufferedReplies,\n normalizedUpdatedReplies,\n repliesFeedName,\n hasMore,\n errors,\n ],\n );\n}\n\nconst emptyArray: any = [];\nconst emptyFunction = async () => {};\n"]}
1
+ {"version":3,"file":"replies.js","sourceRoot":"","sources":["../../src/hooks/replies.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,qCAAqC,CAAC,CAAC;AAC1D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,eAAe,EAAE,EAEtB,qBAAqB,EACrB,iCAAiC,GAClC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,yHAAyH;AACzH,MAAM,UAAU,mBAAm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,yBAAyB;QAC1C,cAAc,EAAE,wBAAwB;QACxC,OAAO;QACP,QAAQ;QACR,KAAK;QACL,KAAK;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,MAAM;KACP,CAAC,EACF;QACE,iBAAiB;QACjB,yBAAyB;QACzB,wBAAwB;QACxB,eAAe;QACf,OAAO;QACP,MAAM;KACP,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAQ,EAAE,CAAC;AAC3B,MAAM,aAAa,GAAG,GAAS,EAAE,kDAAE,CAAC,CAAA,CAAC","sourcesContent":["import { useEffect, useState, useMemo } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:replies:hooks\");\nimport assert from \"assert\";\nimport { UseRepliesOptions, UseRepliesResult } from \"../types\";\nimport { addCommentModerationToComments } from \"../lib/utils/comment-moderation\";\nimport useRepliesStore, {\n RepliesState,\n feedOptionsToFeedName,\n getRepliesFirstPageSkipValidation,\n} from \"../stores/replies\";\nimport useAccountsStore from \"../stores/accounts\";\nimport { addOptimisticVoteCountsToComments } from \"../lib/utils/optimistic-vote-counts\";\n\n/** Pure helper to append an error to the errors array; used for deterministic coverage of reset/loadMore catch paths. */\nexport function appendErrorToErrors(prevErrors: Error[], e: Error): Error[] {\n return [...prevErrors, e];\n}\n\nexport function useReplies(options?: UseRepliesOptions): UseRepliesResult {\n assert(\n !options || typeof options === \"object\",\n `useReplies options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n let {\n comment,\n sortType,\n accountName,\n onlyIfCached,\n flat,\n flatDepth,\n accountComments,\n repliesPerPage,\n filter,\n validateOptimistically,\n streamPage,\n } = opts;\n flatDepth = typeof flatDepth === \"number\" ? flatDepth : 0;\n validateOptimistically = validateOptimistically !== false;\n const invalidFlatDepth =\n flat && typeof comment?.depth === \"number\" && flatDepth !== comment.depth;\n validator.validateUseRepliesArguments(\n comment,\n sortType,\n accountName,\n onlyIfCached,\n flat,\n accountComments,\n repliesPerPage,\n filter,\n );\n\n const [errors, setErrors] = useState<Error[]>([]);\n\n // add replies to store\n const account = useAccount({ accountName });\n const accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const feedOptions = {\n commentCid: comment?.cid,\n commentDepth: comment?.depth,\n postCid: comment?.postCid,\n sortType,\n accountId: account?.id,\n onlyIfCached,\n repliesPerPage,\n flat,\n accountComments,\n filter,\n streamPage,\n };\n const repliesFeedName = feedOptionsToFeedName(feedOptions);\n const addFeedToStoreOrUpdateComment = useRepliesStore(\n (state: RepliesState) => state.addFeedToStoreOrUpdateComment,\n );\n useEffect(() => {\n if (!comment?.cid || !account || invalidFlatDepth) {\n return;\n }\n addFeedToStoreOrUpdateComment(comment, feedOptions).catch((error: unknown) =>\n log.error(\"useReplies addFeedToStoreOrUpdateComment error\", {\n repliesFeedName,\n comment,\n feedOptions,\n error,\n }),\n );\n }, [repliesFeedName, comment]);\n\n let replies = useRepliesStore((state: RepliesState) => state.loadedFeeds[repliesFeedName || \"\"]);\n let bufferedReplies = useRepliesStore(\n (state: RepliesState) => state.bufferedFeeds[repliesFeedName || \"\"],\n );\n let updatedReplies = useRepliesStore(\n (state: RepliesState) => state.updatedFeeds[repliesFeedName || \"\"],\n );\n let hasMore = useRepliesStore(\n (state: RepliesState) => state.feedsHaveMore[repliesFeedName || \"\"],\n );\n hasMore = comment\n ? repliesFeedName && typeof hasMore === \"boolean\"\n ? hasMore\n : !onlyIfCached\n : false;\n\n const incrementFeedPageNumber = useRepliesStore(\n (state: RepliesState) => state.incrementFeedPageNumber,\n );\n let loadMore = async () => {\n try {\n if (!comment?.cid || !account) {\n throw Error(\"useReplies cannot load more replies not initalized yet\");\n }\n incrementFeedPageNumber(repliesFeedName);\n } catch (e: any) {\n await new Promise((r) => setTimeout(r, 50));\n setErrors(appendErrorToErrors(errors, e));\n }\n };\n\n const resetFeed = useRepliesStore((state: RepliesState) => state.resetFeed);\n let reset = async () => {\n try {\n if (!comment?.cid || !account) {\n throw Error(\"useReplies cannot reset replies not initalized yet\");\n }\n resetFeed(repliesFeedName);\n } catch (e: any) {\n await new Promise((r) => setTimeout(r, 50));\n setErrors(appendErrorToErrors(errors, e));\n }\n };\n\n // optimistically avoid the initial validation delay by using skipped validation until validated feed is loaded\n const skipValidation = useMemo(() => {\n if (validateOptimistically && !replies && comment?.cid && account?.id) {\n return getRepliesFirstPageSkipValidation(comment, feedOptions);\n }\n }, [validateOptimistically, replies, comment?.cid, account?.id, comment, repliesFeedName]);\n if (validateOptimistically && !replies && skipValidation?.replies?.length) {\n replies = skipValidation.replies;\n hasMore = skipValidation.hasMore;\n }\n\n // don't display nested replies when flat\n // to start flat replies at a depth other than 0, e.g. a twitter reply thread, change flatDepth\n if (invalidFlatDepth) {\n replies = emptyArray;\n bufferedReplies = emptyArray;\n updatedReplies = emptyArray;\n hasMore = false;\n loadMore = emptyFunction;\n reset = emptyFunction;\n }\n\n if (account && comment?.cid) {\n log(\"useReplies\", {\n repliesLength: replies?.length || 0,\n hasMore,\n comment,\n sortType,\n onlyIfCached,\n flat,\n flatDepth,\n repliesStoreOptions: useRepliesStore.getState().feedsOptions,\n repliesStore: useRepliesStore.getState(),\n invalidFlatDepth,\n });\n }\n\n const state = !hasMore ? \"succeeded\" : \"fetching\";\n const normalizedReplies = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(replies), accountVotes),\n [replies, accountVotes],\n );\n const normalizedBufferedReplies = useMemo(\n () =>\n addOptimisticVoteCountsToComments(\n addCommentModerationToComments(bufferedReplies),\n accountVotes,\n ),\n [bufferedReplies, accountVotes],\n );\n const normalizedUpdatedReplies = useMemo(\n () =>\n addOptimisticVoteCountsToComments(\n addCommentModerationToComments(updatedReplies),\n accountVotes,\n ),\n [updatedReplies, accountVotes],\n );\n\n return useMemo(\n () => ({\n replies: normalizedReplies,\n bufferedReplies: normalizedBufferedReplies,\n updatedReplies: normalizedUpdatedReplies,\n hasMore,\n loadMore,\n reset,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n normalizedReplies,\n normalizedBufferedReplies,\n normalizedUpdatedReplies,\n repliesFeedName,\n hasMore,\n errors,\n ],\n );\n}\n\nconst emptyArray: any = [];\nconst emptyFunction = async () => {};\n"]}
package/dist/index.d.ts CHANGED
@@ -12,8 +12,9 @@ import { getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, valid
12
12
  import { setPkcJs, restorePkcJs } from "./lib/pkc-js/index.js";
13
13
  import { deleteDatabases, deleteCaches } from "./lib/debug-utils.js";
14
14
  import { createCrosspost } from "./lib/crosspost.js";
15
+ import { getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, resolvePostSortType, resolveReplySortType } from "./lib/page-sorts.js";
15
16
  export * from "./types.js";
16
- export { useAccount, useAccounts, useAccountComment, useAccountComments, useAccountVotes, useAccountVote, useAccountEdits, useAccountCommunities, useNotifications, usePubsubSubscribe, useComment, useComments, useCrosspost, useEditedComment, useValidateComment, useReplies, useCommunity, useCommunities, useCommunityStats, useListCommunities, useResolvedCommunityAddress, useAuthor, useAuthorComments, useAuthorAvatar, useResolvedAuthorAddress, useAuthorAddress, setAuthorAvatarsWhitelistedTokenAddresses, resetAuthorAddressCacheForTesting, useFeed, useBufferedFeeds, useSubscribe, useBlock, usePublishComment, usePublishVote, usePublishCommentEdit, usePublishCommentModeration, usePublishCommunityEdit, useCreateCommunity, useExportCommunity, createAccount, deleteAccount, deleteComment, setAccount, setActiveAccount, setAccountsOrder, importAccount, exportAccount, deleteCommunity, useClientsStates, useCommunitiesStates, usePkcRpcSettings, getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, validateEthWallet, setPkcJs, restorePkcJs, deleteDatabases, deleteCaches, createCrosspost, };
17
+ export { useAccount, useAccounts, useAccountComment, useAccountComments, useAccountVotes, useAccountVote, useAccountEdits, useAccountCommunities, useNotifications, usePubsubSubscribe, useComment, useComments, useCrosspost, useEditedComment, useValidateComment, useReplies, useCommunity, useCommunities, useCommunityStats, useListCommunities, useResolvedCommunityAddress, useAuthor, useAuthorComments, useAuthorAvatar, useResolvedAuthorAddress, useAuthorAddress, setAuthorAvatarsWhitelistedTokenAddresses, resetAuthorAddressCacheForTesting, useFeed, useBufferedFeeds, useSubscribe, useBlock, usePublishComment, usePublishVote, usePublishCommentEdit, usePublishCommentModeration, usePublishCommunityEdit, useCreateCommunity, useExportCommunity, createAccount, deleteAccount, deleteComment, setAccount, setActiveAccount, setAccountsOrder, importAccount, exportAccount, deleteCommunity, useClientsStates, useCommunitiesStates, usePkcRpcSettings, getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, validateEthWallet, setPkcJs, restorePkcJs, deleteDatabases, deleteCaches, createCrosspost, getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, resolvePostSortType, resolveReplySortType, };
17
18
  declare const hooks: {
18
19
  useAccount: typeof useAccount;
19
20
  useAccounts: typeof useAccounts;
@@ -81,6 +82,12 @@ declare const hooks: {
81
82
  deleteDatabases: () => Promise<[void, void, any, any, any]>;
82
83
  deleteCaches: () => Promise<[any, any, any]>;
83
84
  createCrosspost: (comment: import("./types.js").Comment) => import("./types.js").Crosspost;
85
+ getAvailablePostSortTypes: (community?: import("./types.js").Community) => string[];
86
+ getAvailableReplySortTypes: (comment?: import("./types.js").Comment) => string[];
87
+ getPreloadedPostSortType: (community?: import("./types.js").Community) => string | undefined;
88
+ getPreloadedReplySortType: (comment?: import("./types.js").Comment) => string | undefined;
89
+ resolvePostSortType: (community: import("./types.js").Community | undefined, requestedSortType?: string) => string | undefined;
90
+ resolveReplySortType: (comment: import("./types.js").Comment | undefined, requestedSortType?: string) => string | undefined;
84
91
  };
85
92
  export default hooks;
86
93
  //# sourceMappingURL=index.d.ts.map
@@ -1 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 import { getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, valid
26
26
  import { setPkcJs, restorePkcJs } from "./lib/pkc-js/index.js";
27
27
  import { deleteDatabases, deleteCaches } from "./lib/debug-utils.js";
28
28
  import { createCrosspost } from "./lib/crosspost.js";
29
+ import { getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, resolvePostSortType, resolveReplySortType, } from "./lib/page-sorts.js";
29
30
  // types
30
31
  export * from "./types.js";
31
32
  // IMPORTANT: should be the same as 'export default hooks'
@@ -53,7 +54,7 @@ usePkcRpcSettings,
53
54
  // chain
54
55
  getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, validateEthWallet,
55
56
  // utils
56
- setPkcJs, restorePkcJs, deleteDatabases, deleteCaches, createCrosspost, };
57
+ setPkcJs, restorePkcJs, deleteDatabases, deleteCaches, createCrosspost, getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, resolvePostSortType, resolveReplySortType, };
57
58
  // IMPORTANT: should be the same as 'export {}'
58
59
  const hooks = {
59
60
  // accounts
@@ -127,6 +128,12 @@ const hooks = {
127
128
  deleteDatabases,
128
129
  deleteCaches,
129
130
  createCrosspost,
131
+ getAvailablePostSortTypes,
132
+ getAvailableReplySortTypes,
133
+ getPreloadedPostSortType,
134
+ getPreloadedReplySortType,
135
+ resolvePostSortType,
136
+ resolveReplySortType,
130
137
  };
131
138
  export default hooks;
132
139
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,QAAQ,EAAE,CAAC;AAEX,WAAW;AACX,OAAO,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB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B,kBAAkB;IAClB,WAAW;IACX,UAAU;IACV,WAAW;IACX,YAAY;IACZ,gBAAgB;IAChB,kBAAkB;IAClB,UAAU;IACV,UAAU;IACV,cAAc;IACd,YAAY;IACZ,cAAc;IACd,iBAAiB;IACjB,kBAAkB;IAClB,2BAA2B;IAC3B,UAAU;IACV,SAAS;IACT,iBAAiB;IACjB,eAAe;IACf,wBAAwB;IACxB,gBAAgB;IAChB,yCAAyC;IACzC,iCAAiC;IACjC,QAAQ;IACR,OAAO;IACP,gBAAgB;IAChB,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,iBAAiB;IACjB,cAAc;IACd,qBAAqB;IACrB,2BAA2B;IAC3B,uBAAuB;IACvB,kBAAkB;IAClB,kBAAkB;IAClB,8CAA8C;IAC9C,aAAa;IACb,aAAa;IACb,aAAa;IACb,UAAU;IACV,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;IACb,aAAa;IACb,eAAe;IACf,SAAS;IACT,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,iBAAiB;IACjB,QAAQ;IACR,6BAA6B;IAC7B,iCAAiC;IACjC,iBAAiB;IACjB,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,eAAe;IACf,YAAY;IACZ,eAAe;CAChB,CAAC;AAEF,eAAe,KAAK,CAAC","sourcesContent":["import polyfill from \"./lib/polyfill\";\npolyfill();\n\n// accounts\nimport {\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useEditedComment,\n useNotifications,\n useAccountCommunities,\n usePubsubSubscribe,\n} from \"./hooks/accounts\";\n\n// comments\nimport { useComment, useComments, useCrosspost, useValidateComment } from \"./hooks/comments\";\n\n// replies\nimport { useReplies } from \"./hooks/replies\";\n\n// communities\nimport {\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n} from \"./hooks/communities\";\n\n// feeds\nimport { useFeed, useBufferedFeeds } from \"./hooks/feeds\";\n\n// authors\nimport {\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n} from \"./hooks/authors\";\n\n// actions\nimport {\n useSubscribe,\n useBlock,\n usePublishComment,\n usePublishVote,\n useCreateCommunity,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useExportCommunity,\n} from \"./hooks/actions\";\n\n// actions that don't have their own hooks yet\nimport {\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n} from \"./stores/accounts/accounts-actions\";\n\n// states\nimport { useClientsStates, useCommunitiesStates } from \"./hooks/states\";\n\n// pkc-rpc\nimport { usePkcRpcSettings } from \"./hooks/pkc-rpc\";\n\n// chain\nimport {\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n} from \"./lib/chain\";\n\n// utils\nimport { setPkcJs, restorePkcJs } from \"./lib/pkc-js\";\nimport { deleteDatabases, deleteCaches } from \"./lib/debug-utils\";\nimport { createCrosspost } from \"./lib/crosspost\";\n\n// types\nexport * from \"./types\";\n\n// IMPORTANT: should be the same as 'export default hooks'\nexport {\n // accounts\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useAccountCommunities,\n useNotifications,\n usePubsubSubscribe,\n // comments\n useComment,\n useComments,\n useCrosspost,\n useEditedComment,\n useValidateComment,\n // replies\n useReplies,\n // communities\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n // authors\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n // feeds\n useFeed,\n useBufferedFeeds,\n // actions\n useSubscribe,\n useBlock,\n usePublishComment,\n usePublishVote,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useCreateCommunity,\n useExportCommunity,\n // actions that don't have their own hooks yet\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n // states\n useClientsStates,\n useCommunitiesStates,\n // pkc-rpc\n usePkcRpcSettings,\n // chain\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n // utils\n setPkcJs,\n restorePkcJs,\n deleteDatabases,\n deleteCaches,\n createCrosspost,\n};\n\n// IMPORTANT: should be the same as 'export {}'\nconst hooks = {\n // accounts\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useAccountCommunities,\n useNotifications,\n usePubsubSubscribe,\n // comments\n useComment,\n useComments,\n useCrosspost,\n useEditedComment,\n useValidateComment,\n // replies\n useReplies,\n // communities\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n // authors\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n // feeds\n useFeed,\n useBufferedFeeds,\n // actions\n useSubscribe,\n useBlock,\n usePublishComment,\n usePublishVote,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useCreateCommunity,\n useExportCommunity,\n // actions that don't have their own hooks yet\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n // states\n useClientsStates,\n useCommunitiesStates,\n // pkc-rpc\n usePkcRpcSettings,\n // chain\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n // utils\n setPkcJs,\n restorePkcJs,\n deleteDatabases,\n deleteCaches,\n createCrosspost,\n};\n\nexport default hooks;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,QAAQ,EAAE,CAAC;AAEX,WAAW;AACX,OAAO,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,WAAW;AACX,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE7F,UAAU;AACV,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,cAAc;AACd,OAAO,EACL,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,QAAQ;AACR,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE1D,UAAU;AACV,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,yCAAyC,EACzC,iCAAiC,GAClC,MAAM,iBAAiB,CAAC;AAEzB,UAAU;AACV,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,8CAA8C;AAC9C,OAAO,EACL,aAAa,EACb,aAAa,EACb,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,GAChB,M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;IAC7B,iCAAiC;IACjC,iBAAiB;IACjB,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,eAAe;IACf,YAAY;IACZ,eAAe;IACf,yBAAyB;IACzB,0BAA0B;IAC1B,wBAAwB;IACxB,yBAAyB;IACzB,mBAAmB;IACnB,oBAAoB;CACrB,CAAC;AAEF,eAAe,KAAK,CAAC","sourcesContent":["import polyfill from \"./lib/polyfill\";\npolyfill();\n\n// accounts\nimport {\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useEditedComment,\n useNotifications,\n useAccountCommunities,\n usePubsubSubscribe,\n} from \"./hooks/accounts\";\n\n// comments\nimport { useComment, useComments, useCrosspost, useValidateComment } from \"./hooks/comments\";\n\n// replies\nimport { useReplies } from \"./hooks/replies\";\n\n// communities\nimport {\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n} from \"./hooks/communities\";\n\n// feeds\nimport { useFeed, useBufferedFeeds } from \"./hooks/feeds\";\n\n// authors\nimport {\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n} from \"./hooks/authors\";\n\n// actions\nimport {\n useSubscribe,\n useBlock,\n usePublishComment,\n usePublishVote,\n useCreateCommunity,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useExportCommunity,\n} from \"./hooks/actions\";\n\n// actions that don't have their own hooks yet\nimport {\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n} from \"./stores/accounts/accounts-actions\";\n\n// states\nimport { useClientsStates, useCommunitiesStates } from \"./hooks/states\";\n\n// pkc-rpc\nimport { usePkcRpcSettings } from \"./hooks/pkc-rpc\";\n\n// chain\nimport {\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n} from \"./lib/chain\";\n\n// utils\nimport { setPkcJs, restorePkcJs } from \"./lib/pkc-js\";\nimport { deleteDatabases, deleteCaches } from \"./lib/debug-utils\";\nimport { createCrosspost } from \"./lib/crosspost\";\nimport {\n getAvailablePostSortTypes,\n getAvailableReplySortTypes,\n getPreloadedPostSortType,\n getPreloadedReplySortType,\n resolvePostSortType,\n resolveReplySortType,\n} from \"./lib/page-sorts\";\n\n// types\nexport * from \"./types\";\n\n// IMPORTANT: should be the same as 'export default hooks'\nexport {\n // accounts\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useAccountCommunities,\n useNotifications,\n usePubsubSubscribe,\n // comments\n useComment,\n useComments,\n useCrosspost,\n useEditedComment,\n useValidateComment,\n // replies\n useReplies,\n // communities\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n // authors\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n // feeds\n useFeed,\n useBufferedFeeds,\n // actions\n useSubscribe,\n useBlock,\n usePublishComment,\n usePublishVote,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useCreateCommunity,\n useExportCommunity,\n // actions that don't have their own hooks yet\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n // states\n useClientsStates,\n useCommunitiesStates,\n // pkc-rpc\n usePkcRpcSettings,\n // chain\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n // utils\n setPkcJs,\n restorePkcJs,\n deleteDatabases,\n deleteCaches,\n createCrosspost,\n getAvailablePostSortTypes,\n getAvailableReplySortTypes,\n getPreloadedPostSortType,\n getPreloadedReplySortType,\n resolvePostSortType,\n resolveReplySortType,\n};\n\n// IMPORTANT: should be the same as 'export {}'\nconst hooks = {\n // accounts\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useAccountCommunities,\n useNotifications,\n usePubsubSubscribe,\n // comments\n useComment,\n useComments,\n useCrosspost,\n useEditedComment,\n useValidateComment,\n // replies\n useReplies,\n // communities\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n // authors\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n // feeds\n useFeed,\n useBufferedFeeds,\n // actions\n useSubscribe,\n useBlock,\n usePublishComment,\n usePublishVote,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useCreateCommunity,\n useExportCommunity,\n // actions that don't have their own hooks yet\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n // states\n useClientsStates,\n useCommunitiesStates,\n // pkc-rpc\n usePkcRpcSettings,\n // chain\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n // utils\n setPkcJs,\n restorePkcJs,\n deleteDatabases,\n deleteCaches,\n createCrosspost,\n getAvailablePostSortTypes,\n getAvailableReplySortTypes,\n getPreloadedPostSortType,\n getPreloadedReplySortType,\n resolvePostSortType,\n resolveReplySortType,\n};\n\nexport default hooks;\n"]}
@@ -0,0 +1,8 @@
1
+ import { Comment, Community } from "../types.js";
2
+ export declare const getAvailablePostSortTypes: (community?: Community) => string[];
3
+ export declare const getAvailableReplySortTypes: (comment?: Comment) => string[];
4
+ export declare const getPreloadedPostSortType: (community?: Community) => string | undefined;
5
+ export declare const getPreloadedReplySortType: (comment?: Comment) => string | undefined;
6
+ export declare const resolvePostSortType: (community: Community | undefined, requestedSortType?: string) => string | undefined;
7
+ export declare const resolveReplySortType: (comment: Comment | undefined, requestedSortType?: string) => string | undefined;
8
+ //# sourceMappingURL=page-sorts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-sorts.d.ts","sourceRoot":"","sources":["../../src/lib/page-sorts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAuB9C,eAAO,MAAM,yBAAyB,GAAI,YAAY,SAAS,KAAG,MAAM,EAC3B,CAAC;AAE9C,eAAO,MAAM,0BAA0B,GAAI,UAAU,OAAO,KAAG,MAAM,EACxB,CAAC;AAE9C,eAAO,MAAM,wBAAwB,GAAI,YAAY,SAAS,KAAG,MAAM,GAAG,SAC9B,CAAC;AAE7C,eAAO,MAAM,yBAAyB,GAAI,UAAU,OAAO,KAAG,MAAM,GAAG,SAC3B,CAAC;AAE7C,eAAO,MAAM,mBAAmB,GAC9B,WAAW,SAAS,GAAG,SAAS,EAChC,oBAAoB,MAAM,KACzB,MAAM,GAAG,SAOX,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,SAAS,OAAO,GAAG,SAAS,EAC5B,oBAAoB,MAAM,KACzB,MAAM,GAAG,SAOX,CAAC"}
@@ -0,0 +1,37 @@
1
+ const getAvailablePageSortTypes = (record) => {
2
+ const sortTypes = new Set();
3
+ for (const sortType of Object.keys((record === null || record === void 0 ? void 0 : record.pages) || {})) {
4
+ if (sortType)
5
+ sortTypes.add(sortType);
6
+ }
7
+ for (const sortType of Object.keys((record === null || record === void 0 ? void 0 : record.pageCids) || {})) {
8
+ if (sortType)
9
+ sortTypes.add(sortType);
10
+ }
11
+ return [...sortTypes];
12
+ };
13
+ const getPreloadedPageSortType = (record) => {
14
+ const preloadedSortType = Object.keys((record === null || record === void 0 ? void 0 : record.pages) || {}).find(Boolean);
15
+ return preloadedSortType || getAvailablePageSortTypes(record)[0];
16
+ };
17
+ export const getAvailablePostSortTypes = (community) => getAvailablePageSortTypes(community === null || community === void 0 ? void 0 : community.posts);
18
+ export const getAvailableReplySortTypes = (comment) => getAvailablePageSortTypes(comment === null || comment === void 0 ? void 0 : comment.replies);
19
+ export const getPreloadedPostSortType = (community) => getPreloadedPageSortType(community === null || community === void 0 ? void 0 : community.posts);
20
+ export const getPreloadedReplySortType = (comment) => getPreloadedPageSortType(comment === null || comment === void 0 ? void 0 : comment.replies);
21
+ export const resolvePostSortType = (community, requestedSortType) => {
22
+ if (requestedSortType !== undefined) {
23
+ return getAvailablePostSortTypes(community).includes(requestedSortType)
24
+ ? requestedSortType
25
+ : undefined;
26
+ }
27
+ return getPreloadedPostSortType(community);
28
+ };
29
+ export const resolveReplySortType = (comment, requestedSortType) => {
30
+ if (requestedSortType !== undefined) {
31
+ return getAvailableReplySortTypes(comment).includes(requestedSortType)
32
+ ? requestedSortType
33
+ : undefined;
34
+ }
35
+ return getPreloadedReplySortType(comment);
36
+ };
37
+ //# sourceMappingURL=page-sorts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-sorts.js","sourceRoot":"","sources":["../../src/lib/page-sorts.ts"],"names":[],"mappings":"AAOA,MAAM,yBAAyB,GAAG,CAAC,MAAoB,EAAY,EAAE;IACnE,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IACpC,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,KAAI,EAAE,CAAC,EAAE,CAAC;QACxD,IAAI,QAAQ;YAAE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IACD,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,KAAI,EAAE,CAAC,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C,iBAAiB;YACnB,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IACD,OAAO,wBAAwB,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAA4B,EAC5B,iBAA0B,EACN,EAAE;IACtB,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACpC,OAAO,0BAA0B,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YACpE,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IACD,OAAO,yBAAyB,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC,CAAC","sourcesContent":["import { Comment, Community } from \"../types\";\n\ntype PagesRecord = {\n pages?: Record<string, unknown>;\n pageCids?: Record<string, unknown>;\n};\n\nconst getAvailablePageSortTypes = (record?: PagesRecord): string[] => {\n const sortTypes = new Set<string>();\n for (const sortType of Object.keys(record?.pages || {})) {\n if (sortType) sortTypes.add(sortType);\n }\n for (const sortType of Object.keys(record?.pageCids || {})) {\n if (sortType) sortTypes.add(sortType);\n }\n return [...sortTypes];\n};\n\nconst getPreloadedPageSortType = (record?: PagesRecord): string | undefined => {\n const preloadedSortType = Object.keys(record?.pages || {}).find(Boolean);\n return preloadedSortType || getAvailablePageSortTypes(record)[0];\n};\n\nexport const getAvailablePostSortTypes = (community?: Community): string[] =>\n getAvailablePageSortTypes(community?.posts);\n\nexport const getAvailableReplySortTypes = (comment?: Comment): string[] =>\n getAvailablePageSortTypes(comment?.replies);\n\nexport const getPreloadedPostSortType = (community?: Community): string | undefined =>\n getPreloadedPageSortType(community?.posts);\n\nexport const getPreloadedReplySortType = (comment?: Comment): string | undefined =>\n getPreloadedPageSortType(comment?.replies);\n\nexport const resolvePostSortType = (\n community: Community | undefined,\n requestedSortType?: string,\n): string | undefined => {\n if (requestedSortType !== undefined) {\n return getAvailablePostSortTypes(community).includes(requestedSortType)\n ? requestedSortType\n : undefined;\n }\n return getPreloadedPostSortType(community);\n};\n\nexport const resolveReplySortType = (\n comment: Comment | undefined,\n requestedSortType?: string,\n): string | undefined => {\n if (requestedSortType !== undefined) {\n return getAvailableReplySortTypes(comment).includes(requestedSortType)\n ? requestedSortType\n : undefined;\n }\n return getPreloadedReplySortType(comment);\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const serializeFeedKey: (parts: readonly unknown[]) => string;
2
+ //# sourceMappingURL=serialize-feed-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-feed-key.d.ts","sourceRoot":"","sources":["../../src/lib/serialize-feed-key.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,GAAI,OAAO,SAAS,OAAO,EAAE,WAMvD,CAAC"}
@@ -0,0 +1,5 @@
1
+ export const serializeFeedKey = (parts) => JSON.stringify(parts.map((part) => [
2
+ typeof part,
3
+ typeof part === "number" && !Number.isFinite(part) ? String(part) : part,
4
+ ]));
5
+ //# sourceMappingURL=serialize-feed-key.js.map