@bitsocial/bitsocial-react-hooks 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +1365 -0
- package/dist/hooks/accounts/accounts.d.ts +64 -0
- package/dist/hooks/accounts/accounts.d.ts.map +1 -0
- package/dist/hooks/accounts/accounts.js +706 -0
- package/dist/hooks/accounts/accounts.js.map +1 -0
- package/dist/hooks/accounts/index.d.ts +2 -0
- package/dist/hooks/accounts/index.d.ts.map +1 -0
- package/dist/hooks/accounts/index.js +2 -0
- package/dist/hooks/accounts/index.js.map +1 -0
- package/dist/hooks/accounts/utils.d.ts +6 -0
- package/dist/hooks/accounts/utils.d.ts.map +1 -0
- package/dist/hooks/accounts/utils.js +226 -0
- package/dist/hooks/accounts/utils.js.map +1 -0
- package/dist/hooks/actions/actions.d.ts +19 -0
- package/dist/hooks/actions/actions.d.ts.map +1 -0
- package/dist/hooks/actions/actions.js +552 -0
- package/dist/hooks/actions/actions.js.map +1 -0
- package/dist/hooks/actions/index.d.ts +2 -0
- package/dist/hooks/actions/index.d.ts.map +1 -0
- package/dist/hooks/actions/index.js +2 -0
- package/dist/hooks/actions/index.js.map +1 -0
- package/dist/hooks/authors/author-avatars.d.ts +28 -0
- package/dist/hooks/authors/author-avatars.d.ts.map +1 -0
- package/dist/hooks/authors/author-avatars.js +191 -0
- package/dist/hooks/authors/author-avatars.js.map +1 -0
- package/dist/hooks/authors/authors.d.ts +37 -0
- package/dist/hooks/authors/authors.d.ts.map +1 -0
- package/dist/hooks/authors/authors.js +509 -0
- package/dist/hooks/authors/authors.js.map +1 -0
- package/dist/hooks/authors/index.d.ts +2 -0
- package/dist/hooks/authors/index.d.ts.map +1 -0
- package/dist/hooks/authors/index.js +2 -0
- package/dist/hooks/authors/index.js.map +1 -0
- package/dist/hooks/authors/utils.d.ts +4 -0
- package/dist/hooks/authors/utils.d.ts.map +1 -0
- package/dist/hooks/authors/utils.js +21 -0
- package/dist/hooks/authors/utils.js.map +1 -0
- package/dist/hooks/comments.d.ts +17 -0
- package/dist/hooks/comments.d.ts.map +1 -0
- package/dist/hooks/comments.js +351 -0
- package/dist/hooks/comments.js.map +1 -0
- package/dist/hooks/communities.d.ts +31 -0
- package/dist/hooks/communities.d.ts.map +1 -0
- package/dist/hooks/communities.js +389 -0
- package/dist/hooks/communities.js.map +1 -0
- package/dist/hooks/feeds/feeds.d.ts +18 -0
- package/dist/hooks/feeds/feeds.d.ts.map +1 -0
- package/dist/hooks/feeds/feeds.js +315 -0
- package/dist/hooks/feeds/feeds.js.map +1 -0
- package/dist/hooks/feeds/index.d.ts +2 -0
- package/dist/hooks/feeds/index.d.ts.map +1 -0
- package/dist/hooks/feeds/index.js +2 -0
- package/dist/hooks/feeds/index.js.map +1 -0
- package/dist/hooks/pkc-rpc.d.ts +7 -0
- package/dist/hooks/pkc-rpc.d.ts.map +1 -0
- package/dist/hooks/pkc-rpc.js +88 -0
- package/dist/hooks/pkc-rpc.js.map +1 -0
- package/dist/hooks/replies.d.ts +5 -0
- package/dist/hooks/replies.d.ts.map +1 -0
- package/dist/hooks/replies.js +155 -0
- package/dist/hooks/replies.js.map +1 -0
- package/dist/hooks/states.d.ts +15 -0
- package/dist/hooks/states.d.ts.map +1 -0
- package/dist/hooks/states.js +213 -0
- package/dist/hooks/states.js.map +1 -0
- package/dist/hooks/utils/use-interval.d.ts +3 -0
- package/dist/hooks/utils/use-interval.d.ts.map +1 -0
- package/dist/hooks/utils/use-interval.js +36 -0
- package/dist/hooks/utils/use-interval.js.map +1 -0
- package/dist/hooks/utils/use-previous.d.ts +1 -0
- package/dist/hooks/utils/use-previous.js +10 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/chain/chain.d.ts +36 -0
- package/dist/lib/chain/chain.d.ts.map +1 -0
- package/dist/lib/chain/chain.js +195 -0
- package/dist/lib/chain/chain.js.map +1 -0
- package/dist/lib/chain/index.d.ts +4 -0
- package/dist/lib/chain/index.d.ts.map +1 -0
- package/dist/lib/chain/index.js +4 -0
- package/dist/lib/chain/index.js.map +1 -0
- package/dist/lib/community-address.d.ts +6 -0
- package/dist/lib/community-address.d.ts.map +1 -0
- package/dist/lib/community-address.js +26 -0
- package/dist/lib/community-address.js.map +1 -0
- package/dist/lib/community-ref.d.ts +23 -0
- package/dist/lib/community-ref.d.ts.map +1 -0
- package/dist/lib/community-ref.js +113 -0
- package/dist/lib/community-ref.js.map +1 -0
- package/dist/lib/debug-utils.d.ts +9 -0
- package/dist/lib/debug-utils.d.ts.map +1 -0
- package/dist/lib/debug-utils.js +21 -0
- package/dist/lib/debug-utils.js.map +1 -0
- package/dist/lib/feed-sort-type.d.ts +2 -0
- package/dist/lib/feed-sort-type.d.ts.map +1 -0
- package/dist/lib/feed-sort-type.js +22 -0
- package/dist/lib/feed-sort-type.js.map +1 -0
- package/dist/lib/localforage-lru/index.d.ts +3 -0
- package/dist/lib/localforage-lru/index.d.ts.map +1 -0
- package/dist/lib/localforage-lru/index.js +46 -0
- package/dist/lib/localforage-lru/index.js.map +1 -0
- package/dist/lib/localforage-lru/localforage-lru.d.ts +6 -0
- package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -0
- package/dist/lib/localforage-lru/localforage-lru.js +182 -0
- package/dist/lib/localforage-lru/localforage-lru.js.map +1 -0
- package/dist/lib/pkc-compat.d.ts +25 -0
- package/dist/lib/pkc-compat.d.ts.map +1 -0
- package/dist/lib/pkc-compat.js +131 -0
- package/dist/lib/pkc-compat.js.map +1 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.d.ts +3 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.d.ts.map +1 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.js +280 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.js.map +1 -0
- package/dist/lib/pkc-js/index.d.ts +11 -0
- package/dist/lib/pkc-js/index.d.ts.map +1 -0
- package/dist/lib/pkc-js/index.js +85 -0
- package/dist/lib/pkc-js/index.js.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.d.ts +3 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.js +1235 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts +137 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock.js +644 -0
- package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -0
- package/dist/lib/polyfill.d.ts +3 -0
- package/dist/lib/polyfill.d.ts.map +1 -0
- package/dist/lib/polyfill.js +14 -0
- package/dist/lib/polyfill.js.map +1 -0
- package/dist/lib/protocol-compat.d.ts +14 -0
- package/dist/lib/protocol-compat.d.ts.map +1 -0
- package/dist/lib/protocol-compat.js +67 -0
- package/dist/lib/protocol-compat.js.map +1 -0
- package/dist/lib/test-utils.d.ts +29 -0
- package/dist/lib/test-utils.d.ts.map +1 -0
- package/dist/lib/test-utils.js +184 -0
- package/dist/lib/test-utils.js.map +1 -0
- package/dist/lib/utils/comment-moderation.d.ts +4 -0
- package/dist/lib/utils/comment-moderation.d.ts.map +1 -0
- package/dist/lib/utils/comment-moderation.js +56 -0
- package/dist/lib/utils/comment-moderation.js.map +1 -0
- package/dist/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +4 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/utils.d.ts +23 -0
- package/dist/lib/utils/utils.d.ts.map +1 -0
- package/dist/lib/utils/utils.js +375 -0
- package/dist/lib/utils/utils.js.map +1 -0
- package/dist/lib/validator.d.ts +30 -0
- package/dist/lib/validator.d.ts.map +1 -0
- package/dist/lib/validator.js +307 -0
- package/dist/lib/validator.js.map +1 -0
- package/dist/stores/accounts/account-generator.d.ts +51 -0
- package/dist/stores/accounts/account-generator.d.ts.map +1 -0
- package/dist/stores/accounts/account-generator.js +160 -0
- package/dist/stores/accounts/account-generator.js.map +1 -0
- package/dist/stores/accounts/accounts-actions-internal.d.ts +8 -0
- package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-actions-internal.js +403 -0
- package/dist/stores/accounts/accounts-actions-internal.js.map +1 -0
- package/dist/stores/accounts/accounts-actions.d.ts +46 -0
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-actions.js +1341 -0
- package/dist/stores/accounts/accounts-actions.js.map +1 -0
- package/dist/stores/accounts/accounts-database.d.ts +34 -0
- package/dist/stores/accounts/accounts-database.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-database.js +685 -0
- package/dist/stores/accounts/accounts-database.js.map +1 -0
- package/dist/stores/accounts/accounts-store.d.ts +32 -0
- package/dist/stores/accounts/accounts-store.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-store.js +169 -0
- package/dist/stores/accounts/accounts-store.js.map +1 -0
- package/dist/stores/accounts/index.d.ts +4 -0
- package/dist/stores/accounts/index.d.ts.map +1 -0
- package/dist/stores/accounts/index.js +4 -0
- package/dist/stores/accounts/index.js.map +1 -0
- package/dist/stores/accounts/utils.d.ts +49 -0
- package/dist/stores/accounts/utils.d.ts.map +1 -0
- package/dist/stores/accounts/utils.js +419 -0
- package/dist/stores/accounts/utils.js.map +1 -0
- package/dist/stores/authors-comments/authors-comments-store.d.ts +37 -0
- package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -0
- package/dist/stores/authors-comments/authors-comments-store.js +338 -0
- package/dist/stores/authors-comments/authors-comments-store.js.map +1 -0
- package/dist/stores/authors-comments/index.d.ts +4 -0
- package/dist/stores/authors-comments/index.d.ts.map +1 -0
- package/dist/stores/authors-comments/index.js +4 -0
- package/dist/stores/authors-comments/index.js.map +1 -0
- package/dist/stores/authors-comments/utils.d.ts +14 -0
- package/dist/stores/authors-comments/utils.d.ts.map +1 -0
- package/dist/stores/authors-comments/utils.js +81 -0
- package/dist/stores/authors-comments/utils.js.map +1 -0
- package/dist/stores/comments/comments-store.d.ts +19 -0
- package/dist/stores/comments/comments-store.d.ts.map +1 -0
- package/dist/stores/comments/comments-store.js +385 -0
- package/dist/stores/comments/comments-store.js.map +1 -0
- package/dist/stores/comments/index.d.ts +4 -0
- package/dist/stores/comments/index.d.ts.map +1 -0
- package/dist/stores/comments/index.js +4 -0
- package/dist/stores/comments/index.js.map +1 -0
- package/dist/stores/communities/communities-store.d.ts +17 -0
- package/dist/stores/communities/communities-store.d.ts.map +1 -0
- package/dist/stores/communities/communities-store.js +304 -0
- package/dist/stores/communities/communities-store.js.map +1 -0
- package/dist/stores/communities/index.d.ts +4 -0
- package/dist/stores/communities/index.d.ts.map +1 -0
- package/dist/stores/communities/index.js +4 -0
- package/dist/stores/communities/index.js.map +1 -0
- package/dist/stores/communities-pages/communities-pages-store.d.ts +23 -0
- package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -0
- package/dist/stores/communities-pages/communities-pages-store.js +316 -0
- package/dist/stores/communities-pages/communities-pages-store.js.map +1 -0
- package/dist/stores/communities-pages/index.d.ts +4 -0
- package/dist/stores/communities-pages/index.d.ts.map +1 -0
- package/dist/stores/communities-pages/index.js +4 -0
- package/dist/stores/communities-pages/index.js.map +1 -0
- package/dist/stores/feeds/feed-sorter.d.ts +5 -0
- package/dist/stores/feeds/feed-sorter.d.ts.map +1 -0
- package/dist/stores/feeds/feed-sorter.js +135 -0
- package/dist/stores/feeds/feed-sorter.js.map +1 -0
- package/dist/stores/feeds/feeds-store.d.ts +25 -0
- package/dist/stores/feeds/feeds-store.d.ts.map +1 -0
- package/dist/stores/feeds/feeds-store.js +459 -0
- package/dist/stores/feeds/feeds-store.js.map +1 -0
- package/dist/stores/feeds/index.d.ts +4 -0
- package/dist/stores/feeds/index.d.ts.map +1 -0
- package/dist/stores/feeds/index.js +4 -0
- package/dist/stores/feeds/index.js.map +1 -0
- package/dist/stores/feeds/utils.d.ts +43 -0
- package/dist/stores/feeds/utils.d.ts.map +1 -0
- package/dist/stores/feeds/utils.js +736 -0
- package/dist/stores/feeds/utils.js.map +1 -0
- package/dist/stores/replies/index.d.ts +4 -0
- package/dist/stores/replies/index.d.ts.map +1 -0
- package/dist/stores/replies/index.js +4 -0
- package/dist/stores/replies/index.js.map +1 -0
- package/dist/stores/replies/replies-comments-store.d.ts +8 -0
- package/dist/stores/replies/replies-comments-store.d.ts.map +1 -0
- package/dist/stores/replies/replies-comments-store.js +23 -0
- package/dist/stores/replies/replies-comments-store.js.map +1 -0
- package/dist/stores/replies/replies-store.d.ts +29 -0
- package/dist/stores/replies/replies-store.d.ts.map +1 -0
- package/dist/stores/replies/replies-store.js +413 -0
- package/dist/stores/replies/replies-store.js.map +1 -0
- package/dist/stores/replies/utils.d.ts +25 -0
- package/dist/stores/replies/utils.d.ts.map +1 -0
- package/dist/stores/replies/utils.js +549 -0
- package/dist/stores/replies/utils.js.map +1 -0
- package/dist/stores/replies-pages/index.d.ts +4 -0
- package/dist/stores/replies-pages/index.d.ts.map +1 -0
- package/dist/stores/replies-pages/index.js +4 -0
- package/dist/stores/replies-pages/index.js.map +1 -0
- package/dist/stores/replies-pages/replies-pages-store.d.ts +20 -0
- package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -0
- package/dist/stores/replies-pages/replies-pages-store.js +270 -0
- package/dist/stores/replies-pages/replies-pages-store.js.map +1 -0
- package/dist/stores/replies-pages/utils.d.ts +3 -0
- package/dist/stores/replies-pages/utils.d.ts.map +1 -0
- package/dist/stores/replies-pages/utils.js +43 -0
- package/dist/stores/replies-pages/utils.js.map +1 -0
- package/dist/types.d.ts +638 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +160 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { useEffect, useState, useMemo } from "react";
|
|
11
|
+
import { useAccount } from "./accounts/index.js";
|
|
12
|
+
import validator from "../lib/validator.js";
|
|
13
|
+
import Logger from "@pkcprotocol/pkc-logger";
|
|
14
|
+
const log = Logger("bitsocial-react-hooks:replies:hooks");
|
|
15
|
+
import assert from "assert";
|
|
16
|
+
import { addCommentModerationToComments } from "../lib/utils/comment-moderation.js";
|
|
17
|
+
import useRepliesStore, { feedOptionsToFeedName, getRepliesFirstPageSkipValidation, } from "../stores/replies/index.js";
|
|
18
|
+
/** Pure helper to append an error to the errors array; used for deterministic coverage of reset/loadMore catch paths. */
|
|
19
|
+
export function appendErrorToErrors(prevErrors, e) {
|
|
20
|
+
return [...prevErrors, e];
|
|
21
|
+
}
|
|
22
|
+
export function useReplies(options) {
|
|
23
|
+
var _a;
|
|
24
|
+
assert(!options || typeof options === "object", `useReplies options argument '${options}' not an object`);
|
|
25
|
+
const opts = options !== null && options !== void 0 ? options : {};
|
|
26
|
+
let { comment, sortType, accountName, onlyIfCached, flat, flatDepth, accountComments, repliesPerPage, filter, validateOptimistically, streamPage, } = opts;
|
|
27
|
+
sortType = sortType || "best";
|
|
28
|
+
flatDepth = typeof flatDepth === "number" ? flatDepth : 0;
|
|
29
|
+
validateOptimistically = validateOptimistically !== false;
|
|
30
|
+
const invalidFlatDepth = flat && typeof (comment === null || comment === void 0 ? void 0 : comment.depth) === "number" && flatDepth !== comment.depth;
|
|
31
|
+
validator.validateUseRepliesArguments(comment, sortType, accountName, onlyIfCached, flat, accountComments, repliesPerPage, filter);
|
|
32
|
+
const [errors, setErrors] = useState([]);
|
|
33
|
+
// add replies to store
|
|
34
|
+
const account = useAccount({ accountName });
|
|
35
|
+
const feedOptions = {
|
|
36
|
+
commentCid: comment === null || comment === void 0 ? void 0 : comment.cid,
|
|
37
|
+
commentDepth: comment === null || comment === void 0 ? void 0 : comment.depth,
|
|
38
|
+
postCid: comment === null || comment === void 0 ? void 0 : comment.postCid,
|
|
39
|
+
sortType,
|
|
40
|
+
accountId: account === null || account === void 0 ? void 0 : account.id,
|
|
41
|
+
onlyIfCached,
|
|
42
|
+
repliesPerPage,
|
|
43
|
+
flat,
|
|
44
|
+
accountComments,
|
|
45
|
+
filter,
|
|
46
|
+
streamPage,
|
|
47
|
+
};
|
|
48
|
+
const repliesFeedName = feedOptionsToFeedName(feedOptions);
|
|
49
|
+
const addFeedToStoreOrUpdateComment = useRepliesStore((state) => state.addFeedToStoreOrUpdateComment);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!(comment === null || comment === void 0 ? void 0 : comment.cid) || !account || invalidFlatDepth) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
addFeedToStoreOrUpdateComment(comment, feedOptions).catch((error) => log.error("useReplies addFeedToStoreOrUpdateComment error", {
|
|
55
|
+
repliesFeedName,
|
|
56
|
+
comment,
|
|
57
|
+
feedOptions,
|
|
58
|
+
error,
|
|
59
|
+
}));
|
|
60
|
+
}, [repliesFeedName, comment]);
|
|
61
|
+
let replies = useRepliesStore((state) => state.loadedFeeds[repliesFeedName || ""]);
|
|
62
|
+
let bufferedReplies = useRepliesStore((state) => state.bufferedFeeds[repliesFeedName || ""]);
|
|
63
|
+
let updatedReplies = useRepliesStore((state) => state.updatedFeeds[repliesFeedName || ""]);
|
|
64
|
+
let hasMore = useRepliesStore((state) => state.feedsHaveMore[repliesFeedName || ""]);
|
|
65
|
+
hasMore = comment
|
|
66
|
+
? repliesFeedName && typeof hasMore === "boolean"
|
|
67
|
+
? hasMore
|
|
68
|
+
: !onlyIfCached
|
|
69
|
+
: false;
|
|
70
|
+
const incrementFeedPageNumber = useRepliesStore((state) => state.incrementFeedPageNumber);
|
|
71
|
+
let loadMore = () => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
try {
|
|
73
|
+
if (!(comment === null || comment === void 0 ? void 0 : comment.cid) || !account) {
|
|
74
|
+
throw Error("useReplies cannot load more replies not initalized yet");
|
|
75
|
+
}
|
|
76
|
+
incrementFeedPageNumber(repliesFeedName);
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
yield new Promise((r) => setTimeout(r, 50));
|
|
80
|
+
setErrors(appendErrorToErrors(errors, e));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const resetFeed = useRepliesStore((state) => state.resetFeed);
|
|
84
|
+
let reset = () => __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
try {
|
|
86
|
+
if (!(comment === null || comment === void 0 ? void 0 : comment.cid) || !account) {
|
|
87
|
+
throw Error("useReplies cannot reset replies not initalized yet");
|
|
88
|
+
}
|
|
89
|
+
resetFeed(repliesFeedName);
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
yield new Promise((r) => setTimeout(r, 50));
|
|
93
|
+
setErrors(appendErrorToErrors(errors, e));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
// optimistically avoid the initial validation delay by using skipped validation until validated feed is loaded
|
|
97
|
+
const skipValidation = useMemo(() => {
|
|
98
|
+
if (validateOptimistically && !replies && (comment === null || comment === void 0 ? void 0 : comment.cid) && (account === null || account === void 0 ? void 0 : account.id)) {
|
|
99
|
+
return getRepliesFirstPageSkipValidation(comment, feedOptions);
|
|
100
|
+
}
|
|
101
|
+
}, [validateOptimistically, replies, comment === null || comment === void 0 ? void 0 : comment.cid, account === null || account === void 0 ? void 0 : account.id, comment, repliesFeedName]);
|
|
102
|
+
if (validateOptimistically && !replies && ((_a = skipValidation === null || skipValidation === void 0 ? void 0 : skipValidation.replies) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
103
|
+
replies = skipValidation.replies;
|
|
104
|
+
hasMore = skipValidation.hasMore;
|
|
105
|
+
}
|
|
106
|
+
// don't display nested replies when flat
|
|
107
|
+
// to start flat replies at a depth other than 0, e.g. a twitter reply thread, change flatDepth
|
|
108
|
+
if (invalidFlatDepth) {
|
|
109
|
+
replies = emptyArray;
|
|
110
|
+
bufferedReplies = emptyArray;
|
|
111
|
+
updatedReplies = emptyArray;
|
|
112
|
+
hasMore = false;
|
|
113
|
+
loadMore = emptyFunction;
|
|
114
|
+
reset = emptyFunction;
|
|
115
|
+
}
|
|
116
|
+
if (account && (comment === null || comment === void 0 ? void 0 : comment.cid)) {
|
|
117
|
+
log("useReplies", {
|
|
118
|
+
repliesLength: (replies === null || replies === void 0 ? void 0 : replies.length) || 0,
|
|
119
|
+
hasMore,
|
|
120
|
+
comment,
|
|
121
|
+
sortType,
|
|
122
|
+
onlyIfCached,
|
|
123
|
+
flat,
|
|
124
|
+
flatDepth,
|
|
125
|
+
repliesStoreOptions: useRepliesStore.getState().feedsOptions,
|
|
126
|
+
repliesStore: useRepliesStore.getState(),
|
|
127
|
+
invalidFlatDepth,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const state = !hasMore ? "succeeded" : "fetching";
|
|
131
|
+
const normalizedReplies = useMemo(() => addCommentModerationToComments(replies), [replies]);
|
|
132
|
+
const normalizedBufferedReplies = useMemo(() => addCommentModerationToComments(bufferedReplies), [bufferedReplies]);
|
|
133
|
+
const normalizedUpdatedReplies = useMemo(() => addCommentModerationToComments(updatedReplies), [updatedReplies]);
|
|
134
|
+
return useMemo(() => ({
|
|
135
|
+
replies: normalizedReplies,
|
|
136
|
+
bufferedReplies: normalizedBufferedReplies,
|
|
137
|
+
updatedReplies: normalizedUpdatedReplies,
|
|
138
|
+
hasMore,
|
|
139
|
+
loadMore,
|
|
140
|
+
reset,
|
|
141
|
+
state,
|
|
142
|
+
error: errors[errors.length - 1],
|
|
143
|
+
errors,
|
|
144
|
+
}), [
|
|
145
|
+
normalizedReplies,
|
|
146
|
+
normalizedBufferedReplies,
|
|
147
|
+
normalizedUpdatedReplies,
|
|
148
|
+
repliesFeedName,
|
|
149
|
+
hasMore,
|
|
150
|
+
errors,
|
|
151
|
+
]);
|
|
152
|
+
}
|
|
153
|
+
const emptyArray = [];
|
|
154
|
+
const emptyFunction = () => __awaiter(void 0, void 0, void 0, function* () { });
|
|
155
|
+
//# sourceMappingURL=replies.js.map
|
|
@@ -0,0 +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,QAAQ,CAAC;AAE5B,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,eAAe,EAAE,EAEtB,qBAAqB,EACrB,iCAAiC,GAClC,MAAM,mBAAmB,CAAC;AAE3B,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,EACvC,g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AQ;YACR,YAAY;YACZ,IAAI;YACJ,SAAS;YACT,mBAAmB,EAAE,eAAe,CAAC,QAAQ,EAAE,CAAC,YAAY;YAC5D,YAAY,EAAE,eAAe,CAAC,QAAQ,EAAE;YACxC,gBAAgB;SACjB,CAAC,CAAC;IACL,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC;IAClD,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,8BAA8B,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5F,MAAM,yBAAyB,GAAG,OAAO,CACvC,GAAG,EAAE,CAAC,8BAA8B,CAAC,eAAe,CAAC,EACrD,CAAC,eAAe,CAAC,CAClB,CAAC;IACF,MAAM,wBAAwB,GAAG,OAAO,CACtC,GAAG,EAAE,CAAC,8BAA8B,CAAC,cAAc,CAAC,EACpD,CAAC,cAAc,CAAC,CACjB,CAAC;IAEF,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,OAAO,EAAE,iBAAiB;QAC1B,eAAe,EAAE,yBAAyB;QAC1C,cAAc,EAAE,wBAAwB;QACxC,OAAO;QACP,QAAQ;QACR,KAAK;QACL,KAAK;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,MAAM;KACP,CAAC,EACF;QACE,iBAAiB;QACjB,yBAAyB;QACzB,wBAAwB;QACxB,eAAe;QACf,OAAO;QACP,MAAM;KACP,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAQ,EAAE,CAAC;AAC3B,MAAM,aAAa,GAAG,GAAS,EAAE,kDAAE,CAAC,CAAA,CAAC","sourcesContent":["import { useEffect, useState, useMemo } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:replies:hooks\");\nimport assert from \"assert\";\nimport { UseRepliesOptions, UseRepliesResult } from \"../types\";\nimport { addCommentModerationToComments } from \"../lib/utils/comment-moderation\";\nimport useRepliesStore, {\n RepliesState,\n feedOptionsToFeedName,\n getRepliesFirstPageSkipValidation,\n} from \"../stores/replies\";\n\n/** Pure helper to append an error to the errors array; used for deterministic coverage of reset/loadMore catch paths. */\nexport function appendErrorToErrors(prevErrors: Error[], e: Error): Error[] {\n return [...prevErrors, e];\n}\n\nexport function useReplies(options?: UseRepliesOptions): UseRepliesResult {\n assert(\n !options || typeof options === \"object\",\n `useReplies options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n let {\n comment,\n sortType,\n accountName,\n onlyIfCached,\n flat,\n flatDepth,\n accountComments,\n repliesPerPage,\n filter,\n validateOptimistically,\n streamPage,\n } = opts;\n sortType = sortType || \"best\";\n flatDepth = typeof flatDepth === \"number\" ? flatDepth : 0;\n validateOptimistically = validateOptimistically !== false;\n const invalidFlatDepth =\n flat && typeof comment?.depth === \"number\" && flatDepth !== comment.depth;\n validator.validateUseRepliesArguments(\n comment,\n sortType,\n accountName,\n onlyIfCached,\n flat,\n accountComments,\n repliesPerPage,\n filter,\n );\n\n const [errors, setErrors] = useState<Error[]>([]);\n\n // add replies to store\n const account = useAccount({ accountName });\n const 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(() => addCommentModerationToComments(replies), [replies]);\n const normalizedBufferedReplies = useMemo(\n () => addCommentModerationToComments(bufferedReplies),\n [bufferedReplies],\n );\n const normalizedUpdatedReplies = useMemo(\n () => addCommentModerationToComments(updatedReplies),\n [updatedReplies],\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"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { UseClientsStatesOptions, UseClientsStatesResult, UseCommunitiesStatesOptions, UseCommunitiesStatesResult } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @param comment - The comment to get the states from
|
|
4
|
+
* @param community - The community to get the states from
|
|
5
|
+
* @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
|
|
6
|
+
* the active account.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useClientsStates(options?: UseClientsStatesOptions): UseClientsStatesResult;
|
|
9
|
+
/**
|
|
10
|
+
* @param communities - The communities to get the states from
|
|
11
|
+
* @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
|
|
12
|
+
* the active account.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useCommunitiesStates(options?: UseCommunitiesStatesOptions): UseCommunitiesStatesResult;
|
|
15
|
+
//# sourceMappingURL=states.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"states.d.ts","sourceRoot":"","sources":["../../src/hooks/states.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,0BAA0B,EAC3B,MAAM,UAAU,CAAC;AAQlB;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,sBAAsB,CA+G1F;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,CAAC,EAAE,2BAA2B,GACpC,0BAA0B,CAuH5B"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import Logger from "@pkcprotocol/pkc-logger";
|
|
3
|
+
const log = Logger("bitsocial-react-hooks:states:hooks");
|
|
4
|
+
import assert from "assert";
|
|
5
|
+
import validator from "../lib/validator.js";
|
|
6
|
+
import { getPageRpcClients } from "../lib/pkc-compat.js";
|
|
7
|
+
import { useCommunities } from "./communities.js";
|
|
8
|
+
import { communityPostsCacheExpired } from "../lib/utils/index.js";
|
|
9
|
+
// TODO: implement getting peers
|
|
10
|
+
const peers = {};
|
|
11
|
+
/**
|
|
12
|
+
* @param comment - The comment to get the states from
|
|
13
|
+
* @param community - The community to get the states from
|
|
14
|
+
* @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
|
|
15
|
+
* the active account.
|
|
16
|
+
*/
|
|
17
|
+
export function useClientsStates(options) {
|
|
18
|
+
assert(options == null || typeof options === "object", `useClientsStates options argument '${options}' not an object`);
|
|
19
|
+
const { comment, community } = options !== null && options !== void 0 ? options : {};
|
|
20
|
+
assert(comment == null || typeof comment === "object", `useClientsStates options.comment argument '${comment}' not an object`);
|
|
21
|
+
assert(community == null || typeof community === "object", `useClientsStates options.community argument '${community}' not an object`);
|
|
22
|
+
assert(!(comment && community), `useClientsStates options.comment and options.community arguments cannot be defined at the same time`);
|
|
23
|
+
const commentOrCommunity = comment || community;
|
|
24
|
+
const states = useMemo(() => {
|
|
25
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
26
|
+
const states = {};
|
|
27
|
+
// if comment is newer than 5 minutes, don't show updating state so user knows it finished
|
|
28
|
+
if ((commentOrCommunity === null || commentOrCommunity === void 0 ? void 0 : commentOrCommunity.cid) && commentOrCommunity.timestamp + 5 * 60 > Date.now() / 1000) {
|
|
29
|
+
return states;
|
|
30
|
+
}
|
|
31
|
+
if (!(commentOrCommunity === null || commentOrCommunity === void 0 ? void 0 : commentOrCommunity.clients)) {
|
|
32
|
+
return states;
|
|
33
|
+
}
|
|
34
|
+
const clients = commentOrCommunity === null || commentOrCommunity === void 0 ? void 0 : commentOrCommunity.clients;
|
|
35
|
+
const addState = (state, clientUrl) => {
|
|
36
|
+
if (!state || state === "stopped") {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!states[state]) {
|
|
40
|
+
states[state] = [];
|
|
41
|
+
}
|
|
42
|
+
states[state].push(clientUrl);
|
|
43
|
+
};
|
|
44
|
+
// dont show state if the data is already fetched
|
|
45
|
+
if (!(commentOrCommunity === null || commentOrCommunity === void 0 ? void 0 : commentOrCommunity.updatedAt) || communityPostsCacheExpired(commentOrCommunity)) {
|
|
46
|
+
for (const clientUrl in clients === null || clients === void 0 ? void 0 : clients.ipfsGateways) {
|
|
47
|
+
addState((_a = clients.ipfsGateways[clientUrl]) === null || _a === void 0 ? void 0 : _a.state, clientUrl);
|
|
48
|
+
}
|
|
49
|
+
for (const clientUrl in clients === null || clients === void 0 ? void 0 : clients.kuboRpcClients) {
|
|
50
|
+
addState((_b = clients.kuboRpcClients[clientUrl]) === null || _b === void 0 ? void 0 : _b.state, clientUrl);
|
|
51
|
+
}
|
|
52
|
+
for (const clientUrl in clients === null || clients === void 0 ? void 0 : clients.pubsubKuboRpcClients) {
|
|
53
|
+
addState((_c = clients.pubsubKuboRpcClients[clientUrl]) === null || _c === void 0 ? void 0 : _c.state, clientUrl);
|
|
54
|
+
}
|
|
55
|
+
const rpcClients = getPageRpcClients(clients);
|
|
56
|
+
for (const clientUrl in rpcClients) {
|
|
57
|
+
addState((_d = rpcClients[clientUrl]) === null || _d === void 0 ? void 0 : _d.state, clientUrl);
|
|
58
|
+
}
|
|
59
|
+
for (const clientUrl in clients === null || clients === void 0 ? void 0 : clients.libp2pJsClients) {
|
|
60
|
+
addState((_e = clients.libp2pJsClients[clientUrl]) === null || _e === void 0 ? void 0 : _e.state, clientUrl);
|
|
61
|
+
}
|
|
62
|
+
for (const chainTicker in clients === null || clients === void 0 ? void 0 : clients.chainProviders) {
|
|
63
|
+
for (const clientUrl in clients.chainProviders[chainTicker]) {
|
|
64
|
+
addState((_f = clients.chainProviders[chainTicker][clientUrl]) === null || _f === void 0 ? void 0 : _f.state, clientUrl);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (const resolverKey in clients === null || clients === void 0 ? void 0 : clients.nameResolvers) {
|
|
68
|
+
addState((_g = clients.nameResolvers[resolverKey]) === null || _g === void 0 ? void 0 : _g.state, resolverKey);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// find community pages and comment replies pages states
|
|
72
|
+
const pages = (commentOrCommunity === null || commentOrCommunity === void 0 ? void 0 : commentOrCommunity.posts) || (commentOrCommunity === null || commentOrCommunity === void 0 ? void 0 : commentOrCommunity.replies);
|
|
73
|
+
if (pages) {
|
|
74
|
+
for (const clientType in pages.clients) {
|
|
75
|
+
for (const sortType in pages.clients[clientType]) {
|
|
76
|
+
for (const clientUrl in pages.clients[clientType][sortType]) {
|
|
77
|
+
let state = pages.clients[clientType][sortType][clientUrl].state;
|
|
78
|
+
if (state === "stopped") {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
state += `-page-${sortType}`;
|
|
82
|
+
if (!states[state]) {
|
|
83
|
+
states[state] = [];
|
|
84
|
+
}
|
|
85
|
+
states[state].push(clientUrl);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
log("useClientsStates", {
|
|
91
|
+
communityAddress: commentOrCommunity === null || commentOrCommunity === void 0 ? void 0 : commentOrCommunity.address,
|
|
92
|
+
commentCid: commentOrCommunity === null || commentOrCommunity === void 0 ? void 0 : commentOrCommunity.cid,
|
|
93
|
+
states,
|
|
94
|
+
commentOrCommunity,
|
|
95
|
+
});
|
|
96
|
+
return states;
|
|
97
|
+
}, [commentOrCommunity]);
|
|
98
|
+
return useMemo(() => ({
|
|
99
|
+
states,
|
|
100
|
+
peers,
|
|
101
|
+
state: "initializing",
|
|
102
|
+
error: undefined,
|
|
103
|
+
errors: [],
|
|
104
|
+
}), [states, peers]);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @param communities - The communities to get the states from
|
|
108
|
+
* @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
|
|
109
|
+
* the active account.
|
|
110
|
+
*/
|
|
111
|
+
export function useCommunitiesStates(options) {
|
|
112
|
+
assert(options == null || typeof options === "object", `useCommunitiesStates options argument '${options}' not an object`);
|
|
113
|
+
const opts = options !== null && options !== void 0 ? options : {};
|
|
114
|
+
const { communities: communitiesInput } = opts;
|
|
115
|
+
validator.validateUseCommunitiesStatesArguments({
|
|
116
|
+
communities: communitiesInput,
|
|
117
|
+
communityRefs: opts.communityRefs,
|
|
118
|
+
communityAddresses: opts.communityAddresses,
|
|
119
|
+
});
|
|
120
|
+
const { communities } = useCommunities({ communities: communitiesInput });
|
|
121
|
+
const states = useMemo(() => {
|
|
122
|
+
var _a;
|
|
123
|
+
const states = {};
|
|
124
|
+
for (const community of communities) {
|
|
125
|
+
if (!(community === null || community === void 0 ? void 0 : community.updatingState)) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
// dont show community state if data is already fetched
|
|
129
|
+
if ((!community.updatedAt || communityPostsCacheExpired(community)) &&
|
|
130
|
+
(community === null || community === void 0 ? void 0 : community.updatingState) !== "stopped" &&
|
|
131
|
+
(community === null || community === void 0 ? void 0 : community.updatingState) !== "succeeded") {
|
|
132
|
+
if (!states[community.updatingState]) {
|
|
133
|
+
states[community.updatingState] = {
|
|
134
|
+
communityAddresses: new Set(),
|
|
135
|
+
clientUrls: new Set(),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
states[community.updatingState].communityAddresses.add(community.address);
|
|
139
|
+
// find client urls
|
|
140
|
+
for (const clientType in community.clients) {
|
|
141
|
+
if (clientType === "chainProviders") {
|
|
142
|
+
for (const chainTicker in community.clients.chainProviders) {
|
|
143
|
+
for (const clientUrl in community.clients.chainProviders[chainTicker]) {
|
|
144
|
+
const state = community.clients.chainProviders[chainTicker][clientUrl].state;
|
|
145
|
+
// TODO: client states should always be the same as community.updatingState
|
|
146
|
+
// but possibly because of a pkc-js bug they are sometimes not
|
|
147
|
+
if (state !== "stopped" && state === community.updatingState) {
|
|
148
|
+
states[community.updatingState].clientUrls.add(clientUrl);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
for (const clientUrl in community.clients[clientType]) {
|
|
155
|
+
const state = community.clients[clientType][clientUrl].state;
|
|
156
|
+
// TODO: client states should always be the same as community.updatingState
|
|
157
|
+
// but possibly because of a pkc-js bug they are sometimes not
|
|
158
|
+
if (state !== "stopped" && state === community.updatingState) {
|
|
159
|
+
states[community.updatingState].clientUrls.add(clientUrl);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// find community pages states and client urls
|
|
166
|
+
const pagesClientsUrls = {};
|
|
167
|
+
for (const clientType in (_a = community === null || community === void 0 ? void 0 : community.posts) === null || _a === void 0 ? void 0 : _a.clients) {
|
|
168
|
+
for (const sortType in community.posts.clients[clientType]) {
|
|
169
|
+
for (const clientUrl in community.posts.clients[clientType][sortType]) {
|
|
170
|
+
let state = community.posts.clients[clientType][sortType][clientUrl].state;
|
|
171
|
+
if (state !== "stopped") {
|
|
172
|
+
state += `-page-${sortType}`;
|
|
173
|
+
if (!pagesClientsUrls[state]) {
|
|
174
|
+
pagesClientsUrls[state] = [];
|
|
175
|
+
}
|
|
176
|
+
pagesClientsUrls[state].push(clientUrl);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// add communityAddresses and clientUrls
|
|
182
|
+
for (const pagesState in pagesClientsUrls) {
|
|
183
|
+
if (!states[pagesState]) {
|
|
184
|
+
states[pagesState] = { communityAddresses: new Set(), clientUrls: new Set() };
|
|
185
|
+
}
|
|
186
|
+
states[pagesState].communityAddresses.add(community.address);
|
|
187
|
+
pagesClientsUrls[pagesState].forEach((clientUrl) => states[pagesState].clientUrls.add(clientUrl));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// convert sets to arrays
|
|
191
|
+
const _states = {};
|
|
192
|
+
for (const state in states) {
|
|
193
|
+
_states[state] = {
|
|
194
|
+
communityAddresses: [...states[state].communityAddresses],
|
|
195
|
+
clientUrls: [...states[state].clientUrls],
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
log("useCommunitiesStates", {
|
|
199
|
+
requestedCommunities: communitiesInput,
|
|
200
|
+
states: _states,
|
|
201
|
+
communities,
|
|
202
|
+
});
|
|
203
|
+
return _states;
|
|
204
|
+
}, [communities]);
|
|
205
|
+
return useMemo(() => ({
|
|
206
|
+
states,
|
|
207
|
+
peers,
|
|
208
|
+
state: "initializing",
|
|
209
|
+
error: undefined,
|
|
210
|
+
errors: [],
|
|
211
|
+
}), [states, peers]);
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=states.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"states.js","sourceRoot":"","sources":["../../src/hooks/states.ts"],"names":[],"mappings":"AAAA,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7D,gBAAgB,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,EAAE,CACzD,MAAM,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAC7C,CAAC;YACJ,CAAC;QACH,CAAC;QAED,yBAAyB;QACzB,MAAM,OAAO,GAAgF,EAAE,CAAC;QAChG,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,GAAG;gBACf,kBAAkB,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,kBAAkB,CAAC;gBACzD,UAAU,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC;aAC1C,CAAC;QACJ,CAAC;QAED,GAAG,CAAC,sBAAsB,EAAE;YAC1B,oBAAoB,EAAE,gBAAgB;YACtC,MAAM,EAAE,OAAO;YACf,WAAW;SACZ,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAElB,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,MAAM;QACN,KAAK;QACL,KAAK,EAAE,cAAc;QACrB,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,EAAE;KACX,CAAC,EACF,CAAC,MAAM,EAAE,KAAK,CAAC,CAChB,CAAC;AACJ,CAAC","sourcesContent":["import { useMemo } from \"react\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:states:hooks\");\nimport assert from \"assert\";\nimport validator from \"../lib/validator\";\nimport {\n UseClientsStatesOptions,\n UseClientsStatesResult,\n UseCommunitiesStatesOptions,\n UseCommunitiesStatesResult,\n} from \"../types\";\nimport { getPageRpcClients } from \"../lib/pkc-compat\";\nimport { useCommunities } from \"./communities\";\nimport { communityPostsCacheExpired } from \"../lib/utils\";\n\n// TODO: implement getting peers\nconst peers = {};\n\n/**\n * @param comment - The comment to get the states from\n * @param community - The community to get the states from\n * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use\n * the active account.\n */\nexport function useClientsStates(options?: UseClientsStatesOptions): UseClientsStatesResult {\n assert(\n options == null || typeof options === \"object\",\n `useClientsStates options argument '${options}' not an object`,\n );\n const { comment, community } = options ?? {};\n assert(\n comment == null || typeof comment === \"object\",\n `useClientsStates options.comment argument '${comment}' not an object`,\n );\n assert(\n community == null || typeof community === \"object\",\n `useClientsStates options.community argument '${community}' not an object`,\n );\n assert(\n !(comment && community),\n `useClientsStates options.comment and options.community arguments cannot be defined at the same time`,\n );\n const commentOrCommunity = comment || community;\n\n const states = useMemo(() => {\n const states: { [state: string]: string[] } = {};\n\n // if comment is newer than 5 minutes, don't show updating state so user knows it finished\n if (commentOrCommunity?.cid && commentOrCommunity.timestamp + 5 * 60 > Date.now() / 1000) {\n return states;\n }\n\n if (!commentOrCommunity?.clients) {\n return states;\n }\n const clients = commentOrCommunity?.clients;\n\n const addState = (state: string | undefined, clientUrl: string) => {\n if (!state || state === \"stopped\") {\n return;\n }\n if (!states[state]) {\n states[state] = [];\n }\n states[state].push(clientUrl);\n };\n\n // dont show state if the data is already fetched\n if (!commentOrCommunity?.updatedAt || communityPostsCacheExpired(commentOrCommunity)) {\n for (const clientUrl in clients?.ipfsGateways) {\n addState(clients.ipfsGateways[clientUrl]?.state, clientUrl);\n }\n for (const clientUrl in clients?.kuboRpcClients) {\n addState(clients.kuboRpcClients[clientUrl]?.state, clientUrl);\n }\n for (const clientUrl in clients?.pubsubKuboRpcClients) {\n addState(clients.pubsubKuboRpcClients[clientUrl]?.state, clientUrl);\n }\n const rpcClients = getPageRpcClients(clients);\n for (const clientUrl in rpcClients) {\n addState(rpcClients[clientUrl]?.state, clientUrl);\n }\n for (const clientUrl in clients?.libp2pJsClients) {\n addState(clients.libp2pJsClients[clientUrl]?.state, clientUrl);\n }\n for (const chainTicker in clients?.chainProviders) {\n for (const clientUrl in clients.chainProviders[chainTicker]) {\n addState(clients.chainProviders[chainTicker][clientUrl]?.state, clientUrl);\n }\n }\n for (const resolverKey in clients?.nameResolvers) {\n addState(clients.nameResolvers[resolverKey]?.state, resolverKey);\n }\n }\n\n // find community pages and comment replies pages states\n const pages = commentOrCommunity?.posts || commentOrCommunity?.replies;\n if (pages) {\n for (const clientType in pages.clients) {\n for (const sortType in pages.clients[clientType]) {\n for (const clientUrl in pages.clients[clientType][sortType]) {\n let state = pages.clients[clientType][sortType][clientUrl].state;\n if (state === \"stopped\") {\n continue;\n }\n state += `-page-${sortType}`;\n if (!states[state]) {\n states[state] = [];\n }\n states[state].push(clientUrl);\n }\n }\n }\n }\n\n log(\"useClientsStates\", {\n communityAddress: commentOrCommunity?.address,\n commentCid: commentOrCommunity?.cid,\n states,\n commentOrCommunity,\n });\n\n return states;\n }, [commentOrCommunity]);\n\n return useMemo(\n () => ({\n states,\n peers,\n state: \"initializing\",\n error: undefined,\n errors: [],\n }),\n [states, peers],\n );\n}\n\n/**\n * @param communities - The communities to get the states from\n * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunitiesStates(\n options?: UseCommunitiesStatesOptions,\n): UseCommunitiesStatesResult {\n assert(\n options == null || typeof options === \"object\",\n `useCommunitiesStates options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { communities: communitiesInput } = opts;\n validator.validateUseCommunitiesStatesArguments({\n communities: communitiesInput,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n });\n const { communities } = useCommunities({ communities: communitiesInput });\n\n const states = useMemo(() => {\n const states: {\n [state: string]: { communityAddresses: Set<string>; clientUrls: Set<string> };\n } = {};\n for (const community of communities) {\n if (!community?.updatingState) {\n continue;\n }\n\n // dont show community state if data is already fetched\n if (\n (!community.updatedAt || communityPostsCacheExpired(community)) &&\n community?.updatingState !== \"stopped\" &&\n community?.updatingState !== \"succeeded\"\n ) {\n if (!states[community.updatingState]) {\n states[community.updatingState] = {\n communityAddresses: new Set(),\n clientUrls: new Set(),\n };\n }\n states[community.updatingState].communityAddresses.add(community.address);\n\n // find client urls\n for (const clientType in community.clients) {\n if (clientType === \"chainProviders\") {\n for (const chainTicker in community.clients.chainProviders) {\n for (const clientUrl in community.clients.chainProviders[chainTicker]) {\n const state = community.clients.chainProviders[chainTicker][clientUrl].state;\n // TODO: client states should always be the same as community.updatingState\n // but possibly because of a pkc-js bug they are sometimes not\n if (state !== \"stopped\" && state === community.updatingState) {\n states[community.updatingState].clientUrls.add(clientUrl);\n }\n }\n }\n } else {\n for (const clientUrl in community.clients[clientType]) {\n const state = community.clients[clientType][clientUrl].state;\n // TODO: client states should always be the same as community.updatingState\n // but possibly because of a pkc-js bug they are sometimes not\n if (state !== \"stopped\" && state === community.updatingState) {\n states[community.updatingState].clientUrls.add(clientUrl);\n }\n }\n }\n }\n }\n\n // find community pages states and client urls\n const pagesClientsUrls: { [state: string]: string[] } = {};\n for (const clientType in community?.posts?.clients) {\n for (const sortType in community.posts.clients[clientType]) {\n for (const clientUrl in community.posts.clients[clientType][sortType]) {\n let state = community.posts.clients[clientType][sortType][clientUrl].state;\n if (state !== \"stopped\") {\n state += `-page-${sortType}`;\n if (!pagesClientsUrls[state]) {\n pagesClientsUrls[state] = [];\n }\n pagesClientsUrls[state].push(clientUrl);\n }\n }\n }\n }\n // add communityAddresses and clientUrls\n for (const pagesState in pagesClientsUrls) {\n if (!states[pagesState]) {\n states[pagesState] = { communityAddresses: new Set(), clientUrls: new Set() };\n }\n states[pagesState].communityAddresses.add(community.address);\n pagesClientsUrls[pagesState].forEach((clientUrl: string) =>\n states[pagesState].clientUrls.add(clientUrl),\n );\n }\n }\n\n // convert sets to arrays\n const _states: { [state: string]: { communityAddresses: string[]; clientUrls: string[] } } = {};\n for (const state in states) {\n _states[state] = {\n communityAddresses: [...states[state].communityAddresses],\n clientUrls: [...states[state].clientUrls],\n };\n }\n\n log(\"useCommunitiesStates\", {\n requestedCommunities: communitiesInput,\n states: _states,\n communities,\n });\n\n return _states;\n }, [communities]);\n\n return useMemo(\n () => ({\n states,\n peers,\n state: \"initializing\",\n error: undefined,\n errors: [],\n }),\n [states, peers],\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-interval.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/use-interval.ts"],"names":[],"mappings":"AAYA,iBAAS,WAAW,CAClB,QAAQ,EAAE,MAAM,IAAI,EACpB,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,EAC5B,SAAS,CAAC,EAAE,OAAO,EACnB,YAAY,GAAE,GAAG,EAAO,QAuBzB;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* usage:
|
|
2
|
+
|
|
3
|
+
useInterval(
|
|
4
|
+
callback: () => void,
|
|
5
|
+
delay: number,
|
|
6
|
+
immediate?: boolean
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
*/
|
|
10
|
+
import { useEffect, useRef } from "react";
|
|
11
|
+
function useInterval(callback, delay, immediate, dependencies = []) {
|
|
12
|
+
const savedCallback = useRef(undefined);
|
|
13
|
+
// Remember the latest callback.
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
savedCallback.current = callback;
|
|
16
|
+
});
|
|
17
|
+
// Execute callback if immediate is set.
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
var _a;
|
|
20
|
+
if (!immediate)
|
|
21
|
+
return;
|
|
22
|
+
if (delay === null || delay === false)
|
|
23
|
+
return;
|
|
24
|
+
(_a = savedCallback.current) === null || _a === void 0 ? void 0 : _a.call(savedCallback);
|
|
25
|
+
}, [immediate, ...dependencies]);
|
|
26
|
+
// Set up the interval.
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (delay === null || delay === false)
|
|
29
|
+
return undefined;
|
|
30
|
+
const tick = () => { var _a; return (_a = savedCallback.current) === null || _a === void 0 ? void 0 : _a.call(savedCallback); };
|
|
31
|
+
const id = setInterval(tick, delay);
|
|
32
|
+
return () => clearInterval(id);
|
|
33
|
+
}, [delay]);
|
|
34
|
+
}
|
|
35
|
+
export default useInterval;
|
|
36
|
+
//# sourceMappingURL=use-interval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-interval.js","sourceRoot":"","sources":["../../../src/hooks/utils/use-interval.ts"],"names":[],"mappings":"AAAA;;;;;;;;EAQE;AAEF,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,SAAS,WAAW,CAClB,QAAoB,EACpB,KAA4B,EAC5B,SAAmB,EACnB,eAAsB,EAAE;IAExB,MAAM,aAAa,GAAG,MAAM,CAA2B,SAAS,CAAC,CAAC;IAElE,gCAAgC;IAChC,SAAS,CAAC,GAAG,EAAE;QACb,aAAa,CAAC,OAAO,GAAG,QAAQ,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,wCAAwC;IACxC,SAAS,CAAC,GAAG,EAAE;;QACb,IAAI,CAAC,SAAS;YAAE,OAAO;QACvB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK;YAAE,OAAO;QAC9C,MAAA,aAAa,CAAC,OAAO,6DAAI,CAAC;IAC5B,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC;IAEjC,uBAAuB;IACvB,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK;YAAE,OAAO,SAAS,CAAC;QACxD,MAAM,IAAI,GAAG,GAAG,EAAE,WAAC,OAAA,MAAA,aAAa,CAAC,OAAO,6DAAI,CAAA,EAAA,CAAC;QAC7C,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACpC,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,CAAC;AAED,eAAe,WAAW,CAAC","sourcesContent":["/* usage:\n\nuseInterval(\n callback: () => void,\n delay: number,\n immediate?: boolean\n)\n\n*/\n\nimport { useEffect, useRef } from \"react\";\n\nfunction useInterval(\n callback: () => void,\n delay: number | null | false,\n immediate?: boolean,\n dependencies: any[] = [],\n) {\n const savedCallback = useRef<(() => void) | undefined>(undefined);\n\n // Remember the latest callback.\n useEffect(() => {\n savedCallback.current = callback;\n });\n\n // Execute callback if immediate is set.\n useEffect(() => {\n if (!immediate) return;\n if (delay === null || delay === false) return;\n savedCallback.current?.();\n }, [immediate, ...dependencies]);\n\n // Set up the interval.\n useEffect(() => {\n if (delay === null || delay === false) return undefined;\n const tick = () => savedCallback.current?.();\n const id = setInterval(tick, delay);\n return () => clearInterval(id);\n }, [delay]);\n}\n\nexport default useInterval;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function usePrevious<Type>(value: Type): Type | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
export default function usePrevious(value) {
|
|
3
|
+
const [current, setCurrent] = useState(value);
|
|
4
|
+
const [previous, setPrevious] = useState();
|
|
5
|
+
if (value !== current) {
|
|
6
|
+
setPrevious(current);
|
|
7
|
+
setCurrent(value);
|
|
8
|
+
}
|
|
9
|
+
return previous;
|
|
10
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { useAccount, useAccounts, useAccountComment, useAccountComments, useAccountVotes, useAccountVote, useAccountEdits, useEditedComment, useNotifications, useAccountCommunities, usePubsubSubscribe } from "./hooks/accounts/index.js";
|
|
2
|
+
import { useComment, useComments, useValidateComment } from "./hooks/comments.js";
|
|
3
|
+
import { useReplies } from "./hooks/replies.js";
|
|
4
|
+
import { useCommunity, useCommunities, useCommunityStats, useListCommunities, useResolvedCommunityAddress } from "./hooks/communities.js";
|
|
5
|
+
import { useFeed, useBufferedFeeds } from "./hooks/feeds/index.js";
|
|
6
|
+
import { useAuthor, useAuthorComments, useAuthorAvatar, useResolvedAuthorAddress, useAuthorAddress, setAuthorAvatarsWhitelistedTokenAddresses, resetAuthorAddressCacheForTesting } from "./hooks/authors/index.js";
|
|
7
|
+
import { useSubscribe, useBlock, usePublishComment, usePublishVote, useCreateCommunity, usePublishCommentEdit, usePublishCommentModeration, usePublishCommunityEdit } from "./hooks/actions/index.js";
|
|
8
|
+
import { createAccount, deleteAccount, deleteComment, setAccount, setActiveAccount, setAccountsOrder, importAccount, exportAccount, deleteCommunity } from "./stores/accounts/accounts-actions.js";
|
|
9
|
+
import { useClientsStates, useCommunitiesStates } from "./hooks/states.js";
|
|
10
|
+
import { usePkcRpcSettings } from "./hooks/pkc-rpc.js";
|
|
11
|
+
import { getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, validateEthWallet } from "./lib/chain/index.js";
|
|
12
|
+
import { setPkcJs, restorePkcJs } from "./lib/pkc-js/index.js";
|
|
13
|
+
import { deleteDatabases, deleteCaches } from "./lib/debug-utils.js";
|
|
14
|
+
export * from "./types.js";
|
|
15
|
+
export { useAccount, useAccounts, useAccountComment, useAccountComments, useAccountVotes, useAccountVote, useAccountEdits, useAccountCommunities, useNotifications, usePubsubSubscribe, useComment, useComments, useEditedComment, useValidateComment, useReplies, useCommunity, useCommunities, useCommunityStats, useListCommunities, useResolvedCommunityAddress, useAuthor, useAuthorComments, useAuthorAvatar, useResolvedAuthorAddress, useAuthorAddress, setAuthorAvatarsWhitelistedTokenAddresses, resetAuthorAddressCacheForTesting, useFeed, useBufferedFeeds, useSubscribe, useBlock, usePublishComment, usePublishVote, usePublishCommentEdit, usePublishCommentModeration, usePublishCommunityEdit, useCreateCommunity, createAccount, deleteAccount, deleteComment, setAccount, setActiveAccount, setAccountsOrder, importAccount, exportAccount, deleteCommunity, useClientsStates, useCommunitiesStates, usePkcRpcSettings, getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, validateEthWallet, setPkcJs, restorePkcJs, deleteDatabases, deleteCaches, };
|
|
16
|
+
declare const hooks: {
|
|
17
|
+
useAccount: typeof useAccount;
|
|
18
|
+
useAccounts: typeof useAccounts;
|
|
19
|
+
useAccountComment: typeof useAccountComment;
|
|
20
|
+
useAccountComments: typeof useAccountComments;
|
|
21
|
+
useAccountVotes: typeof useAccountVotes;
|
|
22
|
+
useAccountVote: typeof useAccountVote;
|
|
23
|
+
useAccountEdits: typeof useAccountEdits;
|
|
24
|
+
useAccountCommunities: typeof useAccountCommunities;
|
|
25
|
+
useNotifications: typeof useNotifications;
|
|
26
|
+
usePubsubSubscribe: typeof usePubsubSubscribe;
|
|
27
|
+
useComment: typeof useComment;
|
|
28
|
+
useComments: typeof useComments;
|
|
29
|
+
useEditedComment: typeof useEditedComment;
|
|
30
|
+
useValidateComment: typeof useValidateComment;
|
|
31
|
+
useReplies: typeof useReplies;
|
|
32
|
+
useCommunity: typeof useCommunity;
|
|
33
|
+
useCommunities: typeof useCommunities;
|
|
34
|
+
useCommunityStats: typeof useCommunityStats;
|
|
35
|
+
useListCommunities: typeof useListCommunities;
|
|
36
|
+
useResolvedCommunityAddress: typeof useResolvedCommunityAddress;
|
|
37
|
+
useAuthor: typeof useAuthor;
|
|
38
|
+
useAuthorComments: typeof useAuthorComments;
|
|
39
|
+
useAuthorAvatar: typeof useAuthorAvatar;
|
|
40
|
+
useResolvedAuthorAddress: typeof useResolvedAuthorAddress;
|
|
41
|
+
useAuthorAddress: typeof useAuthorAddress;
|
|
42
|
+
setAuthorAvatarsWhitelistedTokenAddresses: (tokenAddresses: string[]) => void;
|
|
43
|
+
resetAuthorAddressCacheForTesting: typeof resetAuthorAddressCacheForTesting;
|
|
44
|
+
useFeed: typeof useFeed;
|
|
45
|
+
useBufferedFeeds: typeof useBufferedFeeds;
|
|
46
|
+
useSubscribe: typeof useSubscribe;
|
|
47
|
+
useBlock: typeof useBlock;
|
|
48
|
+
usePublishComment: typeof usePublishComment;
|
|
49
|
+
usePublishVote: typeof usePublishVote;
|
|
50
|
+
usePublishCommentEdit: typeof usePublishCommentEdit;
|
|
51
|
+
usePublishCommentModeration: typeof usePublishCommentModeration;
|
|
52
|
+
usePublishCommunityEdit: typeof usePublishCommunityEdit;
|
|
53
|
+
useCreateCommunity: typeof useCreateCommunity;
|
|
54
|
+
createAccount: (accountName?: string) => Promise<void>;
|
|
55
|
+
deleteAccount: (accountName?: string) => Promise<void>;
|
|
56
|
+
deleteComment: (commentCidOrAccountCommentIndex: string | number, accountName?: string) => Promise<void>;
|
|
57
|
+
setAccount: (account: import("./types.js").Account) => Promise<void>;
|
|
58
|
+
setActiveAccount: (accountName: string) => Promise<void>;
|
|
59
|
+
setAccountsOrder: (newOrderedAccountNames: string[]) => Promise<void>;
|
|
60
|
+
importAccount: (serializedAccount: string) => Promise<void>;
|
|
61
|
+
exportAccount: (accountName?: string) => Promise<string>;
|
|
62
|
+
deleteCommunity: (communityAddress: string, accountName?: string) => Promise<void>;
|
|
63
|
+
useClientsStates: typeof useClientsStates;
|
|
64
|
+
useCommunitiesStates: typeof useCommunitiesStates;
|
|
65
|
+
usePkcRpcSettings: typeof usePkcRpcSettings;
|
|
66
|
+
getEthWalletFromPkcPrivateKey: (privateKeyBase64: string, authorAddress: string) => Promise<{
|
|
67
|
+
address: string;
|
|
68
|
+
timestamp: number;
|
|
69
|
+
signature: {
|
|
70
|
+
signature: string;
|
|
71
|
+
type: string;
|
|
72
|
+
};
|
|
73
|
+
} | undefined>;
|
|
74
|
+
getEthPrivateKeyFromPkcPrivateKey: (privateKeyBase64: string, authorAddress: string) => Promise<string | undefined>;
|
|
75
|
+
validateEthWallet: (wallet: import("./types.js").Wallet, authorAddress: string) => Promise<void>;
|
|
76
|
+
setPkcJs: typeof setPkcJs;
|
|
77
|
+
restorePkcJs: typeof restorePkcJs;
|
|
78
|
+
deleteDatabases: () => Promise<[void, void, any, any, any]>;
|
|
79
|
+
deleteCaches: () => Promise<[any, any, any]>;
|
|
80
|
+
};
|
|
81
|
+
export default hooks;
|
|
82
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,EAClB,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG/E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EACL,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,2BAA2B,EAC5B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,yCAAyC,EACzC,iCAAiC,EAClC,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,uBAAuB,EACxB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,aAAa,EACb,aAAa,EACb,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EAChB,MAAM,oCAAoC,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,EACL,6BAA6B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