@bitsocial/bitsocial-react-hooks 0.2.1 → 0.2.3

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 (117) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +2 -0
  3. package/dist/hooks/accounts/accounts.d.ts.map +1 -1
  4. package/dist/hooks/accounts/accounts.js +35 -10
  5. package/dist/hooks/accounts/accounts.js.map +1 -1
  6. package/dist/hooks/actions/actions.d.ts.map +1 -1
  7. package/dist/hooks/actions/actions.js +166 -93
  8. package/dist/hooks/actions/actions.js.map +1 -1
  9. package/dist/hooks/authors/author-avatars.d.ts +2 -2
  10. package/dist/hooks/authors/author-avatars.d.ts.map +1 -1
  11. package/dist/hooks/authors/author-avatars.js +48 -20
  12. package/dist/hooks/authors/author-avatars.js.map +1 -1
  13. package/dist/hooks/authors/authors.d.ts.map +1 -1
  14. package/dist/hooks/authors/authors.js +68 -22
  15. package/dist/hooks/authors/authors.js.map +1 -1
  16. package/dist/hooks/comments.d.ts.map +1 -1
  17. package/dist/hooks/comments.js +54 -3
  18. package/dist/hooks/comments.js.map +1 -1
  19. package/dist/hooks/communities.d.ts.map +1 -1
  20. package/dist/hooks/communities.js +41 -12
  21. package/dist/hooks/communities.js.map +1 -1
  22. package/dist/hooks/feeds/feeds.d.ts.map +1 -1
  23. package/dist/hooks/feeds/feeds.js +47 -11
  24. package/dist/hooks/feeds/feeds.js.map +1 -1
  25. package/dist/hooks/pkc-rpc.d.ts.map +1 -1
  26. package/dist/hooks/pkc-rpc.js +33 -20
  27. package/dist/hooks/pkc-rpc.js.map +1 -1
  28. package/dist/hooks/replies.d.ts.map +1 -1
  29. package/dist/hooks/replies.js +30 -4
  30. package/dist/hooks/replies.js.map +1 -1
  31. package/dist/index.d.ts +6 -4
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -2
  34. package/dist/index.js.map +1 -1
  35. package/dist/lib/debug-utils.d.ts +4 -4
  36. package/dist/lib/debug-utils.d.ts.map +1 -1
  37. package/dist/lib/debug-utils.js +56 -11
  38. package/dist/lib/debug-utils.js.map +1 -1
  39. package/dist/lib/localforage-lru/localforage-lru.d.ts +1 -0
  40. package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -1
  41. package/dist/lib/localforage-lru/localforage-lru.js +48 -10
  42. package/dist/lib/localforage-lru/localforage-lru.js.map +1 -1
  43. package/dist/lib/page-sorts.d.ts +6 -0
  44. package/dist/lib/page-sorts.d.ts.map +1 -1
  45. package/dist/lib/page-sorts.js +45 -9
  46. package/dist/lib/page-sorts.js.map +1 -1
  47. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -1
  48. package/dist/lib/pkc-js/pkc-js-mock-content.js +5 -1
  49. package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -1
  50. package/dist/lib/utils/utils.d.ts.map +1 -1
  51. package/dist/lib/utils/utils.js +24 -16
  52. package/dist/lib/utils/utils.js.map +1 -1
  53. package/dist/lib/validator.d.ts +1 -1
  54. package/dist/lib/validator.d.ts.map +1 -1
  55. package/dist/lib/validator.js +7 -1
  56. package/dist/lib/validator.js.map +1 -1
  57. package/dist/stores/accounts/account-generator.d.ts +1 -0
  58. package/dist/stores/accounts/account-generator.d.ts.map +1 -1
  59. package/dist/stores/accounts/account-generator.js +12 -4
  60. package/dist/stores/accounts/account-generator.js.map +1 -1
  61. package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -1
  62. package/dist/stores/accounts/accounts-actions-internal.js +24 -6
  63. package/dist/stores/accounts/accounts-actions-internal.js.map +1 -1
  64. package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
  65. package/dist/stores/accounts/accounts-actions.js +339 -98
  66. package/dist/stores/accounts/accounts-actions.js.map +1 -1
  67. package/dist/stores/accounts/accounts-database.d.ts +1 -0
  68. package/dist/stores/accounts/accounts-database.d.ts.map +1 -1
  69. package/dist/stores/accounts/accounts-database.js +82 -15
  70. package/dist/stores/accounts/accounts-database.js.map +1 -1
  71. package/dist/stores/accounts/accounts-store.d.ts +1 -1
  72. package/dist/stores/accounts/accounts-store.d.ts.map +1 -1
  73. package/dist/stores/accounts/accounts-store.js +1 -1
  74. package/dist/stores/accounts/accounts-store.js.map +1 -1
  75. package/dist/stores/accounts/utils.d.ts +5 -1
  76. package/dist/stores/accounts/utils.d.ts.map +1 -1
  77. package/dist/stores/accounts/utils.js +58 -0
  78. package/dist/stores/accounts/utils.js.map +1 -1
  79. package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -1
  80. package/dist/stores/authors-comments/authors-comments-store.js +39 -12
  81. package/dist/stores/authors-comments/authors-comments-store.js.map +1 -1
  82. package/dist/stores/comments/comments-store.d.ts +2 -0
  83. package/dist/stores/comments/comments-store.d.ts.map +1 -1
  84. package/dist/stores/comments/comments-store.js +170 -21
  85. package/dist/stores/comments/comments-store.js.map +1 -1
  86. package/dist/stores/communities/communities-store.d.ts.map +1 -1
  87. package/dist/stores/communities/communities-store.js +27 -7
  88. package/dist/stores/communities/communities-store.js.map +1 -1
  89. package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -1
  90. package/dist/stores/communities-pages/communities-pages-store.js +131 -12
  91. package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
  92. package/dist/stores/feeds/feed-sorter.d.ts +5 -2
  93. package/dist/stores/feeds/feed-sorter.d.ts.map +1 -1
  94. package/dist/stores/feeds/feed-sorter.js +15 -4
  95. package/dist/stores/feeds/feed-sorter.js.map +1 -1
  96. package/dist/stores/feeds/feeds-store.d.ts +3 -0
  97. package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
  98. package/dist/stores/feeds/feeds-store.js +36 -26
  99. package/dist/stores/feeds/feeds-store.js.map +1 -1
  100. package/dist/stores/feeds/utils.d.ts +16 -0
  101. package/dist/stores/feeds/utils.d.ts.map +1 -1
  102. package/dist/stores/feeds/utils.js +82 -26
  103. package/dist/stores/feeds/utils.js.map +1 -1
  104. package/dist/stores/replies/replies-store.d.ts.map +1 -1
  105. package/dist/stores/replies/replies-store.js +32 -6
  106. package/dist/stores/replies/replies-store.js.map +1 -1
  107. package/dist/stores/replies/utils.d.ts +3 -2
  108. package/dist/stores/replies/utils.d.ts.map +1 -1
  109. package/dist/stores/replies/utils.js +38 -5
  110. package/dist/stores/replies/utils.js.map +1 -1
  111. package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -1
  112. package/dist/stores/replies-pages/replies-pages-store.js +68 -13
  113. package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
  114. package/dist/types.d.ts +11 -2
  115. package/dist/types.d.ts.map +1 -1
  116. package/dist/types.js.map +1 -1
  117. package/package.json +2 -2
@@ -21,6 +21,8 @@ import shallow from "zustand/shallow";
21
21
  import { getCommunityRefKeys, getUniqueSortedCommunityRefs, } from "../../lib/community-ref.js";
22
22
  import { serializeFeedKey } from "../../lib/serialize-feed-key.js";
23
23
  let feedAutoUpdateSubscriptionCount = 0;
24
+ const emptyErrors = [];
25
+ const emptyCommunityKeys = [];
24
26
  /**
25
27
  * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]
26
28
  * @param sortType - A sort name published by the community, or a standard sort computed client-side
@@ -31,7 +33,7 @@ let feedAutoUpdateSubscriptionCount = 0;
31
33
  export function useFeed(options) {
32
34
  assert(!options || typeof options === "object", `useFeed options argument '${options}' not an object`);
33
35
  const opts = options || {};
34
- let { communities, sortType, accountName, postsPerPage, filter, newerThan, accountComments, modQueue, } = opts;
36
+ let { communities, sortType, accountName, postsPerPage, filter, newerThan, accountComments, modQueue, includeBlockedCids, } = opts;
35
37
  validator.validateUseFeedArguments({
36
38
  communities,
37
39
  communityRefs: opts.communityRefs,
@@ -42,6 +44,7 @@ export function useFeed(options) {
42
44
  filter,
43
45
  newerThan,
44
46
  accountComments,
47
+ includeBlockedCids,
45
48
  });
46
49
  const account = useAccount({ accountName });
47
50
  const accountVotes = useAccountsStore((state) => (account === null || account === void 0 ? void 0 : account.id) ? state.accountsVotes[account.id] : undefined);
@@ -55,17 +58,28 @@ export function useFeed(options) {
55
58
  const normalizedCommunityRefs = useMemo(() => communities || [], [communities]);
56
59
  const uniqueCommunityRefs = useUniqueSortedCommunityRefs(normalizedCommunityRefs);
57
60
  const uniqueCommunityKeys = useMemo(() => getCommunityRefKeys(uniqueCommunityRefs), [uniqueCommunityRefs]);
58
- const feedName = useFeedName(account === null || account === void 0 ? void 0 : account.id, sortType, uniqueCommunityKeys, postsPerPage, filter, newerThan, accountComments, modQueue);
59
- const [errors, setErrors] = useState([]);
61
+ const feedName = useFeedName(account === null || account === void 0 ? void 0 : account.id, sortType, uniqueCommunityKeys, postsPerPage, filter, newerThan, accountComments, modQueue, includeBlockedCids);
62
+ // errors belong to the feed they happened in, another feed starts without them. Drop them when
63
+ // the feed changes (or when one lands after it changed) so they don't return with the old feed
64
+ const [feedErrors, setFeedErrors] = useState();
65
+ if (feedErrors && feedErrors.feedName !== feedName) {
66
+ setFeedErrors(undefined);
67
+ }
68
+ const errors = (feedErrors === null || feedErrors === void 0 ? void 0 : feedErrors.feedName) === feedName ? feedErrors.errors : emptyErrors;
69
+ const addError = (error) => setFeedErrors((previous) => ({
70
+ feedName,
71
+ errors: (previous === null || previous === void 0 ? void 0 : previous.feedName) === feedName ? [...previous.errors, error] : [error],
72
+ }));
60
73
  const communityKeysWithNewerPosts = useFeedsStore((state) => state.feedsCommunityKeysWithNewerPosts[feedName]);
61
74
  const feedCommunityKeysWithMore = useFeedsStore((state) => state.feedsCommunityKeysWithMore[feedName]);
75
+ const communityKeysWithUnavailableSort = useFeedsStore((state) => state.feedsCommunityKeysWithUnavailableSort[feedName]);
62
76
  // add feed to store
63
77
  useEffect(() => {
64
78
  if (!uniqueCommunityRefs.length || !account) {
65
79
  return;
66
80
  }
67
81
  const isBufferedFeed = false;
68
- addFeedToStore(feedName, uniqueCommunityRefs, uniqueCommunityKeys, sortType, account, isBufferedFeed, postsPerPage, filter, newerThan, accountComments, modQueue).catch((error) => log.error("useFeed addFeedToStore error", { feedName, error }));
82
+ addFeedToStore(feedName, uniqueCommunityRefs, uniqueCommunityKeys, sortType, account, isBufferedFeed, postsPerPage, filter, newerThan, accountComments, modQueue, includeBlockedCids).catch((error) => log.error("useFeed addFeedToStore error", { feedName, error }));
69
83
  }, [feedName]);
70
84
  // keep the feed's communities updating while mounted, after the feed was added above
71
85
  useEffect(() => {
@@ -92,12 +106,20 @@ export function useFeed(options) {
92
106
  if (!uniqueCommunityRefs.length || !account) {
93
107
  throw Error("useFeed cannot load more feed not initalized yet");
94
108
  }
95
- incrementFeedPageNumber(feedName);
109
+ try {
110
+ incrementFeedPageNumber(feedName);
111
+ }
112
+ catch (error) {
113
+ // infinite scroll calls loadMore before the feed or its current page has loaded, the
114
+ // store refuses the page increment and that isn't a feed error
115
+ log("useFeed loadMore before the feed page loaded", { feedName, error });
116
+ yield new Promise((r) => setTimeout(r, 50));
117
+ }
96
118
  }
97
119
  catch (e) {
98
120
  // wait 100 ms so infinite scroll doesn't spam this function
99
121
  yield new Promise((r) => setTimeout(r, 50));
100
- setErrors([...errors, e]);
122
+ addError(e);
101
123
  }
102
124
  });
103
125
  const reset = () => __awaiter(this, void 0, void 0, function* () {
@@ -110,7 +132,7 @@ export function useFeed(options) {
110
132
  catch (e) {
111
133
  // wait 100 ms so infinite scroll doesn't spam this function
112
134
  yield new Promise((r) => setTimeout(r, 50));
113
- setErrors([...errors, e]);
135
+ addError(e);
114
136
  }
115
137
  });
116
138
  const expandTimeWindow = (nextNewerThan) => __awaiter(this, void 0, void 0, function* () {
@@ -122,7 +144,7 @@ export function useFeed(options) {
122
144
  }
123
145
  catch (e) {
124
146
  yield new Promise((r) => setTimeout(r, 50));
125
- setErrors([...errors, e]);
147
+ addError(e);
126
148
  }
127
149
  });
128
150
  if (account && normalizedCommunityRefs.length) {
@@ -155,6 +177,7 @@ export function useFeed(options) {
155
177
  hasMore,
156
178
  communityKeysWithNewerPosts: communityKeysWithNewerPosts || [],
157
179
  communityKeysWithMore,
180
+ communityKeysWithUnavailableSort: communityKeysWithUnavailableSort || emptyCommunityKeys,
158
181
  loadMore,
159
182
  expandTimeWindow,
160
183
  reset,
@@ -170,6 +193,7 @@ export function useFeed(options) {
170
193
  errors,
171
194
  communityKeysWithNewerPosts,
172
195
  communityKeysWithMore,
196
+ communityKeysWithUnavailableSort,
173
197
  ]);
174
198
  }
175
199
  /**
@@ -301,12 +325,14 @@ function useUniqueSortedCommunityRefs(communityRefs) {
301
325
  return getUniqueSortedCommunityRefs(communityRefs);
302
326
  }, [communityRefs]);
303
327
  }
304
- function useFeedName(accountId, sortType, uniqueCommunityKeys, postsPerPage, filter, newerThan, accountComments, modQueue) {
328
+ function useFeedName(accountId, sortType, uniqueCommunityKeys, postsPerPage, filter, newerThan, accountComments, modQueue, includeBlockedCids) {
329
+ var _a;
305
330
  const filterKey = filter === null || filter === void 0 ? void 0 : filter.key;
306
331
  const accountCommentsNewerThan = accountComments === null || accountComments === void 0 ? void 0 : accountComments.newerThan;
307
332
  const accountCommentsAppend = accountComments === null || accountComments === void 0 ? void 0 : accountComments.append;
333
+ const accountCommentsLimit = (_a = accountComments === null || accountComments === void 0 ? void 0 : accountComments.limit) !== null && _a !== void 0 ? _a : undefined;
308
334
  return useMemo(() => {
309
- return serializeFeedKey([
335
+ const feedKey = [
310
336
  accountId,
311
337
  sortType,
312
338
  uniqueCommunityKeys,
@@ -316,7 +342,15 @@ function useFeedName(accountId, sortType, uniqueCommunityKeys, postsPerPage, fil
316
342
  accountCommentsNewerThan,
317
343
  accountCommentsAppend,
318
344
  modQueue,
319
- ]);
345
+ ];
346
+ // options added later are only part of the name when set, feeds without them keep their name
347
+ if (accountCommentsLimit !== undefined) {
348
+ feedKey.push(accountCommentsLimit);
349
+ }
350
+ if (includeBlockedCids === true) {
351
+ feedKey.push(includeBlockedCids);
352
+ }
353
+ return serializeFeedKey(feedKey);
320
354
  }, [
321
355
  accountId,
322
356
  sortType,
@@ -326,7 +360,9 @@ function useFeedName(accountId, sortType, uniqueCommunityKeys, postsPerPage, fil
326
360
  newerThan,
327
361
  accountCommentsNewerThan,
328
362
  accountCommentsAppend,
363
+ accountCommentsLimit,
329
364
  modQueue === null || modQueue === void 0 ? void 0 : modQueue.toString(),
365
+ includeBlockedCids,
330
366
  ]);
331
367
  }
332
368
  function useFeedNames(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,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7D,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,kBAAkB,CAAC;AAUtC,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAC/C,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAEL,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,IAAI,+BAA+B,GAAG,CAAC,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,OAAwB;IAC9C,MAAM,CACJ,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EACvC,6BAA6B,OAAO,iBAAiB,CACtD,CAAC;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S,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, useRef, 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 \"../../lib/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 useAccountsStore from \"../../stores/accounts\";\nimport { addCommentModerationToComments } from \"../../lib/utils/comment-moderation\";\nimport { addOptimisticVoteCountsToComments } from \"../../lib/utils/optimistic-vote-counts\";\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\nlet feedAutoUpdateSubscriptionCount = 0;\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, or a standard sort computed client-side\n * when every post fits in the preloaded page. 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 accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);\n const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);\n const autoUpdateSubscriptionId = useRef(`useFeed-${++feedAutoUpdateSubscriptionCount}`);\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 const feedCommunityKeysWithMore = useFeedsStore(\n (state) => state.feedsCommunityKeysWithMore[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 // keep the feed's communities updating while mounted, after the feed was added above\n useEffect(() => {\n if (!uniqueCommunityRefs.length || !account) {\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n startFeedAutoUpdate(feedName, subscriberId);\n return () => stopFeedAutoUpdate(feedName, subscriberId);\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 // until the feed is first calculated, every community still has more\n let communityKeysWithMore = feedCommunityKeysWithMore || uniqueCommunityKeys;\n if (!normalizedCommunityRefs.length) {\n communityKeysWithMore = [];\n }\n // apply the account's pending votes like useComment/useComments/useReplies do, so voting from a\n // feed updates the score immediately instead of only once the community publishes the new counts\n const normalizedFeed = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(feed), accountVotes),\n [feed, accountVotes],\n );\n const normalizedBufferedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(bufferedFeed), accountVotes),\n [bufferedFeed, accountVotes],\n );\n const normalizedUpdatedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(updatedFeed), accountVotes),\n [updatedFeed, accountVotes],\n );\n\n return useMemo(\n () => ({\n feed: normalizedFeed,\n bufferedFeed: normalizedBufferedFeed,\n updatedFeed: normalizedUpdatedFeed,\n hasMore,\n communityKeysWithNewerPosts: communityKeysWithNewerPosts || [],\n communityKeysWithMore,\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 communityKeysWithMore,\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 const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);\n const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);\n const autoUpdateSubscriptionId = useRef(`useBufferedFeeds-${++feedAutoUpdateSubscriptionCount}`);\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 // keep the buffered feeds' communities updating while mounted, keyed by the names so\n // inline options recreated on every render do not resubscribe\n useEffect(() => {\n if (!account) {\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n const subscribedFeedNames = feedNames.filter((_, i) => communityRefsArrays[i]?.length);\n for (const feedName of subscribedFeedNames) {\n startFeedAutoUpdate(feedName, subscriberId);\n }\n return () => {\n for (const feedName of subscribedFeedNames) {\n stopFeedAutoUpdate(feedName, subscriberId);\n }\n };\n }, [JSON.stringify(feedNames), account?.id]);\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
+ {"version":3,"file":"feeds.js","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,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rC,CAAC;QACD,IAAI,kBAAkB,KAAK,IAAI,EAAE,CAAC;YAChC,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC,EAAE;QACD,SAAS;QACT,QAAQ;QACR,mBAAmB;QACnB,YAAY;QACZ,SAAS;QACT,SAAS;QACT,wBAAwB;QACxB,qBAAqB;QACrB,oBAAoB;QACpB,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAQ,EAAE;QACpB,kBAAkB;KACnB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,YAAY,CACnB,SAAiB,EACjB,SAAiC,EACjC,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,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, useRef, 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 \"../../lib/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 useAccountsStore from \"../../stores/accounts\";\nimport { addCommentModerationToComments } from \"../../lib/utils/comment-moderation\";\nimport { addOptimisticVoteCountsToComments } from \"../../lib/utils/optimistic-vote-counts\";\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\nlet feedAutoUpdateSubscriptionCount = 0;\nconst emptyErrors: Error[] = [];\nconst emptyCommunityKeys: string[] = [];\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, or a standard sort computed client-side\n * when every post fits in the preloaded page. 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 includeBlockedCids,\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 includeBlockedCids,\n });\n const account = useAccount({ accountName });\n const accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);\n const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);\n const autoUpdateSubscriptionId = useRef(`useFeed-${++feedAutoUpdateSubscriptionCount}`);\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 includeBlockedCids,\n );\n // errors belong to the feed they happened in, another feed starts without them. Drop them when\n // the feed changes (or when one lands after it changed) so they don't return with the old feed\n const [feedErrors, setFeedErrors] = useState<{ feedName: string; errors: Error[] }>();\n if (feedErrors && feedErrors.feedName !== feedName) {\n setFeedErrors(undefined);\n }\n const errors = feedErrors?.feedName === feedName ? feedErrors.errors : emptyErrors;\n const addError = (error: Error) =>\n setFeedErrors((previous) => ({\n feedName,\n errors: previous?.feedName === feedName ? [...previous.errors, error] : [error],\n }));\n const communityKeysWithNewerPosts = useFeedsStore(\n (state) => state.feedsCommunityKeysWithNewerPosts[feedName],\n );\n const feedCommunityKeysWithMore = useFeedsStore(\n (state) => state.feedsCommunityKeysWithMore[feedName],\n );\n const communityKeysWithUnavailableSort = useFeedsStore(\n (state) => state.feedsCommunityKeysWithUnavailableSort[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 includeBlockedCids,\n ).catch((error: unknown) => log.error(\"useFeed addFeedToStore error\", { feedName, error }));\n }, [feedName]);\n\n // keep the feed's communities updating while mounted, after the feed was added above\n useEffect(() => {\n if (!uniqueCommunityRefs.length || !account) {\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n startFeedAutoUpdate(feedName, subscriberId);\n return () => stopFeedAutoUpdate(feedName, subscriberId);\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 try {\n incrementFeedPageNumber(feedName);\n } catch (error) {\n // infinite scroll calls loadMore before the feed or its current page has loaded, the\n // store refuses the page increment and that isn't a feed error\n log(\"useFeed loadMore before the feed page loaded\", { feedName, error });\n await new Promise((r) => setTimeout(r, 50));\n }\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 addError(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 addError(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 addError(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 // until the feed is first calculated, every community still has more\n let communityKeysWithMore = feedCommunityKeysWithMore || uniqueCommunityKeys;\n if (!normalizedCommunityRefs.length) {\n communityKeysWithMore = [];\n }\n // apply the account's pending votes like useComment/useComments/useReplies do, so voting from a\n // feed updates the score immediately instead of only once the community publishes the new counts\n const normalizedFeed = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(feed), accountVotes),\n [feed, accountVotes],\n );\n const normalizedBufferedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(bufferedFeed), accountVotes),\n [bufferedFeed, accountVotes],\n );\n const normalizedUpdatedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(updatedFeed), accountVotes),\n [updatedFeed, accountVotes],\n );\n\n return useMemo(\n () => ({\n feed: normalizedFeed,\n bufferedFeed: normalizedBufferedFeed,\n updatedFeed: normalizedUpdatedFeed,\n hasMore,\n communityKeysWithNewerPosts: communityKeysWithNewerPosts || [],\n communityKeysWithMore,\n communityKeysWithUnavailableSort: communityKeysWithUnavailableSort || emptyCommunityKeys,\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 communityKeysWithMore,\n communityKeysWithUnavailableSort,\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 const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);\n const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);\n const autoUpdateSubscriptionId = useRef(`useBufferedFeeds-${++feedAutoUpdateSubscriptionCount}`);\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 // keep the buffered feeds' communities updating while mounted, keyed by the names so\n // inline options recreated on every render do not resubscribe\n useEffect(() => {\n if (!account) {\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n const subscribedFeedNames = feedNames.filter((_, i) => communityRefsArrays[i]?.length);\n for (const feedName of subscribedFeedNames) {\n startFeedAutoUpdate(feedName, subscriberId);\n }\n return () => {\n for (const feedName of subscribedFeedNames) {\n stopFeedAutoUpdate(feedName, subscriberId);\n }\n };\n }, [JSON.stringify(feedNames), account?.id]);\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 includeBlockedCids?: boolean,\n) {\n const filterKey = filter?.key;\n const accountCommentsNewerThan = accountComments?.newerThan;\n const accountCommentsAppend = accountComments?.append;\n const accountCommentsLimit = accountComments?.limit ?? undefined;\n return useMemo(() => {\n const feedKey: unknown[] = [\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n modQueue,\n ];\n // options added later are only part of the name when set, feeds without them keep their name\n if (accountCommentsLimit !== undefined) {\n feedKey.push(accountCommentsLimit);\n }\n if (includeBlockedCids === true) {\n feedKey.push(includeBlockedCids);\n }\n return serializeFeedKey(feedKey);\n }, [\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n accountCommentsLimit,\n modQueue?.toString(),\n includeBlockedCids,\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":"pkc-rpc.d.ts","sourceRoot":"","sources":["../../src/hooks/pkc-rpc.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAkB,MAAM,UAAU,CAAC;AAM7F;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,uBAAuB,CAoF7F"}
1
+ {"version":3,"file":"pkc-rpc.d.ts","sourceRoot":"","sources":["../../src/hooks/pkc-rpc.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAkB,MAAM,UAAU,CAAC;AAM7F;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,uBAAuB,CAkG7F"}
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { useState, useMemo, useEffect } from "react";
10
+ import { useState, useMemo, useEffect, useRef } from "react";
11
11
  import { useAccount } from "./accounts/index.js";
12
12
  import assert from "../lib/assert.js";
13
13
  import { getProtocolClient, getRpcClients } from "../lib/pkc-compat.js";
@@ -23,23 +23,39 @@ export function usePkcRpcSettings(options) {
23
23
  const protocolClient = getProtocolClient(account);
24
24
  const rpcClient = getFirstRpcClient(protocolClient);
25
25
  const [pkcRpcSettingsState, setPkcRpcSettingsState] = useState();
26
- const [state, setState] = useState("initializing");
26
+ const [rpcState, setRpcState] = useState("initializing");
27
+ // the result of the last setPkcRpcSettings call, shown instead of the rpc state for a while
28
+ const [saveResult, setSaveResult] = useState();
29
+ const saveResultTimeout = useRef(undefined);
27
30
  const [errors, setErrors] = useState([]);
31
+ // the rpc client whose settings and state the hook shows
32
+ const shownRpcClient = useRef(rpcClient);
33
+ const showSaveResult = (result) => {
34
+ clearTimeout(saveResultTimeout.current);
35
+ setSaveResult(result);
36
+ if (result) {
37
+ saveResultTimeout.current = setTimeout(() => setSaveResult(undefined), 10000);
38
+ }
39
+ };
40
+ useEffect(() => () => clearTimeout(saveResultTimeout.current), []);
28
41
  useEffect(() => {
42
+ var _a;
43
+ // the settings, state and save result of a previous rpc client don't apply to this one
44
+ shownRpcClient.current = rpcClient;
45
+ showSaveResult(undefined);
46
+ setPkcRpcSettingsState((_a = rpcClient === null || rpcClient === void 0 ? void 0 : rpcClient.settings) !== null && _a !== void 0 ? _a : undefined);
47
+ setRpcState((rpcClient === null || rpcClient === void 0 ? void 0 : rpcClient.state) || "initializing");
29
48
  if (!account || !protocolClient)
30
49
  return;
31
50
  if (!rpcClient)
32
51
  return;
33
- if (rpcClient.settings != null)
34
- setPkcRpcSettingsState(rpcClient.settings);
35
- const rpcState = rpcClient.state;
36
- if (rpcState != null && rpcState !== "")
37
- setState(rpcState);
38
52
  const onRpcSettingsChange = (pkcRpcSettings) => {
39
53
  setPkcRpcSettingsState(pkcRpcSettings);
40
54
  };
41
55
  const onRpcStateChange = (rpcState) => {
42
- setState(rpcState);
56
+ // a newer rpc state replaces the save result
57
+ showSaveResult(undefined);
58
+ setRpcState(rpcState);
43
59
  };
44
60
  const onRpcError = (e) => {
45
61
  setErrors((prevErrors) => [...prevErrors, e]);
@@ -59,24 +75,21 @@ export function usePkcRpcSettings(options) {
59
75
  assert(pkcRpcSettings && typeof pkcRpcSettings === "object", `usePkcRpcSettings.setPkcRpcSettings pkcRpcSettings argument '${pkcRpcSettings}' not an object`);
60
76
  const currentRpcClient = getFirstRpcClient(getProtocolClient(account));
61
77
  assert(currentRpcClient, `can't use usePkcRpcSettings.setPkcRpcSettings no account.pkc.clients.pkcRpcClients`);
78
+ // a save that finishes after the hook switched to another rpc client doesn't apply to it
62
79
  try {
63
80
  yield currentRpcClient.setSettings(pkcRpcSettings);
64
- setState("succeeded");
81
+ if (currentRpcClient === shownRpcClient.current) {
82
+ showSaveResult("succeeded");
83
+ }
65
84
  }
66
85
  catch (e) {
67
- setErrors((prevErrors) => [...prevErrors, e]);
68
- setState("failed");
86
+ if (currentRpcClient === shownRpcClient.current) {
87
+ setErrors((prevErrors) => [...prevErrors, e]);
88
+ showSaveResult("failed");
89
+ }
69
90
  }
70
- const rpcStateAfter = currentRpcClient.state;
71
- setTimeout(() => {
72
- setState((prevState) => {
73
- if (prevState !== rpcStateAfter && rpcStateAfter != null && rpcStateAfter !== "") {
74
- return rpcStateAfter;
75
- }
76
- return prevState;
77
- });
78
- }, 10000);
79
91
  });
92
+ const state = saveResult || rpcState;
80
93
  return useMemo(() => ({
81
94
  pkcRpcSettings: pkcRpcSettingsState,
82
95
  setPkcRpcSettings: updatePkcRpcSettings,
@@ -1 +1 @@
1
- {"version":3,"file":"pkc-rpc.js","sourceRoot":"","sources":["../../src/hooks/pkc-rpc.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,MAAM,MAAM,eAAe,CAAC;AAEnC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAErE,MAAM,iBAAiB,GAAG,CAAC,cAAmB,EAAE,EAAE,CAChD,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAQ,CAAC;AAE/D;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAkC;IAClE,MAAM,CACJ,CAAC,OAA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AC,CAAC;QACrB,CAAC;QAED,MAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,CAAC;QAC7C,UAAU,CAAC,GAAG,EAAE;YACd,QAAQ,CAAC,CAAC,SAAS,EAAE,EAAE;gBACrB,IAAI,SAAS,KAAK,aAAa,IAAI,aAAa,IAAI,IAAI,IAAI,aAAa,KAAK,EAAE,EAAE,CAAC;oBACjF,OAAO,aAAa,CAAC;gBACvB,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,CAAC,CAAC,CAAC;QACL,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC,CAAA,CAAC;IAEF,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,cAAc,EAAE,mBAAmB;QACnC,iBAAiB,EAAE,oBAAoB;QACvC,KAAK;QACL,KAAK,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAClC,MAAM;KACP,CAAC,EACF,CAAC,mBAAmB,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAClD,CAAC;AACJ,CAAC","sourcesContent":["import { useState, useMemo, useEffect } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport assert from \"../lib/assert\";\nimport { UsePkcRpcSettingsOptions, UsePkcRpcSettingsResult, PkcRpcSettings } from \"../types\";\nimport { getProtocolClient, getRpcClients } from \"../lib/pkc-compat\";\n\nconst getFirstRpcClient = (protocolClient: any) =>\n Object.values(getRpcClients(protocolClient) || {})[0] as any;\n\n/**\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 usePkcRpcSettings(options?: UsePkcRpcSettingsOptions): UsePkcRpcSettingsResult {\n assert(\n !options || typeof options === \"object\",\n `usePkcRpcSettings options argument '${options}' not an object`,\n );\n const { accountName } = options ?? {};\n const account = useAccount({ accountName });\n const protocolClient = getProtocolClient(account);\n const rpcClient = getFirstRpcClient(protocolClient);\n const [pkcRpcSettingsState, setPkcRpcSettingsState] = useState<PkcRpcSettings>();\n const [state, setState] = useState<string>(\"initializing\");\n const [errors, setErrors] = useState<Error[]>([]);\n\n useEffect(() => {\n if (!account || !protocolClient) return;\n if (!rpcClient) return;\n\n if (rpcClient.settings != null) setPkcRpcSettingsState(rpcClient.settings);\n const rpcState = rpcClient.state;\n if (rpcState != null && rpcState !== \"\") setState(rpcState);\n\n const onRpcSettingsChange = (pkcRpcSettings: PkcRpcSettings) => {\n setPkcRpcSettingsState(pkcRpcSettings);\n };\n const onRpcStateChange = (rpcState: string) => {\n setState(rpcState);\n };\n const onRpcError = (e: any) => {\n setErrors((prevErrors) => [...prevErrors, e]);\n };\n\n rpcClient.on(\"settingschange\", onRpcSettingsChange);\n rpcClient.on(\"statechange\", onRpcStateChange);\n rpcClient.on(\"error\", onRpcError);\n\n // clean up\n return () => {\n rpcClient.removeListener(\"settingschange\", onRpcSettingsChange);\n rpcClient.removeListener(\"statechange\", onRpcStateChange);\n rpcClient.removeListener(\"error\", onRpcError);\n };\n }, [account?.id, rpcClient, protocolClient]);\n\n const updatePkcRpcSettings = async (pkcRpcSettings: PkcRpcSettings) => {\n assert(account, `can't use usePkcRpcSettings.setPkcRpcSettings before initialized`);\n assert(\n pkcRpcSettings && typeof pkcRpcSettings === \"object\",\n `usePkcRpcSettings.setPkcRpcSettings pkcRpcSettings argument '${pkcRpcSettings}' not an object`,\n );\n const currentRpcClient = getFirstRpcClient(getProtocolClient(account));\n assert(\n currentRpcClient,\n `can't use usePkcRpcSettings.setPkcRpcSettings no account.pkc.clients.pkcRpcClients`,\n );\n\n try {\n await currentRpcClient.setSettings(pkcRpcSettings);\n setState(\"succeeded\");\n } catch (e: any) {\n setErrors((prevErrors) => [...prevErrors, e]);\n setState(\"failed\");\n }\n\n const rpcStateAfter = currentRpcClient.state;\n setTimeout(() => {\n setState((prevState) => {\n if (prevState !== rpcStateAfter && rpcStateAfter != null && rpcStateAfter !== \"\") {\n return rpcStateAfter;\n }\n return prevState;\n });\n }, 10000);\n };\n\n return useMemo(\n () => ({\n pkcRpcSettings: pkcRpcSettingsState,\n setPkcRpcSettings: updatePkcRpcSettings,\n state,\n error: errors?.[errors.length - 1],\n errors,\n }),\n [pkcRpcSettingsState, account?.id, state, errors],\n );\n}\n"]}
1
+ {"version":3,"file":"pkc-rpc.js","sourceRoot":"","sources":["../../src/hooks/pkc-rpc.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,MAAM,MAAM,eAAe,CAAC;AAEnC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAErE,MAAM,iBAAiB,GAAG,CAAC,cAAmB,EAAE,EAAE,CAChD,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAQ,CAAC;AAE/D;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAkC;IAClE,MAAM,CACJ,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EACvC,uCAAuC,OAAO,iBAAiB,CAChE,CAAC;IACF,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IACtC,MAAM,OAAO,GAAG,UAAU,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;IAC5C,MAAM,cAAc,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,iBAAiB,CAAC,cAAc,CAAC,CAAC;IACpD,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,QAAQ,EAAkB,CAAC;IACjF,MAAM,CAAC,QAAQ,EAAE,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QAEF,yFAAyF;QACzF,IAAI,CAAC;YACH,MAAM,gBAAgB,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;YACnD,IAAI,gBAAgB,KAAK,cAAc,CAAC,OAAO,EAAE,CAAC;gBAChD,cAAc,CAAC,WAAW,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,IAAI,gBAAgB,KAAK,cAAc,CAAC,OAAO,EAAE,CAAC;gBAChD,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC9C,cAAc,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC,CAAA,CAAC;IAEF,MAAM,KAAK,GAAG,UAAU,IAAI,QAAQ,CAAC;IAErC,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,cAAc,EAAE,mBAAmB;QACnC,iBAAiB,EAAE,oBAAoB;QACvC,KAAK;QACL,KAAK,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAClC,MAAM;KACP,CAAC,EACF,CAAC,mBAAmB,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAClD,CAAC;AACJ,CAAC","sourcesContent":["import { useState, useMemo, useEffect, useRef } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport assert from \"../lib/assert\";\nimport { UsePkcRpcSettingsOptions, UsePkcRpcSettingsResult, PkcRpcSettings } from \"../types\";\nimport { getProtocolClient, getRpcClients } from \"../lib/pkc-compat\";\n\nconst getFirstRpcClient = (protocolClient: any) =>\n Object.values(getRpcClients(protocolClient) || {})[0] as any;\n\n/**\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 usePkcRpcSettings(options?: UsePkcRpcSettingsOptions): UsePkcRpcSettingsResult {\n assert(\n !options || typeof options === \"object\",\n `usePkcRpcSettings options argument '${options}' not an object`,\n );\n const { accountName } = options ?? {};\n const account = useAccount({ accountName });\n const protocolClient = getProtocolClient(account);\n const rpcClient = getFirstRpcClient(protocolClient);\n const [pkcRpcSettingsState, setPkcRpcSettingsState] = useState<PkcRpcSettings>();\n const [rpcState, setRpcState] = useState<string>(\"initializing\");\n // the result of the last setPkcRpcSettings call, shown instead of the rpc state for a while\n const [saveResult, setSaveResult] = useState<string>();\n const saveResultTimeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const [errors, setErrors] = useState<Error[]>([]);\n // the rpc client whose settings and state the hook shows\n const shownRpcClient = useRef(rpcClient);\n\n const showSaveResult = (result?: string) => {\n clearTimeout(saveResultTimeout.current);\n setSaveResult(result);\n if (result) {\n saveResultTimeout.current = setTimeout(() => setSaveResult(undefined), 10000);\n }\n };\n useEffect(() => () => clearTimeout(saveResultTimeout.current), []);\n\n useEffect(() => {\n // the settings, state and save result of a previous rpc client don't apply to this one\n shownRpcClient.current = rpcClient;\n showSaveResult(undefined);\n setPkcRpcSettingsState(rpcClient?.settings ?? undefined);\n setRpcState(rpcClient?.state || \"initializing\");\n if (!account || !protocolClient) return;\n if (!rpcClient) return;\n\n const onRpcSettingsChange = (pkcRpcSettings: PkcRpcSettings) => {\n setPkcRpcSettingsState(pkcRpcSettings);\n };\n const onRpcStateChange = (rpcState: string) => {\n // a newer rpc state replaces the save result\n showSaveResult(undefined);\n setRpcState(rpcState);\n };\n const onRpcError = (e: any) => {\n setErrors((prevErrors) => [...prevErrors, e]);\n };\n\n rpcClient.on(\"settingschange\", onRpcSettingsChange);\n rpcClient.on(\"statechange\", onRpcStateChange);\n rpcClient.on(\"error\", onRpcError);\n\n // clean up\n return () => {\n rpcClient.removeListener(\"settingschange\", onRpcSettingsChange);\n rpcClient.removeListener(\"statechange\", onRpcStateChange);\n rpcClient.removeListener(\"error\", onRpcError);\n };\n }, [account?.id, rpcClient, protocolClient]);\n\n const updatePkcRpcSettings = async (pkcRpcSettings: PkcRpcSettings) => {\n assert(account, `can't use usePkcRpcSettings.setPkcRpcSettings before initialized`);\n assert(\n pkcRpcSettings && typeof pkcRpcSettings === \"object\",\n `usePkcRpcSettings.setPkcRpcSettings pkcRpcSettings argument '${pkcRpcSettings}' not an object`,\n );\n const currentRpcClient = getFirstRpcClient(getProtocolClient(account));\n assert(\n currentRpcClient,\n `can't use usePkcRpcSettings.setPkcRpcSettings no account.pkc.clients.pkcRpcClients`,\n );\n\n // a save that finishes after the hook switched to another rpc client doesn't apply to it\n try {\n await currentRpcClient.setSettings(pkcRpcSettings);\n if (currentRpcClient === shownRpcClient.current) {\n showSaveResult(\"succeeded\");\n }\n } catch (e: any) {\n if (currentRpcClient === shownRpcClient.current) {\n setErrors((prevErrors) => [...prevErrors, e]);\n showSaveResult(\"failed\");\n }\n }\n };\n\n const state = saveResult || rpcState;\n\n return useMemo(\n () => ({\n pkcRpcSettings: pkcRpcSettingsState,\n setPkcRpcSettings: updatePkcRpcSettings,\n state,\n error: errors?.[errors.length - 1],\n errors,\n }),\n [pkcRpcSettingsState, account?.id, state, errors],\n );\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,CAoMxE"}
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;AAW/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,CAgOxE"}
@@ -17,6 +17,7 @@ import { addCommentModerationToComments } from "../lib/utils/comment-moderation.
17
17
  import useRepliesStore, { feedOptionsToFeedName, getRepliesFirstPageSkipValidation, } from "../stores/replies/index.js";
18
18
  import useAccountsStore from "../stores/accounts/index.js";
19
19
  import { addOptimisticVoteCountsToComments } from "../lib/utils/optimistic-vote-counts.js";
20
+ import { isReplySortTypeUnavailable } from "../lib/page-sorts.js";
20
21
  /** Pure helper to append an error to the errors array; used for deterministic coverage of reset/loadMore catch paths. */
21
22
  export function appendErrorToErrors(prevErrors, e) {
22
23
  return [...prevErrors, e];
@@ -30,7 +31,6 @@ export function useReplies(options) {
30
31
  validateOptimistically = validateOptimistically !== false;
31
32
  const invalidFlatDepth = flat && typeof (comment === null || comment === void 0 ? void 0 : comment.depth) === "number" && flatDepth !== comment.depth;
32
33
  validator.validateUseRepliesArguments(comment, sortType, accountName, onlyIfCached, flat, accountComments, repliesPerPage, filter);
33
- const [errors, setErrors] = useState([]);
34
34
  // add replies to store
35
35
  const account = useAccount({ accountName });
36
36
  const accountVotes = useAccountsStore((state) => (account === null || account === void 0 ? void 0 : account.id) ? state.accountsVotes[account.id] : undefined);
@@ -48,6 +48,19 @@ export function useReplies(options) {
48
48
  streamPage,
49
49
  };
50
50
  const repliesFeedName = feedOptionsToFeedName(feedOptions);
51
+ // errors belong to the replies feed they happened in, another feed starts without them. Drop them
52
+ // when the feed changes (or when one lands after it changed) so they don't return with the old
53
+ // feed. The comment's postCid only fills in once it loads, that doesn't make it another feed
54
+ const errorsFeedName = feedOptionsToFeedName(Object.assign(Object.assign({}, feedOptions), { postCid: undefined }));
55
+ const [feedErrors, setFeedErrors] = useState();
56
+ if (feedErrors && feedErrors.feedName !== errorsFeedName) {
57
+ setFeedErrors(undefined);
58
+ }
59
+ const errors = (feedErrors === null || feedErrors === void 0 ? void 0 : feedErrors.feedName) === errorsFeedName ? feedErrors.errors : emptyArray;
60
+ const addError = (error) => setFeedErrors((previous) => ({
61
+ feedName: errorsFeedName,
62
+ errors: appendErrorToErrors((previous === null || previous === void 0 ? void 0 : previous.feedName) === errorsFeedName ? previous.errors : emptyArray, error),
63
+ }));
51
64
  const addFeedToStoreOrUpdateComment = useRepliesStore((state) => state.addFeedToStoreOrUpdateComment);
52
65
  useEffect(() => {
53
66
  if (!(comment === null || comment === void 0 ? void 0 : comment.cid) || !account || invalidFlatDepth) {
@@ -75,11 +88,19 @@ export function useReplies(options) {
75
88
  if (!(comment === null || comment === void 0 ? void 0 : comment.cid) || !account) {
76
89
  throw Error("useReplies cannot load more replies not initalized yet");
77
90
  }
78
- incrementFeedPageNumber(repliesFeedName);
91
+ try {
92
+ incrementFeedPageNumber(repliesFeedName);
93
+ }
94
+ catch (error) {
95
+ // infinite scroll calls loadMore before the replies feed or its current page has loaded,
96
+ // the store refuses the page increment and that isn't a replies error
97
+ log("useReplies loadMore before the replies page loaded", { repliesFeedName, error });
98
+ yield new Promise((r) => setTimeout(r, 50));
99
+ }
79
100
  }
80
101
  catch (e) {
81
102
  yield new Promise((r) => setTimeout(r, 50));
82
- setErrors(appendErrorToErrors(errors, e));
103
+ addError(e);
83
104
  }
84
105
  });
85
106
  const resetFeed = useRepliesStore((state) => state.resetFeed);
@@ -92,7 +113,7 @@ export function useReplies(options) {
92
113
  }
93
114
  catch (e) {
94
115
  yield new Promise((r) => setTimeout(r, 50));
95
- setErrors(appendErrorToErrors(errors, e));
116
+ addError(e);
96
117
  }
97
118
  });
98
119
  // optimistically avoid the initial validation delay by using skipped validation until validated feed is loaded
@@ -130,6 +151,9 @@ export function useReplies(options) {
130
151
  });
131
152
  }
132
153
  const state = !hasMore ? "succeeded" : "fetching";
154
+ // an empty result because the comment does not publish the requested sort, rather than because
155
+ // its replies are still loading or it has none
156
+ const sortTypeUnavailable = isReplySortTypeUnavailable(comment, sortType);
133
157
  const normalizedReplies = useMemo(() => addOptimisticVoteCountsToComments(addCommentModerationToComments(replies), accountVotes), [replies, accountVotes]);
134
158
  const normalizedBufferedReplies = useMemo(() => addOptimisticVoteCountsToComments(addCommentModerationToComments(bufferedReplies), accountVotes), [bufferedReplies, accountVotes]);
135
159
  const normalizedUpdatedReplies = useMemo(() => addOptimisticVoteCountsToComments(addCommentModerationToComments(updatedReplies), accountVotes), [updatedReplies, accountVotes]);
@@ -138,6 +162,7 @@ export function useReplies(options) {
138
162
  bufferedReplies: normalizedBufferedReplies,
139
163
  updatedReplies: normalizedUpdatedReplies,
140
164
  hasMore,
165
+ sortTypeUnavailable,
141
166
  loadMore,
142
167
  reset,
143
168
  state,
@@ -149,6 +174,7 @@ export function useReplies(options) {
149
174
  normalizedUpdatedReplies,
150
175
  repliesFeedName,
151
176
  hasMore,
177
+ sortTypeUnavailable,
152
178
  errors,
153
179
  ]);
154
180
  }
@@ -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,MAAM,eAAe,CAAC;AAEnC,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,eAAe,EAAE,EAEtB,qBAAqB,EACrB,iCAAiC,GAClC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,gBAAgB,MAAM,oBAAoB,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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 \"../lib/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"]}
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,eAAe,CAAC;AAEnC,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;AACxF,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAE/D,yHAAyH;AACzH,MAAM,UAAU,mBAAmB,CAAC,UAAmB,EAAE,CAAQ;IAC/D,OAAO,CAAC,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,OAA2B;;IACpD,MAAM,CACJ,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ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,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 \"../lib/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\";\nimport { isReplySortTypeUnavailable } from \"../lib/page-sorts\";\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 // 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\n // errors belong to the replies feed they happened in, another feed starts without them. Drop them\n // when the feed changes (or when one lands after it changed) so they don't return with the old\n // feed. The comment's postCid only fills in once it loads, that doesn't make it another feed\n const errorsFeedName = feedOptionsToFeedName({ ...feedOptions, postCid: undefined });\n const [feedErrors, setFeedErrors] = useState<{ feedName: string; errors: Error[] }>();\n if (feedErrors && feedErrors.feedName !== errorsFeedName) {\n setFeedErrors(undefined);\n }\n const errors = feedErrors?.feedName === errorsFeedName ? feedErrors.errors : emptyArray;\n const addError = (error: Error) =>\n setFeedErrors((previous) => ({\n feedName: errorsFeedName,\n errors: appendErrorToErrors(\n previous?.feedName === errorsFeedName ? previous.errors : emptyArray,\n error,\n ),\n }));\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 try {\n incrementFeedPageNumber(repliesFeedName);\n } catch (error) {\n // infinite scroll calls loadMore before the replies feed or its current page has loaded,\n // the store refuses the page increment and that isn't a replies error\n log(\"useReplies loadMore before the replies page loaded\", { repliesFeedName, error });\n await new Promise((r) => setTimeout(r, 50));\n }\n } catch (e: any) {\n await new Promise((r) => setTimeout(r, 50));\n addError(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 addError(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 // an empty result because the comment does not publish the requested sort, rather than because\n // its replies are still loading or it has none\n const sortTypeUnavailable = isReplySortTypeUnavailable(comment, sortType);\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 sortTypeUnavailable,\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 sortTypeUnavailable,\n errors,\n ],\n );\n}\n\nconst emptyArray: any = [];\nconst emptyFunction = async () => {};\n"]}