Utility functions
Utility functions in Bitsocial React Hooks. Usage, options, and examples.
setPkcJs(PKC) // swap the underlying protocol client implementation, e.g. for mocks or Electron
deleteDatabases() // delete all databases, including all caches and accounts data
deleteCaches() // delete the cached comments, cached communities and cached pages only, no accounts data
createCrosspost(comment: Comment): Crosspost // build the immutable payload accepted by pkc-js
getAvailablePostSortTypes(community: Community): string[]
getAvailableReplySortTypes(comment: Comment): string[]
getPreloadedPostSortType(community: Community): string | undefined
getPreloadedReplySortType(comment: Comment): string | undefined
resolvePostSortType(community: Community, requestedSortType?: string): string | undefined
resolveReplySortType(comment: Comment, requestedSortType?: string): string | undefined
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
getReplyPageSortType(comment: Comment, requestedSortType?: string): string | undefined
getSortTimeframeSeconds(sortType?: string): number | undefined // time window of top*/controversial* timeframe sorts
isFlatSortType(sortType?: string): boolean
createCrosspost requires a fully loaded comment with comment.cid and
comment.raw.comment. Publish the returned payload through the existing action hook:
const crosspost = createCrosspost(sourceComment);
const { publishComment } = usePublishComment({
communityAddress: targetCommunityAddress,
title: sourceComment.title,
crosspost,
});
await publishComment();
Render the author-signed embedded record immediately with useCrosspost. The referenced
community is only confirmed after its signed CommentUpdate has loaded, exposed as
isCommunityVerified:
const original = useCrosspost({ crosspost: post.crosspost });
return <CrosspostCard comment={original} verified={original.isCommunityVerified} />;