@bitsocial/bitsocial-react-hooks 0.1.45 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +7 -1
- package/dist/hooks/feeds/feeds.d.ts +2 -1
- package/dist/hooks/feeds/feeds.d.ts.map +1 -1
- package/dist/hooks/feeds/feeds.js +2 -1
- package/dist/hooks/feeds/feeds.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/page-sorts.d.ts +4 -0
- package/dist/lib/page-sorts.d.ts.map +1 -1
- package/dist/lib/page-sorts.js +123 -15
- package/dist/lib/page-sorts.js.map +1 -1
- package/dist/stores/communities-pages/communities-pages-store.js +7 -6
- package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
- package/dist/stores/feeds/utils.d.ts.map +1 -1
- package/dist/stores/feeds/utils.js +24 -6
- package/dist/stores/feeds/utils.js.map +1 -1
- package/dist/stores/replies/replies-store.d.ts.map +1 -1
- package/dist/stores/replies/replies-store.js +5 -1
- package/dist/stores/replies/replies-store.js.map +1 -1
- package/dist/stores/replies/utils.d.ts.map +1 -1
- package/dist/stores/replies/utils.js +9 -7
- package/dist/stores/replies/utils.js.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.js +7 -6
- package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
- package/package.json +8 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [0.1.46](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.45...v0.1.46) (2026-09-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **feeds:** serve standard sorts from a complete preloaded page ([#116](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/116)) ([8b35e6d](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/8b35e6de19dcf501fa229291dd6c2eb3895f2c78))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
## [0.1.45](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.44...v0.1.45) (2026-09-09)
|
|
2
11
|
|
|
3
12
|
|
package/README.md
CHANGED
|
@@ -32,6 +32,8 @@ yarn install
|
|
|
32
32
|
|
|
33
33
|
Run `corepack enable` once per machine so plain `yarn` resolves to the pinned Yarn 4 release.
|
|
34
34
|
|
|
35
|
+
AI contributor guidance starts in [AGENTS.md](AGENTS.md). Edit shared skills and roles in `.agents/`, then run `yarn ai-workflow:sync`, `yarn ai-workflow:check`, and `yarn ai-workflow:test`; commit generated native app files with their sources. See [skills and tools](docs/agent-playbooks/skills-and-tools.md) for discovery paths and [verification](docs/agent-playbooks/verification.md) for checks appropriate to each change.
|
|
36
|
+
|
|
35
37
|
---
|
|
36
38
|
|
|
37
39
|
## Table of Contents
|
|
@@ -168,7 +170,7 @@ useBufferedFeeds({feedsOptions: UseFeedOptions[]}) // preload or buffer feeds in
|
|
|
168
170
|
`useFeed().reset()` clears the current feed and refreshes the latest community snapshots before rebuilding it.
|
|
169
171
|
`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
172
|
|
|
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
|
|
173
|
+
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 requestable names with `getAvailablePostSortTypes(community)` and `getAvailableReplySortTypes(comment)`. pkc-js preloads a single sort and only publishes `pageCids` once that page overflows, so when every post or reply fits in the preloaded page the standard sorts (`hot`, `new`, `active` and `top*` for posts; `best`, `new`, `old`, `newFlat` and `oldFlat` for replies) are also requestable and are sorted client-side from that page, including the time window of `top*` timeframe sorts. `getPostPageSortType(community, sortType)` and `getReplyPageSortType(comment, sortType)` return the page that serves a sort. A requested sort that is neither published nor computable client-side 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.
|
|
172
174
|
|
|
173
175
|
#### Actions Hooks
|
|
174
176
|
|
|
@@ -235,6 +237,10 @@ getPreloadedPostSortType(community: Community): string | undefined
|
|
|
235
237
|
getPreloadedReplySortType(comment: Comment): string | undefined
|
|
236
238
|
resolvePostSortType(community: Community, requestedSortType?: string): string | undefined
|
|
237
239
|
resolveReplySortType(comment: Comment, requestedSortType?: string): string | undefined
|
|
240
|
+
getPostPageSortType(community: Community, requestedSortType?: string): string | undefined // page sort serving the request, e.g. the preloaded page a single-page community re-sorts client-side
|
|
241
|
+
getReplyPageSortType(comment: Comment, requestedSortType?: string): string | undefined
|
|
242
|
+
getSortTimeframeSeconds(sortType?: string): number | undefined // time window of top*/controversial* timeframe sorts
|
|
243
|
+
isFlatSortType(sortType?: string): boolean
|
|
238
244
|
```
|
|
239
245
|
|
|
240
246
|
`createCrosspost` requires a fully loaded comment with `comment.cid` and
|
|
@@ -1,7 +1,8 @@
|
|
|
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 - A sort name published by the community
|
|
4
|
+
* @param sortType - A sort name published by the community, or a standard sort computed client-side
|
|
5
|
+
* when every post fits in the preloaded page. Omit it to use the preloaded sort.
|
|
5
6
|
* @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
|
|
6
7
|
* the active account.
|
|
7
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
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;AAarB
|
|
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;AAarB;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CAsL/D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,sBAAsB,CAwI1F"}
|
|
@@ -22,7 +22,8 @@ import { getCommunityRefKeys, getUniqueSortedCommunityRefs, } from "../../lib/co
|
|
|
22
22
|
import { serializeFeedKey } from "../../lib/serialize-feed-key.js";
|
|
23
23
|
/**
|
|
24
24
|
* @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]
|
|
25
|
-
* @param sortType - A sort name published by the community
|
|
25
|
+
* @param sortType - A sort name published by the community, or a standard sort computed client-side
|
|
26
|
+
* when every post fits in the preloaded page. Omit it to use the preloaded sort.
|
|
26
27
|
* @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
|
|
27
28
|
* the active account.
|
|
28
29
|
*/
|
|
@@ -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,GA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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 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\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 accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\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 // 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 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
|
+
{"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,O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E,SAAS,CAAC;IAC5D,MAAM,qBAAqB,GAAG,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,MAAM,CAAC;IACtD,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,OAAO,gBAAgB,CAAC;YACtB,SAAS;YACT,QAAQ;YACR,mBAAmB;YACnB,YAAY;YACZ,SAAS;YACT,SAAS;YACT,wBAAwB;YACxB,qBAAqB;YACrB,QAAQ;SACT,CAAC,CAAC;IACL,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,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, 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 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\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 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 // 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 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"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,9 +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
|
+
import { getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType } from "./lib/page-sorts.js";
|
|
16
16
|
export * from "./types.js";
|
|
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, useSaveComment, 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
|
+
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, useSaveComment, 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, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType, };
|
|
18
18
|
declare const hooks: {
|
|
19
19
|
useAccount: typeof useAccount;
|
|
20
20
|
useAccounts: typeof useAccounts;
|
|
@@ -87,6 +87,10 @@ declare const hooks: {
|
|
|
87
87
|
getAvailableReplySortTypes: (comment?: import("./types.js").Comment) => string[];
|
|
88
88
|
getPreloadedPostSortType: (community?: import("./types.js").Community) => string | undefined;
|
|
89
89
|
getPreloadedReplySortType: (comment?: import("./types.js").Comment) => string | undefined;
|
|
90
|
+
getPostPageSortType: (community: import("./types.js").Community | undefined, requestedSortType?: string) => string | undefined;
|
|
91
|
+
getReplyPageSortType: (comment: import("./types.js").Comment | undefined, requestedSortType?: string) => string | undefined;
|
|
92
|
+
getSortTimeframeSeconds: (sortType?: string) => number | undefined;
|
|
93
|
+
isFlatSortType: (sortType?: string) => boolean;
|
|
90
94
|
resolvePostSortType: (community: import("./types.js").Community | undefined, requestedSortType?: string) => string | undefined;
|
|
91
95
|
resolveReplySortType: (comment: import("./types.js").Comment | undefined, requestedSortType?: string) => string | undefined;
|
|
92
96
|
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EACl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MAAM,iBAAiB,CAAC;AAClD,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAG1B,cAAc,SAAS,CAAC;AAGxB,OAAO,EAEL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAElB,UAAU,EACV,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAElB,UAAU,EAEV,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,2BAA2B,EAE3B,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,yCAAyC,EACzC,iCAAiC,EAEjC,OAAO,EACP,gBAAgB,EAEhB,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,2BAA2B,EAC3B,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAElB,aAAa,EACb,aAAa,EACb,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EAEf,gBAAgB,EAChB,oBAAoB,EAEpB,iBAAiB,EAEjB,6BAA6B,EAC7B,iCAAiC,EACjC,iBAAiB,EAEjB,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,eAAe,EACf,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,GACrB,CAAC;AAGF,QAAA,MAAM,KAAK
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmFV,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ 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
|
+
import { getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType, } from "./lib/page-sorts.js";
|
|
30
30
|
// types
|
|
31
31
|
export * from "./types.js";
|
|
32
32
|
// IMPORTANT: should be the same as 'export default hooks'
|
|
@@ -54,7 +54,7 @@ usePkcRpcSettings,
|
|
|
54
54
|
// chain
|
|
55
55
|
getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, validateEthWallet,
|
|
56
56
|
// utils
|
|
57
|
-
setPkcJs, restorePkcJs, deleteDatabases, deleteCaches, createCrosspost, getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, resolvePostSortType, resolveReplySortType, };
|
|
57
|
+
setPkcJs, restorePkcJs, deleteDatabases, deleteCaches, createCrosspost, getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType, };
|
|
58
58
|
// IMPORTANT: should be the same as 'export {}'
|
|
59
59
|
const hooks = {
|
|
60
60
|
// accounts
|
|
@@ -133,6 +133,10 @@ const hooks = {
|
|
|
133
133
|
getAvailableReplySortTypes,
|
|
134
134
|
getPreloadedPostSortType,
|
|
135
135
|
getPreloadedReplySortType,
|
|
136
|
+
getPostPageSortType,
|
|
137
|
+
getReplyPageSortType,
|
|
138
|
+
getSortTimeframeSeconds,
|
|
139
|
+
isFlatSortType,
|
|
136
140
|
resolvePostSortType,
|
|
137
141
|
resolveReplySortType,
|
|
138
142
|
};
|
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,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,cAAc,EACd,iBAAiB,EACjB,c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B,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;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 useSaveComment,\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 useSaveComment,\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 useSaveComment,\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"]}
|
|
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,cAAc,EACd,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,g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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;IACf,yBAAyB;IACzB,0BAA0B;IAC1B,wBAAwB;IACxB,yBAAyB;IACzB,mBAAmB;IACnB,oBAAoB;IACpB,uBAAuB;IACvB,cAAc;IACd,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 useSaveComment,\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 getPostPageSortType,\n getReplyPageSortType,\n getSortTimeframeSeconds,\n isFlatSortType,\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 useSaveComment,\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 getPostPageSortType,\n getReplyPageSortType,\n getSortTimeframeSeconds,\n isFlatSortType,\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 useSaveComment,\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 getPostPageSortType,\n getReplyPageSortType,\n getSortTimeframeSeconds,\n isFlatSortType,\n resolvePostSortType,\n resolveReplySortType,\n};\n\nexport default hooks;\n"]}
|
package/dist/lib/page-sorts.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Comment, Community } from "../types.js";
|
|
2
|
+
export declare const isFlatSortType: (sortType?: string) => boolean;
|
|
3
|
+
export declare const getSortTimeframeSeconds: (sortType?: string) => number | undefined;
|
|
2
4
|
export declare const getAvailablePostSortTypes: (community?: Community) => string[];
|
|
3
5
|
export declare const getAvailableReplySortTypes: (comment?: Comment) => string[];
|
|
4
6
|
export declare const getPreloadedPostSortType: (community?: Community) => string | undefined;
|
|
5
7
|
export declare const getPreloadedReplySortType: (comment?: Comment) => string | undefined;
|
|
6
8
|
export declare const resolvePostSortType: (community: Community | undefined, requestedSortType?: string) => string | undefined;
|
|
7
9
|
export declare const resolveReplySortType: (comment: Comment | undefined, requestedSortType?: string) => string | undefined;
|
|
10
|
+
export declare const getPostPageSortType: (community: Community | undefined, requestedSortType?: string) => string | undefined;
|
|
11
|
+
export declare const getReplyPageSortType: (comment: Comment | undefined, requestedSortType?: string) => string | undefined;
|
|
8
12
|
//# sourceMappingURL=page-sorts.d.ts.map
|
|
@@ -1 +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;
|
|
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;AA4C9C,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,OAA8C,CAAC;AAElG,eAAO,MAAM,uBAAuB,GAAI,WAAW,MAAM,KAAG,MAAM,GAAG,SAGpE,CAAC;AAyHF,eAAO,MAAM,yBAAyB,GAAI,YAAY,SAAS,KAAG,MAAM,EACM,CAAC;AAE/E,eAAO,MAAM,0BAA0B,GAAI,UAAU,OAAO,KAAG,MAAM,EACkB,CAAC;AAExF,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,SAC+E,CAAC;AAE5F,eAAO,MAAM,oBAAoB,GAC/B,SAAS,OAAO,GAAG,SAAS,EAC5B,oBAAoB,MAAM,KACzB,MAAM,GAAG,SAKT,CAAC;AAIJ,eAAO,MAAM,mBAAmB,GAC9B,WAAW,SAAS,GAAG,SAAS,EAChC,oBAAoB,MAAM,KACzB,MAAM,GAAG,SACgF,CAAC;AAE7F,eAAO,MAAM,oBAAoB,GAC/B,SAAS,OAAO,GAAG,SAAS,EAC5B,oBAAoB,MAAM,KACzB,MAAM,GAAG,SAC+E,CAAC"}
|
package/dist/lib/page-sorts.js
CHANGED
|
@@ -1,4 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
// Standard pkc-js sorts (pkc-js src/pages/util.ts) whose scoring the feed sorter reproduces. pkc-js
|
|
2
|
+
// preloads a single sort and only publishes pageCids once that page overflows, so a record whose
|
|
3
|
+
// comments all fit in the preloaded page can serve any of these by re-sorting that page client-side.
|
|
4
|
+
const CLIENT_SORTABLE_POST_SORT_TYPES = [
|
|
5
|
+
"hot",
|
|
6
|
+
"new",
|
|
7
|
+
"active",
|
|
8
|
+
"topHour",
|
|
9
|
+
"topDay",
|
|
10
|
+
"topWeek",
|
|
11
|
+
"topMonth",
|
|
12
|
+
"topYear",
|
|
13
|
+
"topAll",
|
|
14
|
+
];
|
|
15
|
+
const CLIENT_SORTABLE_REPLY_SORT_TYPES = ["best", "new", "old", "newFlat", "oldFlat"];
|
|
16
|
+
// pkc-js only publishes flat sorts for a post's replies (REPLY_REPLIES_SORT_TYPES has none), so a
|
|
17
|
+
// nested reply must not advertise them while its replies still fit in the preloaded page
|
|
18
|
+
const getClientSortableReplySortTypes = (comment) => {
|
|
19
|
+
const isPost = (comment === null || comment === void 0 ? void 0 : comment.depth) !== undefined ? comment.depth === 0 : !(comment === null || comment === void 0 ? void 0 : comment.parentCid);
|
|
20
|
+
return isPost
|
|
21
|
+
? CLIENT_SORTABLE_REPLY_SORT_TYPES
|
|
22
|
+
: CLIENT_SORTABLE_REPLY_SORT_TYPES.filter((sortType) => !isFlatSortType(sortType));
|
|
23
|
+
};
|
|
24
|
+
// pkc-js TIMEFRAMES_TO_SECONDS, applied client-side when a timeframe sort is computed from a
|
|
25
|
+
// preloaded page instead of a page the community windowed itself
|
|
26
|
+
const SORT_TIMEFRAMES_SECONDS = {
|
|
27
|
+
Hour: 3600,
|
|
28
|
+
Day: 86400,
|
|
29
|
+
Week: 604800,
|
|
30
|
+
Month: 2629746,
|
|
31
|
+
Year: 31557600,
|
|
32
|
+
};
|
|
33
|
+
export const isFlatSortType = (sortType) => Boolean(sortType === null || sortType === void 0 ? void 0 : sortType.endsWith("Flat"));
|
|
34
|
+
export const getSortTimeframeSeconds = (sortType) => {
|
|
35
|
+
var _a;
|
|
36
|
+
const timeframe = (_a = sortType === null || sortType === void 0 ? void 0 : sortType.match(/^(?:top|controversial)(Hour|Day|Week|Month|Year)$/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
37
|
+
return timeframe ? SORT_TIMEFRAMES_SECONDS[timeframe] : undefined;
|
|
38
|
+
};
|
|
39
|
+
const getPublishedPageSortTypes = (record) => {
|
|
2
40
|
const sortTypes = new Set();
|
|
3
41
|
for (const sortType of Object.keys((record === null || record === void 0 ? void 0 : record.pages) || {})) {
|
|
4
42
|
if (sortType)
|
|
@@ -10,28 +48,98 @@ const getAvailablePageSortTypes = (record) => {
|
|
|
10
48
|
}
|
|
11
49
|
return [...sortTypes];
|
|
12
50
|
};
|
|
51
|
+
// preloaded pages holding the record's complete comment set: no page continues with a nextCid and
|
|
52
|
+
// no pageCids are published (pkc-js publishes pageCids for every sort once the preloaded page overflows)
|
|
53
|
+
const getCompletePreloadedPageSortTypes = (record) => {
|
|
54
|
+
if (Object.keys((record === null || record === void 0 ? void 0 : record.pageCids) || {}).length > 0) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
const pages = (record === null || record === void 0 ? void 0 : record.pages) || {};
|
|
58
|
+
const sortTypes = Object.keys(pages).filter((sortType) => { var _a; return Array.isArray((_a = pages[sortType]) === null || _a === void 0 ? void 0 : _a.comments); });
|
|
59
|
+
if (!sortTypes.length ||
|
|
60
|
+
sortTypes.some((sortType) => { var _a; return (_a = pages[sortType]) === null || _a === void 0 ? void 0 : _a.nextCid; })) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
// a page windowed by a timeframe sort only holds that window, never the complete set
|
|
64
|
+
return sortTypes.filter((sortType) => !getSortTimeframeSeconds(sortType));
|
|
65
|
+
};
|
|
66
|
+
// a flat sort flattens the whole reply tree, so every nested reply chain must be complete too
|
|
67
|
+
const hasCompleteReplyTree = (page) => ((page === null || page === void 0 ? void 0 : page.comments) || []).every((comment) => {
|
|
68
|
+
var _a;
|
|
69
|
+
const completeSortTypes = getCompletePreloadedPageSortTypes(comment === null || comment === void 0 ? void 0 : comment.replies);
|
|
70
|
+
if (!completeSortTypes.length) {
|
|
71
|
+
// no preloaded replies is only complete when the comment reports none, and a continued or
|
|
72
|
+
// paged chain is never complete
|
|
73
|
+
return !((comment === null || comment === void 0 ? void 0 : comment.replyCount) > 0) && !Object.keys(((_a = comment === null || comment === void 0 ? void 0 : comment.replies) === null || _a === void 0 ? void 0 : _a.pages) || {}).length;
|
|
74
|
+
}
|
|
75
|
+
const hierarchicalSortType = completeSortTypes.find((sortType) => !isFlatSortType(sortType));
|
|
76
|
+
return hierarchicalSortType === undefined
|
|
77
|
+
? true
|
|
78
|
+
: hasCompleteReplyTree(comment.replies.pages[hierarchicalSortType]);
|
|
79
|
+
});
|
|
80
|
+
// a flat page cannot rebuild the reply tree, so it only serves flat sorts; a hierarchical page
|
|
81
|
+
// serves flat sorts only when its nested reply chains are complete
|
|
82
|
+
const getClientSortableSortTypes = (record, clientSortableSortTypes) => {
|
|
83
|
+
var _a;
|
|
84
|
+
const completeSortTypes = getCompletePreloadedPageSortTypes(record);
|
|
85
|
+
if (!completeSortTypes.length) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
const hierarchicalSortType = completeSortTypes.find((sortType) => !isFlatSortType(sortType));
|
|
89
|
+
if (hierarchicalSortType === undefined) {
|
|
90
|
+
return clientSortableSortTypes.filter(isFlatSortType);
|
|
91
|
+
}
|
|
92
|
+
const canFlatten = completeSortTypes.some(isFlatSortType) ||
|
|
93
|
+
hasCompleteReplyTree((_a = record === null || record === void 0 ? void 0 : record.pages) === null || _a === void 0 ? void 0 : _a[hierarchicalSortType]);
|
|
94
|
+
return canFlatten
|
|
95
|
+
? clientSortableSortTypes
|
|
96
|
+
: clientSortableSortTypes.filter((sortType) => !isFlatSortType(sortType));
|
|
97
|
+
};
|
|
98
|
+
const getAvailablePageSortTypes = (record, clientSortableSortTypes) => {
|
|
99
|
+
const sortTypes = getPublishedPageSortTypes(record);
|
|
100
|
+
for (const sortType of getClientSortableSortTypes(record, clientSortableSortTypes)) {
|
|
101
|
+
if (!sortTypes.includes(sortType))
|
|
102
|
+
sortTypes.push(sortType);
|
|
103
|
+
}
|
|
104
|
+
return sortTypes;
|
|
105
|
+
};
|
|
13
106
|
const getPreloadedPageSortType = (record) => {
|
|
14
107
|
const preloadedSortType = Object.keys((record === null || record === void 0 ? void 0 : record.pages) || {}).find(Boolean);
|
|
15
|
-
return preloadedSortType ||
|
|
108
|
+
return preloadedSortType || getPublishedPageSortTypes(record)[0];
|
|
16
109
|
};
|
|
17
|
-
|
|
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) => {
|
|
110
|
+
const resolvePageSortType = (record, requestedSortType, clientSortableSortTypes) => {
|
|
22
111
|
if (requestedSortType !== undefined) {
|
|
23
|
-
return
|
|
112
|
+
return getAvailablePageSortTypes(record, clientSortableSortTypes).includes(requestedSortType)
|
|
24
113
|
? requestedSortType
|
|
25
114
|
: undefined;
|
|
26
115
|
}
|
|
27
|
-
return
|
|
116
|
+
return getPreloadedPageSortType(record);
|
|
28
117
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
118
|
+
// the page that serves a resolved sort: its published page, or the complete preloaded page the
|
|
119
|
+
// client re-sorts (a flat sort prefers a complete flat page, else flattens a hierarchical one)
|
|
120
|
+
const getPageSortTypeToRead = (record, sortType) => {
|
|
121
|
+
var _a;
|
|
122
|
+
if (sortType === undefined) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
if (getPublishedPageSortTypes(record).includes(sortType)) {
|
|
126
|
+
return sortType;
|
|
127
|
+
}
|
|
128
|
+
const completeSortTypes = getCompletePreloadedPageSortTypes(record);
|
|
129
|
+
const hierarchicalSortType = completeSortTypes.find((preloadedSortType) => !isFlatSortType(preloadedSortType));
|
|
130
|
+
if (isFlatSortType(sortType)) {
|
|
131
|
+
return (_a = completeSortTypes.find(isFlatSortType)) !== null && _a !== void 0 ? _a : hierarchicalSortType;
|
|
34
132
|
}
|
|
35
|
-
return
|
|
133
|
+
return hierarchicalSortType;
|
|
36
134
|
};
|
|
135
|
+
export const getAvailablePostSortTypes = (community) => getAvailablePageSortTypes(community === null || community === void 0 ? void 0 : community.posts, CLIENT_SORTABLE_POST_SORT_TYPES);
|
|
136
|
+
export const getAvailableReplySortTypes = (comment) => getAvailablePageSortTypes(comment === null || comment === void 0 ? void 0 : comment.replies, getClientSortableReplySortTypes(comment));
|
|
137
|
+
export const getPreloadedPostSortType = (community) => getPreloadedPageSortType(community === null || community === void 0 ? void 0 : community.posts);
|
|
138
|
+
export const getPreloadedReplySortType = (comment) => getPreloadedPageSortType(comment === null || comment === void 0 ? void 0 : comment.replies);
|
|
139
|
+
export const resolvePostSortType = (community, requestedSortType) => resolvePageSortType(community === null || community === void 0 ? void 0 : community.posts, requestedSortType, CLIENT_SORTABLE_POST_SORT_TYPES);
|
|
140
|
+
export const resolveReplySortType = (comment, requestedSortType) => resolvePageSortType(comment === null || comment === void 0 ? void 0 : comment.replies, requestedSortType, getClientSortableReplySortTypes(comment));
|
|
141
|
+
// the `community.posts` page sort that serves a request, e.g. the preloaded `hot` page when a
|
|
142
|
+
// single-page community serves `active` client-side; undefined when the sort cannot be served
|
|
143
|
+
export const getPostPageSortType = (community, requestedSortType) => getPageSortTypeToRead(community === null || community === void 0 ? void 0 : community.posts, resolvePostSortType(community, requestedSortType));
|
|
144
|
+
export const getReplyPageSortType = (comment, requestedSortType) => getPageSortTypeToRead(comment === null || comment === void 0 ? void 0 : comment.replies, resolveReplySortType(comment, requestedSortType));
|
|
37
145
|
//# sourceMappingURL=page-sorts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-sorts.js","sourceRoot":"","sources":["../../src/lib/page-sorts.ts"],"names":[],"mappings":"AAOA,MAAM,yBAAyB,GAAG,CAAC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AAS,aAAT,SAAS,uBAAT,SAAS,CAAE,KAAK,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,OAAiB,EAAsB,EAAE,CACjF,wBAAwB,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,SAAgC,EAChC,iBAA0B,EACN,EAAE;IACtB,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACpC,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YACrE,CAAC,CAAC,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"]}
|
|
1
|
+
{"version":3,"file":"page-sorts.js","sourceRoot":"","sources":["../../src/lib/page-sorts.ts"],"names":[],"mappings":"AASA,oGAAoG;AACpG,iGAAiG;AACjG,qGAAqG;AACrG,MAAM,+BAA+B,GAAG;IACtC,KAAK;IACL,KAAK;IACL,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,SAAS;IACT,UAAU;IACV,SAAS;IACT,QAAQ;CACT,CAAC;AACF,MAAM,gCAAgC,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAEtF,kGAAkG;AAClG,yFAAyF;AACzF,MAAM,+BAA+B,GAAG,CAAC,OAAiB,EAAY,EAAE;IACtE,MAAM,MAAM,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,MAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA,O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,CAAC;AAExF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,SAAqB,EAAsB,EAAE,CACpF,wBAAwB,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,KAAK,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,OAAiB,EAAsB,EAAE,CACjF,wBAAwB,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,SAAgC,EAChC,iBAA0B,EACN,EAAE,CACtB,mBAAmB,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,KAAK,EAAE,iBAAiB,EAAE,+BAA+B,CAAC,CAAC;AAE5F,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAA4B,EAC5B,iBAA0B,EACN,EAAE,CACtB,mBAAmB,CACjB,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAChB,iBAAiB,EACjB,+BAA+B,CAAC,OAAO,CAAC,CACzC,CAAC;AAEJ,8FAA8F;AAC9F,8FAA8F;AAC9F,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,SAAgC,EAChC,iBAA0B,EACN,EAAE,CACtB,qBAAqB,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,KAAK,EAAE,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAE7F,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAA4B,EAC5B,iBAA0B,EACN,EAAE,CACtB,qBAAqB,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAAE,oBAAoB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC","sourcesContent":["import { Comment, Community } from \"../types\";\n\ntype PagesRecord = {\n pages?: Record<string, unknown>;\n pageCids?: Record<string, unknown>;\n};\n\ntype PreloadedPage = { comments?: unknown; nextCid?: string } | undefined;\n\n// Standard pkc-js sorts (pkc-js src/pages/util.ts) whose scoring the feed sorter reproduces. pkc-js\n// preloads a single sort and only publishes pageCids once that page overflows, so a record whose\n// comments all fit in the preloaded page can serve any of these by re-sorting that page client-side.\nconst CLIENT_SORTABLE_POST_SORT_TYPES = [\n \"hot\",\n \"new\",\n \"active\",\n \"topHour\",\n \"topDay\",\n \"topWeek\",\n \"topMonth\",\n \"topYear\",\n \"topAll\",\n];\nconst CLIENT_SORTABLE_REPLY_SORT_TYPES = [\"best\", \"new\", \"old\", \"newFlat\", \"oldFlat\"];\n\n// pkc-js only publishes flat sorts for a post's replies (REPLY_REPLIES_SORT_TYPES has none), so a\n// nested reply must not advertise them while its replies still fit in the preloaded page\nconst getClientSortableReplySortTypes = (comment?: Comment): string[] => {\n const isPost = comment?.depth !== undefined ? comment.depth === 0 : !comment?.parentCid;\n return isPost\n ? CLIENT_SORTABLE_REPLY_SORT_TYPES\n : CLIENT_SORTABLE_REPLY_SORT_TYPES.filter((sortType) => !isFlatSortType(sortType));\n};\n\n// pkc-js TIMEFRAMES_TO_SECONDS, applied client-side when a timeframe sort is computed from a\n// preloaded page instead of a page the community windowed itself\nconst SORT_TIMEFRAMES_SECONDS: Record<string, number> = {\n Hour: 3600,\n Day: 86400,\n Week: 604800,\n Month: 2629746,\n Year: 31557600,\n};\n\nexport const isFlatSortType = (sortType?: string): boolean => Boolean(sortType?.endsWith(\"Flat\"));\n\nexport const getSortTimeframeSeconds = (sortType?: string): number | undefined => {\n const timeframe = sortType?.match(/^(?:top|controversial)(Hour|Day|Week|Month|Year)$/)?.[1];\n return timeframe ? SORT_TIMEFRAMES_SECONDS[timeframe] : undefined;\n};\n\nconst getPublishedPageSortTypes = (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\n// preloaded pages holding the record's complete comment set: no page continues with a nextCid and\n// no pageCids are published (pkc-js publishes pageCids for every sort once the preloaded page overflows)\nconst getCompletePreloadedPageSortTypes = (record?: PagesRecord): string[] => {\n if (Object.keys(record?.pageCids || {}).length > 0) {\n return [];\n }\n const pages = record?.pages || {};\n const sortTypes = Object.keys(pages).filter((sortType) =>\n Array.isArray((pages[sortType] as PreloadedPage)?.comments),\n );\n if (\n !sortTypes.length ||\n sortTypes.some((sortType) => (pages[sortType] as PreloadedPage)?.nextCid)\n ) {\n return [];\n }\n // a page windowed by a timeframe sort only holds that window, never the complete set\n return sortTypes.filter((sortType) => !getSortTimeframeSeconds(sortType));\n};\n\n// a flat sort flattens the whole reply tree, so every nested reply chain must be complete too\nconst hasCompleteReplyTree = (page: PreloadedPage): boolean =>\n ((page?.comments as Comment[] | undefined) || []).every((comment) => {\n const completeSortTypes = getCompletePreloadedPageSortTypes(comment?.replies);\n if (!completeSortTypes.length) {\n // no preloaded replies is only complete when the comment reports none, and a continued or\n // paged chain is never complete\n return !(comment?.replyCount > 0) && !Object.keys(comment?.replies?.pages || {}).length;\n }\n const hierarchicalSortType = completeSortTypes.find((sortType) => !isFlatSortType(sortType));\n return hierarchicalSortType === undefined\n ? true\n : hasCompleteReplyTree(comment.replies.pages[hierarchicalSortType]);\n });\n\n// a flat page cannot rebuild the reply tree, so it only serves flat sorts; a hierarchical page\n// serves flat sorts only when its nested reply chains are complete\nconst getClientSortableSortTypes = (\n record: PagesRecord | undefined,\n clientSortableSortTypes: string[],\n): string[] => {\n const completeSortTypes = getCompletePreloadedPageSortTypes(record);\n if (!completeSortTypes.length) {\n return [];\n }\n const hierarchicalSortType = completeSortTypes.find((sortType) => !isFlatSortType(sortType));\n if (hierarchicalSortType === undefined) {\n return clientSortableSortTypes.filter(isFlatSortType);\n }\n const canFlatten =\n completeSortTypes.some(isFlatSortType) ||\n hasCompleteReplyTree(record?.pages?.[hierarchicalSortType] as PreloadedPage);\n return canFlatten\n ? clientSortableSortTypes\n : clientSortableSortTypes.filter((sortType) => !isFlatSortType(sortType));\n};\n\nconst getAvailablePageSortTypes = (\n record: PagesRecord | undefined,\n clientSortableSortTypes: string[],\n): string[] => {\n const sortTypes = getPublishedPageSortTypes(record);\n for (const sortType of getClientSortableSortTypes(record, clientSortableSortTypes)) {\n if (!sortTypes.includes(sortType)) sortTypes.push(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 || getPublishedPageSortTypes(record)[0];\n};\n\nconst resolvePageSortType = (\n record: PagesRecord | undefined,\n requestedSortType: string | undefined,\n clientSortableSortTypes: string[],\n): string | undefined => {\n if (requestedSortType !== undefined) {\n return getAvailablePageSortTypes(record, clientSortableSortTypes).includes(requestedSortType)\n ? requestedSortType\n : undefined;\n }\n return getPreloadedPageSortType(record);\n};\n\n// the page that serves a resolved sort: its published page, or the complete preloaded page the\n// client re-sorts (a flat sort prefers a complete flat page, else flattens a hierarchical one)\nconst getPageSortTypeToRead = (\n record: PagesRecord | undefined,\n sortType: string | undefined,\n): string | undefined => {\n if (sortType === undefined) {\n return undefined;\n }\n if (getPublishedPageSortTypes(record).includes(sortType)) {\n return sortType;\n }\n const completeSortTypes = getCompletePreloadedPageSortTypes(record);\n const hierarchicalSortType = completeSortTypes.find(\n (preloadedSortType) => !isFlatSortType(preloadedSortType),\n );\n if (isFlatSortType(sortType)) {\n return completeSortTypes.find(isFlatSortType) ?? hierarchicalSortType;\n }\n return hierarchicalSortType;\n};\n\nexport const getAvailablePostSortTypes = (community?: Community): string[] =>\n getAvailablePageSortTypes(community?.posts, CLIENT_SORTABLE_POST_SORT_TYPES);\n\nexport const getAvailableReplySortTypes = (comment?: Comment): string[] =>\n getAvailablePageSortTypes(comment?.replies, getClientSortableReplySortTypes(comment));\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 resolvePageSortType(community?.posts, requestedSortType, CLIENT_SORTABLE_POST_SORT_TYPES);\n\nexport const resolveReplySortType = (\n comment: Comment | undefined,\n requestedSortType?: string,\n): string | undefined =>\n resolvePageSortType(\n comment?.replies,\n requestedSortType,\n getClientSortableReplySortTypes(comment),\n );\n\n// the `community.posts` page sort that serves a request, e.g. the preloaded `hot` page when a\n// single-page community serves `active` client-side; undefined when the sort cannot be served\nexport const getPostPageSortType = (\n community: Community | undefined,\n requestedSortType?: string,\n): string | undefined =>\n getPageSortTypeToRead(community?.posts, resolvePostSortType(community, requestedSortType));\n\nexport const getReplyPageSortType = (\n comment: Comment | undefined,\n requestedSortType?: string,\n): string | undefined =>\n getPageSortTypeToRead(comment?.replies, resolveReplySortType(comment, requestedSortType));\n"]}
|
|
@@ -17,7 +17,7 @@ import localForageLru from "../../lib/localforage-lru/index.js";
|
|
|
17
17
|
import createStore from "zustand";
|
|
18
18
|
import assert from "assert";
|
|
19
19
|
import { createPkcCommunity, getPkcCreateCommunity, normalizeCommentCommunityAddress, } from "../../lib/pkc-compat.js";
|
|
20
|
-
import {
|
|
20
|
+
import { getPostPageSortType } from "../../lib/page-sorts.js";
|
|
21
21
|
const communitiesPagesDatabase = localForageLru.createInstance({
|
|
22
22
|
name: "bitsocialReactHooks-communitiesPages",
|
|
23
23
|
size: 500,
|
|
@@ -284,15 +284,16 @@ export const getCommunityFirstPageCid = (community, sortType, pageType = "posts"
|
|
|
284
284
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
285
285
|
assert(community && typeof community === "object", `getCommunityFirstPageCid community '${community}' invalid`);
|
|
286
286
|
assert(sortType === undefined || (typeof sortType === "string" && sortType.length > 0), `getCommunityFirstPageCid sortType '${sortType}' invalid`);
|
|
287
|
-
|
|
288
|
-
|
|
287
|
+
// posts served client-side from a complete preloaded page read that page instead of their own
|
|
288
|
+
const pageSortType = pageType === "posts" ? getPostPageSortType(community, sortType) : sortType;
|
|
289
|
+
if (!pageSortType) {
|
|
289
290
|
return;
|
|
290
291
|
}
|
|
291
292
|
// community has preloaded posts for sort type
|
|
292
|
-
if ((_c = (_b = (_a = community[pageType]) === null || _a === void 0 ? void 0 : _a.pages) === null || _b === void 0 ? void 0 : _b[
|
|
293
|
-
return (_f = (_e = (_d = community[pageType]) === null || _d === void 0 ? void 0 : _d.pages) === null || _e === void 0 ? void 0 : _e[
|
|
293
|
+
if ((_c = (_b = (_a = community[pageType]) === null || _a === void 0 ? void 0 : _a.pages) === null || _b === void 0 ? void 0 : _b[pageSortType]) === null || _c === void 0 ? void 0 : _c.comments) {
|
|
294
|
+
return (_f = (_e = (_d = community[pageType]) === null || _d === void 0 ? void 0 : _d.pages) === null || _e === void 0 ? void 0 : _e[pageSortType]) === null || _f === void 0 ? void 0 : _f.nextCid;
|
|
294
295
|
}
|
|
295
|
-
return (_h = (_g = community[pageType]) === null || _g === void 0 ? void 0 : _g.pageCids) === null || _h === void 0 ? void 0 : _h[
|
|
296
|
+
return (_h = (_g = community[pageType]) === null || _g === void 0 ? void 0 : _g.pageCids) === null || _h === void 0 ? void 0 : _h[pageSortType];
|
|
296
297
|
// TODO: if a loaded community doesn't have a first page, it's unclear what we should do
|
|
297
298
|
// should we try to use another sort type by default, like 'hot', or should we just ignore it?
|
|
298
299
|
};
|