@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.
Files changed (269) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +1365 -0
  3. package/dist/hooks/accounts/accounts.d.ts +64 -0
  4. package/dist/hooks/accounts/accounts.d.ts.map +1 -0
  5. package/dist/hooks/accounts/accounts.js +706 -0
  6. package/dist/hooks/accounts/accounts.js.map +1 -0
  7. package/dist/hooks/accounts/index.d.ts +2 -0
  8. package/dist/hooks/accounts/index.d.ts.map +1 -0
  9. package/dist/hooks/accounts/index.js +2 -0
  10. package/dist/hooks/accounts/index.js.map +1 -0
  11. package/dist/hooks/accounts/utils.d.ts +6 -0
  12. package/dist/hooks/accounts/utils.d.ts.map +1 -0
  13. package/dist/hooks/accounts/utils.js +226 -0
  14. package/dist/hooks/accounts/utils.js.map +1 -0
  15. package/dist/hooks/actions/actions.d.ts +19 -0
  16. package/dist/hooks/actions/actions.d.ts.map +1 -0
  17. package/dist/hooks/actions/actions.js +552 -0
  18. package/dist/hooks/actions/actions.js.map +1 -0
  19. package/dist/hooks/actions/index.d.ts +2 -0
  20. package/dist/hooks/actions/index.d.ts.map +1 -0
  21. package/dist/hooks/actions/index.js +2 -0
  22. package/dist/hooks/actions/index.js.map +1 -0
  23. package/dist/hooks/authors/author-avatars.d.ts +28 -0
  24. package/dist/hooks/authors/author-avatars.d.ts.map +1 -0
  25. package/dist/hooks/authors/author-avatars.js +191 -0
  26. package/dist/hooks/authors/author-avatars.js.map +1 -0
  27. package/dist/hooks/authors/authors.d.ts +37 -0
  28. package/dist/hooks/authors/authors.d.ts.map +1 -0
  29. package/dist/hooks/authors/authors.js +509 -0
  30. package/dist/hooks/authors/authors.js.map +1 -0
  31. package/dist/hooks/authors/index.d.ts +2 -0
  32. package/dist/hooks/authors/index.d.ts.map +1 -0
  33. package/dist/hooks/authors/index.js +2 -0
  34. package/dist/hooks/authors/index.js.map +1 -0
  35. package/dist/hooks/authors/utils.d.ts +4 -0
  36. package/dist/hooks/authors/utils.d.ts.map +1 -0
  37. package/dist/hooks/authors/utils.js +21 -0
  38. package/dist/hooks/authors/utils.js.map +1 -0
  39. package/dist/hooks/comments.d.ts +17 -0
  40. package/dist/hooks/comments.d.ts.map +1 -0
  41. package/dist/hooks/comments.js +351 -0
  42. package/dist/hooks/comments.js.map +1 -0
  43. package/dist/hooks/communities.d.ts +31 -0
  44. package/dist/hooks/communities.d.ts.map +1 -0
  45. package/dist/hooks/communities.js +389 -0
  46. package/dist/hooks/communities.js.map +1 -0
  47. package/dist/hooks/feeds/feeds.d.ts +18 -0
  48. package/dist/hooks/feeds/feeds.d.ts.map +1 -0
  49. package/dist/hooks/feeds/feeds.js +315 -0
  50. package/dist/hooks/feeds/feeds.js.map +1 -0
  51. package/dist/hooks/feeds/index.d.ts +2 -0
  52. package/dist/hooks/feeds/index.d.ts.map +1 -0
  53. package/dist/hooks/feeds/index.js +2 -0
  54. package/dist/hooks/feeds/index.js.map +1 -0
  55. package/dist/hooks/pkc-rpc.d.ts +7 -0
  56. package/dist/hooks/pkc-rpc.d.ts.map +1 -0
  57. package/dist/hooks/pkc-rpc.js +88 -0
  58. package/dist/hooks/pkc-rpc.js.map +1 -0
  59. package/dist/hooks/replies.d.ts +5 -0
  60. package/dist/hooks/replies.d.ts.map +1 -0
  61. package/dist/hooks/replies.js +155 -0
  62. package/dist/hooks/replies.js.map +1 -0
  63. package/dist/hooks/states.d.ts +15 -0
  64. package/dist/hooks/states.d.ts.map +1 -0
  65. package/dist/hooks/states.js +213 -0
  66. package/dist/hooks/states.js.map +1 -0
  67. package/dist/hooks/utils/use-interval.d.ts +3 -0
  68. package/dist/hooks/utils/use-interval.d.ts.map +1 -0
  69. package/dist/hooks/utils/use-interval.js +36 -0
  70. package/dist/hooks/utils/use-interval.js.map +1 -0
  71. package/dist/hooks/utils/use-previous.d.ts +1 -0
  72. package/dist/hooks/utils/use-previous.js +10 -0
  73. package/dist/index.d.ts +82 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +128 -0
  76. package/dist/index.js.map +1 -0
  77. package/dist/lib/chain/chain.d.ts +36 -0
  78. package/dist/lib/chain/chain.d.ts.map +1 -0
  79. package/dist/lib/chain/chain.js +195 -0
  80. package/dist/lib/chain/chain.js.map +1 -0
  81. package/dist/lib/chain/index.d.ts +4 -0
  82. package/dist/lib/chain/index.d.ts.map +1 -0
  83. package/dist/lib/chain/index.js +4 -0
  84. package/dist/lib/chain/index.js.map +1 -0
  85. package/dist/lib/community-address.d.ts +6 -0
  86. package/dist/lib/community-address.d.ts.map +1 -0
  87. package/dist/lib/community-address.js +26 -0
  88. package/dist/lib/community-address.js.map +1 -0
  89. package/dist/lib/community-ref.d.ts +23 -0
  90. package/dist/lib/community-ref.d.ts.map +1 -0
  91. package/dist/lib/community-ref.js +113 -0
  92. package/dist/lib/community-ref.js.map +1 -0
  93. package/dist/lib/debug-utils.d.ts +9 -0
  94. package/dist/lib/debug-utils.d.ts.map +1 -0
  95. package/dist/lib/debug-utils.js +21 -0
  96. package/dist/lib/debug-utils.js.map +1 -0
  97. package/dist/lib/feed-sort-type.d.ts +2 -0
  98. package/dist/lib/feed-sort-type.d.ts.map +1 -0
  99. package/dist/lib/feed-sort-type.js +22 -0
  100. package/dist/lib/feed-sort-type.js.map +1 -0
  101. package/dist/lib/localforage-lru/index.d.ts +3 -0
  102. package/dist/lib/localforage-lru/index.d.ts.map +1 -0
  103. package/dist/lib/localforage-lru/index.js +46 -0
  104. package/dist/lib/localforage-lru/index.js.map +1 -0
  105. package/dist/lib/localforage-lru/localforage-lru.d.ts +6 -0
  106. package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -0
  107. package/dist/lib/localforage-lru/localforage-lru.js +182 -0
  108. package/dist/lib/localforage-lru/localforage-lru.js.map +1 -0
  109. package/dist/lib/pkc-compat.d.ts +25 -0
  110. package/dist/lib/pkc-compat.d.ts.map +1 -0
  111. package/dist/lib/pkc-compat.js +131 -0
  112. package/dist/lib/pkc-compat.js.map +1 -0
  113. package/dist/lib/pkc-js/fixtures/markdown-example.d.ts +3 -0
  114. package/dist/lib/pkc-js/fixtures/markdown-example.d.ts.map +1 -0
  115. package/dist/lib/pkc-js/fixtures/markdown-example.js +280 -0
  116. package/dist/lib/pkc-js/fixtures/markdown-example.js.map +1 -0
  117. package/dist/lib/pkc-js/index.d.ts +11 -0
  118. package/dist/lib/pkc-js/index.d.ts.map +1 -0
  119. package/dist/lib/pkc-js/index.js +85 -0
  120. package/dist/lib/pkc-js/index.js.map +1 -0
  121. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts +3 -0
  122. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -0
  123. package/dist/lib/pkc-js/pkc-js-mock-content.js +1235 -0
  124. package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -0
  125. package/dist/lib/pkc-js/pkc-js-mock.d.ts +137 -0
  126. package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -0
  127. package/dist/lib/pkc-js/pkc-js-mock.js +644 -0
  128. package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -0
  129. package/dist/lib/polyfill.d.ts +3 -0
  130. package/dist/lib/polyfill.d.ts.map +1 -0
  131. package/dist/lib/polyfill.js +14 -0
  132. package/dist/lib/polyfill.js.map +1 -0
  133. package/dist/lib/protocol-compat.d.ts +14 -0
  134. package/dist/lib/protocol-compat.d.ts.map +1 -0
  135. package/dist/lib/protocol-compat.js +67 -0
  136. package/dist/lib/protocol-compat.js.map +1 -0
  137. package/dist/lib/test-utils.d.ts +29 -0
  138. package/dist/lib/test-utils.d.ts.map +1 -0
  139. package/dist/lib/test-utils.js +184 -0
  140. package/dist/lib/test-utils.js.map +1 -0
  141. package/dist/lib/utils/comment-moderation.d.ts +4 -0
  142. package/dist/lib/utils/comment-moderation.d.ts.map +1 -0
  143. package/dist/lib/utils/comment-moderation.js +56 -0
  144. package/dist/lib/utils/comment-moderation.js.map +1 -0
  145. package/dist/lib/utils/index.d.ts +4 -0
  146. package/dist/lib/utils/index.d.ts.map +1 -0
  147. package/dist/lib/utils/index.js +4 -0
  148. package/dist/lib/utils/index.js.map +1 -0
  149. package/dist/lib/utils/utils.d.ts +23 -0
  150. package/dist/lib/utils/utils.d.ts.map +1 -0
  151. package/dist/lib/utils/utils.js +375 -0
  152. package/dist/lib/utils/utils.js.map +1 -0
  153. package/dist/lib/validator.d.ts +30 -0
  154. package/dist/lib/validator.d.ts.map +1 -0
  155. package/dist/lib/validator.js +307 -0
  156. package/dist/lib/validator.js.map +1 -0
  157. package/dist/stores/accounts/account-generator.d.ts +51 -0
  158. package/dist/stores/accounts/account-generator.d.ts.map +1 -0
  159. package/dist/stores/accounts/account-generator.js +160 -0
  160. package/dist/stores/accounts/account-generator.js.map +1 -0
  161. package/dist/stores/accounts/accounts-actions-internal.d.ts +8 -0
  162. package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -0
  163. package/dist/stores/accounts/accounts-actions-internal.js +403 -0
  164. package/dist/stores/accounts/accounts-actions-internal.js.map +1 -0
  165. package/dist/stores/accounts/accounts-actions.d.ts +46 -0
  166. package/dist/stores/accounts/accounts-actions.d.ts.map +1 -0
  167. package/dist/stores/accounts/accounts-actions.js +1341 -0
  168. package/dist/stores/accounts/accounts-actions.js.map +1 -0
  169. package/dist/stores/accounts/accounts-database.d.ts +34 -0
  170. package/dist/stores/accounts/accounts-database.d.ts.map +1 -0
  171. package/dist/stores/accounts/accounts-database.js +685 -0
  172. package/dist/stores/accounts/accounts-database.js.map +1 -0
  173. package/dist/stores/accounts/accounts-store.d.ts +32 -0
  174. package/dist/stores/accounts/accounts-store.d.ts.map +1 -0
  175. package/dist/stores/accounts/accounts-store.js +169 -0
  176. package/dist/stores/accounts/accounts-store.js.map +1 -0
  177. package/dist/stores/accounts/index.d.ts +4 -0
  178. package/dist/stores/accounts/index.d.ts.map +1 -0
  179. package/dist/stores/accounts/index.js +4 -0
  180. package/dist/stores/accounts/index.js.map +1 -0
  181. package/dist/stores/accounts/utils.d.ts +49 -0
  182. package/dist/stores/accounts/utils.d.ts.map +1 -0
  183. package/dist/stores/accounts/utils.js +419 -0
  184. package/dist/stores/accounts/utils.js.map +1 -0
  185. package/dist/stores/authors-comments/authors-comments-store.d.ts +37 -0
  186. package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -0
  187. package/dist/stores/authors-comments/authors-comments-store.js +338 -0
  188. package/dist/stores/authors-comments/authors-comments-store.js.map +1 -0
  189. package/dist/stores/authors-comments/index.d.ts +4 -0
  190. package/dist/stores/authors-comments/index.d.ts.map +1 -0
  191. package/dist/stores/authors-comments/index.js +4 -0
  192. package/dist/stores/authors-comments/index.js.map +1 -0
  193. package/dist/stores/authors-comments/utils.d.ts +14 -0
  194. package/dist/stores/authors-comments/utils.d.ts.map +1 -0
  195. package/dist/stores/authors-comments/utils.js +81 -0
  196. package/dist/stores/authors-comments/utils.js.map +1 -0
  197. package/dist/stores/comments/comments-store.d.ts +19 -0
  198. package/dist/stores/comments/comments-store.d.ts.map +1 -0
  199. package/dist/stores/comments/comments-store.js +385 -0
  200. package/dist/stores/comments/comments-store.js.map +1 -0
  201. package/dist/stores/comments/index.d.ts +4 -0
  202. package/dist/stores/comments/index.d.ts.map +1 -0
  203. package/dist/stores/comments/index.js +4 -0
  204. package/dist/stores/comments/index.js.map +1 -0
  205. package/dist/stores/communities/communities-store.d.ts +17 -0
  206. package/dist/stores/communities/communities-store.d.ts.map +1 -0
  207. package/dist/stores/communities/communities-store.js +304 -0
  208. package/dist/stores/communities/communities-store.js.map +1 -0
  209. package/dist/stores/communities/index.d.ts +4 -0
  210. package/dist/stores/communities/index.d.ts.map +1 -0
  211. package/dist/stores/communities/index.js +4 -0
  212. package/dist/stores/communities/index.js.map +1 -0
  213. package/dist/stores/communities-pages/communities-pages-store.d.ts +23 -0
  214. package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -0
  215. package/dist/stores/communities-pages/communities-pages-store.js +316 -0
  216. package/dist/stores/communities-pages/communities-pages-store.js.map +1 -0
  217. package/dist/stores/communities-pages/index.d.ts +4 -0
  218. package/dist/stores/communities-pages/index.d.ts.map +1 -0
  219. package/dist/stores/communities-pages/index.js +4 -0
  220. package/dist/stores/communities-pages/index.js.map +1 -0
  221. package/dist/stores/feeds/feed-sorter.d.ts +5 -0
  222. package/dist/stores/feeds/feed-sorter.d.ts.map +1 -0
  223. package/dist/stores/feeds/feed-sorter.js +135 -0
  224. package/dist/stores/feeds/feed-sorter.js.map +1 -0
  225. package/dist/stores/feeds/feeds-store.d.ts +25 -0
  226. package/dist/stores/feeds/feeds-store.d.ts.map +1 -0
  227. package/dist/stores/feeds/feeds-store.js +459 -0
  228. package/dist/stores/feeds/feeds-store.js.map +1 -0
  229. package/dist/stores/feeds/index.d.ts +4 -0
  230. package/dist/stores/feeds/index.d.ts.map +1 -0
  231. package/dist/stores/feeds/index.js +4 -0
  232. package/dist/stores/feeds/index.js.map +1 -0
  233. package/dist/stores/feeds/utils.d.ts +43 -0
  234. package/dist/stores/feeds/utils.d.ts.map +1 -0
  235. package/dist/stores/feeds/utils.js +736 -0
  236. package/dist/stores/feeds/utils.js.map +1 -0
  237. package/dist/stores/replies/index.d.ts +4 -0
  238. package/dist/stores/replies/index.d.ts.map +1 -0
  239. package/dist/stores/replies/index.js +4 -0
  240. package/dist/stores/replies/index.js.map +1 -0
  241. package/dist/stores/replies/replies-comments-store.d.ts +8 -0
  242. package/dist/stores/replies/replies-comments-store.d.ts.map +1 -0
  243. package/dist/stores/replies/replies-comments-store.js +23 -0
  244. package/dist/stores/replies/replies-comments-store.js.map +1 -0
  245. package/dist/stores/replies/replies-store.d.ts +29 -0
  246. package/dist/stores/replies/replies-store.d.ts.map +1 -0
  247. package/dist/stores/replies/replies-store.js +413 -0
  248. package/dist/stores/replies/replies-store.js.map +1 -0
  249. package/dist/stores/replies/utils.d.ts +25 -0
  250. package/dist/stores/replies/utils.d.ts.map +1 -0
  251. package/dist/stores/replies/utils.js +549 -0
  252. package/dist/stores/replies/utils.js.map +1 -0
  253. package/dist/stores/replies-pages/index.d.ts +4 -0
  254. package/dist/stores/replies-pages/index.d.ts.map +1 -0
  255. package/dist/stores/replies-pages/index.js +4 -0
  256. package/dist/stores/replies-pages/index.js.map +1 -0
  257. package/dist/stores/replies-pages/replies-pages-store.d.ts +20 -0
  258. package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -0
  259. package/dist/stores/replies-pages/replies-pages-store.js +270 -0
  260. package/dist/stores/replies-pages/replies-pages-store.js.map +1 -0
  261. package/dist/stores/replies-pages/utils.d.ts +3 -0
  262. package/dist/stores/replies-pages/utils.d.ts.map +1 -0
  263. package/dist/stores/replies-pages/utils.js +43 -0
  264. package/dist/stores/replies-pages/utils.js.map +1 -0
  265. package/dist/types.d.ts +638 -0
  266. package/dist/types.d.ts.map +1 -0
  267. package/dist/types.js +3 -0
  268. package/dist/types.js.map +1 -0
  269. package/package.json +160 -0
@@ -0,0 +1,552 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { useMemo, useRef, useState } from "react";
22
+ import useAccountsStore from "../../stores/accounts/index.js";
23
+ import Logger from "@pkcprotocol/pkc-logger";
24
+ const log = Logger("bitsocial-react-hooks:actions:hooks");
25
+ import assert from "assert";
26
+ import { useAccount, useAccountId } from "../accounts/index.js";
27
+ /** Wraps a callback to no-op when guard returns false. Exported for coverage. */
28
+ export function withGuardActive(guardActive, fn) {
29
+ return ((...args) => {
30
+ if (!guardActive())
31
+ return;
32
+ return fn(...args);
33
+ });
34
+ }
35
+ const noop = () => { };
36
+ /** For usePublishComment: when abandoned, catch should no-op. Exported for coverage. */
37
+ export function handlePublishErrorWhenAbandoned(activeRequestIdRef, requestId, error, setErrors, onError) {
38
+ if (activeRequestIdRef.current !== requestId)
39
+ return;
40
+ setErrors((errors) => [...errors, error]);
41
+ (onError !== null && onError !== void 0 ? onError : noop)(error);
42
+ }
43
+ /** For usePublishVote catch. Exported for coverage. */
44
+ export function handlePublishVoteError(error, setErrors, onError) {
45
+ setErrors((errors) => [...errors, error]);
46
+ (onError !== null && onError !== void 0 ? onError : noop)(error);
47
+ }
48
+ const publishChallengeAnswersNotReady = (challengeAnswers) => __awaiter(void 0, void 0, void 0, function* () {
49
+ throw Error(`can't call publishChallengeAnswers() before result.challenge is defined (before the challenge message is received)`);
50
+ });
51
+ export function useSubscribe(options) {
52
+ var _a;
53
+ assert(!options || typeof options === "object", `useSubscribe options argument '${options}' not an object`);
54
+ const { communityAddress, accountName, onError } = options || {};
55
+ const account = useAccount({ accountName });
56
+ const accountsActions = useAccountsStore((state) => state.accountsActions);
57
+ const [errors, setErrors] = useState([]);
58
+ let state = "initializing";
59
+ let subscribed;
60
+ // before the account and communityAddress is defined, nothing can happen
61
+ if (account && communityAddress) {
62
+ state = "ready";
63
+ subscribed = Boolean((_a = account.subscriptions) === null || _a === void 0 ? void 0 : _a.includes(communityAddress));
64
+ }
65
+ const subscribe = () => __awaiter(this, void 0, void 0, function* () {
66
+ try {
67
+ yield accountsActions.subscribe(communityAddress, accountName);
68
+ }
69
+ catch (e) {
70
+ setErrors((errors) => [...errors, e]);
71
+ onError === null || onError === void 0 ? void 0 : onError(e);
72
+ }
73
+ });
74
+ const unsubscribe = () => __awaiter(this, void 0, void 0, function* () {
75
+ try {
76
+ yield accountsActions.unsubscribe(communityAddress, accountName);
77
+ }
78
+ catch (e) {
79
+ setErrors((errors) => [...errors, e]);
80
+ onError === null || onError === void 0 ? void 0 : onError(e);
81
+ }
82
+ });
83
+ return useMemo(() => ({
84
+ subscribed,
85
+ subscribe,
86
+ unsubscribe,
87
+ state,
88
+ error: errors[errors.length - 1],
89
+ errors,
90
+ }), [state, subscribed, errors, communityAddress, accountName]);
91
+ }
92
+ export function useBlock(options) {
93
+ assert(!options || typeof options === "object", `useBlock options argument '${options}' not an object`);
94
+ const { address, cid, accountName, onError } = options || {};
95
+ if (address && cid) {
96
+ throw Error(`can't useBlock with both an address '${address}' and cid '${cid}' argument at the same time`);
97
+ }
98
+ const account = useAccount({ accountName });
99
+ const accountsActions = useAccountsStore((state) => state.accountsActions);
100
+ const [errors, setErrors] = useState([]);
101
+ let state = "initializing";
102
+ let blocked;
103
+ // before the account and address is defined, nothing can happen
104
+ if (account && (address || cid)) {
105
+ state = "ready";
106
+ if (address) {
107
+ blocked = Boolean(account.blockedAddresses[address]);
108
+ }
109
+ if (cid) {
110
+ blocked = Boolean(account.blockedCids[cid]);
111
+ }
112
+ }
113
+ const block = () => __awaiter(this, void 0, void 0, function* () {
114
+ try {
115
+ if (cid) {
116
+ yield accountsActions.blockCid(cid, accountName);
117
+ }
118
+ else {
119
+ yield accountsActions.blockAddress(address, accountName);
120
+ }
121
+ }
122
+ catch (e) {
123
+ setErrors((errors) => [...errors, e]);
124
+ onError === null || onError === void 0 ? void 0 : onError(e);
125
+ }
126
+ });
127
+ const unblock = () => __awaiter(this, void 0, void 0, function* () {
128
+ try {
129
+ if (cid) {
130
+ yield accountsActions.unblockCid(cid, accountName);
131
+ }
132
+ else {
133
+ yield accountsActions.unblockAddress(address, accountName);
134
+ }
135
+ }
136
+ catch (e) {
137
+ setErrors((errors) => [...errors, e]);
138
+ onError === null || onError === void 0 ? void 0 : onError(e);
139
+ }
140
+ });
141
+ return useMemo(() => ({
142
+ blocked,
143
+ block,
144
+ unblock,
145
+ state,
146
+ error: errors[errors.length - 1],
147
+ errors,
148
+ }), [state, blocked, errors, address, accountName]);
149
+ }
150
+ export function usePublishComment(options) {
151
+ assert(!options || typeof options === "object", `usePublishComment options argument '${options}' not an object`);
152
+ const _a = options || {}, { accountName } = _a, publishCommentOptions = __rest(_a, ["accountName"]);
153
+ const accountsActions = useAccountsStore((state) => state.accountsActions);
154
+ const accountId = useAccountId(accountName);
155
+ const [errors, setErrors] = useState([]);
156
+ const [publishingState, setPublishingState] = useState();
157
+ const [index, setIndex] = useState();
158
+ const [challenge, setChallenge] = useState();
159
+ const [challengeVerification, setChallengeVerification] = useState();
160
+ const [publishChallengeAnswers, setPublishChallengeAnswers] = useState();
161
+ const indexRef = useRef(undefined);
162
+ const publishRequestIdRef = useRef(0);
163
+ const activePublishRequestIdRef = useRef(undefined);
164
+ const guardActive = () => activePublishRequestIdRef.current !== undefined;
165
+ publishCommentOptions._onPendingCommentIndex = withGuardActive(guardActive, (pendingIndex) => {
166
+ indexRef.current = pendingIndex;
167
+ setIndex(pendingIndex);
168
+ });
169
+ let initialState = "initializing";
170
+ if (accountId && options)
171
+ initialState = "ready";
172
+ const originalOnError = publishCommentOptions.onError;
173
+ const onError = (error) => __awaiter(this, void 0, void 0, function* () {
174
+ setErrors((errors) => [...errors, error]);
175
+ (originalOnError !== null && originalOnError !== void 0 ? originalOnError : noop)(error);
176
+ });
177
+ publishCommentOptions.onError = onError;
178
+ const originalOnChallenge = publishCommentOptions.onChallenge;
179
+ publishCommentOptions.onChallenge = withGuardActive(guardActive, (challenge, comment) => __awaiter(this, void 0, void 0, function* () {
180
+ setPublishChallengeAnswers(() => comment === null || comment === void 0 ? void 0 : comment.publishChallengeAnswers.bind(comment));
181
+ setChallenge(challenge);
182
+ (originalOnChallenge !== null && originalOnChallenge !== void 0 ? originalOnChallenge : noop)(challenge, comment);
183
+ }));
184
+ const originalOnChallengeVerification = publishCommentOptions.onChallengeVerification;
185
+ publishCommentOptions.onChallengeVerification = withGuardActive(guardActive, (challengeVerification, comment) => __awaiter(this, void 0, void 0, function* () {
186
+ setChallengeVerification(challengeVerification);
187
+ (originalOnChallengeVerification !== null && originalOnChallengeVerification !== void 0 ? originalOnChallengeVerification : noop)(challengeVerification, comment);
188
+ }));
189
+ publishCommentOptions.onPublishingStateChange = withGuardActive(guardActive, (publishingState) => setPublishingState(publishingState));
190
+ const publishComment = () => __awaiter(this, void 0, void 0, function* () {
191
+ const requestId = publishRequestIdRef.current + 1;
192
+ publishRequestIdRef.current = requestId;
193
+ activePublishRequestIdRef.current = requestId;
194
+ try {
195
+ const { index } = yield accountsActions.publishComment(publishCommentOptions, accountName);
196
+ if (activePublishRequestIdRef.current !== requestId) {
197
+ return;
198
+ }
199
+ indexRef.current = index;
200
+ setIndex(index);
201
+ }
202
+ catch (e) {
203
+ handlePublishErrorWhenAbandoned(activePublishRequestIdRef, requestId, e, setErrors, originalOnError);
204
+ }
205
+ });
206
+ const abandonPublish = () => __awaiter(this, void 0, void 0, function* () {
207
+ activePublishRequestIdRef.current = undefined;
208
+ const idx = indexRef.current;
209
+ if (idx !== undefined) {
210
+ yield accountsActions.deleteComment(idx, accountName);
211
+ }
212
+ indexRef.current = undefined;
213
+ setChallenge(undefined);
214
+ setChallengeVerification(undefined);
215
+ setPublishChallengeAnswers(undefined);
216
+ setIndex(undefined);
217
+ setPublishingState(undefined);
218
+ });
219
+ return useMemo(() => ({
220
+ index,
221
+ challenge,
222
+ challengeVerification,
223
+ publishComment,
224
+ abandonPublish,
225
+ publishChallengeAnswers: publishChallengeAnswers || publishChallengeAnswersNotReady,
226
+ state: publishingState || initialState,
227
+ error: errors[errors.length - 1],
228
+ errors,
229
+ }), [
230
+ publishingState,
231
+ initialState,
232
+ errors,
233
+ index,
234
+ challenge,
235
+ challengeVerification,
236
+ options,
237
+ accountName,
238
+ publishChallengeAnswers,
239
+ ]);
240
+ }
241
+ export function usePublishVote(options) {
242
+ assert(!options || typeof options === "object", `usePublishVote options argument '${options}' not an object`);
243
+ const _a = options || {}, { accountName } = _a, publishVoteOptions = __rest(_a, ["accountName"]);
244
+ const accountsActions = useAccountsStore((state) => state.accountsActions);
245
+ const accountId = useAccountId(accountName);
246
+ const [errors, setErrors] = useState([]);
247
+ const [publishingState, setPublishingState] = useState();
248
+ const [challenge, setChallenge] = useState();
249
+ const [challengeVerification, setChallengeVerification] = useState();
250
+ const [publishChallengeAnswers, setPublishChallengeAnswers] = useState();
251
+ let initialState = "initializing";
252
+ // before the accountId and options is defined, nothing can happen
253
+ if (accountId && options) {
254
+ initialState = "ready";
255
+ }
256
+ // define onError if not defined
257
+ const originalOnError = publishVoteOptions.onError;
258
+ const onError = (error) => __awaiter(this, void 0, void 0, function* () {
259
+ setErrors((errors) => [...errors, error]);
260
+ originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(error);
261
+ });
262
+ publishVoteOptions.onError = onError;
263
+ // define onChallenge if not defined
264
+ const originalOnChallenge = publishVoteOptions.onChallenge;
265
+ const onChallenge = (challenge, vote) => __awaiter(this, void 0, void 0, function* () {
266
+ setPublishChallengeAnswers(() => vote === null || vote === void 0 ? void 0 : vote.publishChallengeAnswers.bind(vote));
267
+ setChallenge(challenge);
268
+ (originalOnChallenge !== null && originalOnChallenge !== void 0 ? originalOnChallenge : (() => { }))(challenge, vote);
269
+ });
270
+ publishVoteOptions.onChallenge = onChallenge;
271
+ const originalOnChallengeVerification = publishVoteOptions.onChallengeVerification;
272
+ const onChallengeVerification = (challengeVerification, vote) => __awaiter(this, void 0, void 0, function* () {
273
+ setChallengeVerification(challengeVerification);
274
+ (originalOnChallengeVerification !== null && originalOnChallengeVerification !== void 0 ? originalOnChallengeVerification : noop)(challengeVerification, vote);
275
+ });
276
+ publishVoteOptions.onChallengeVerification = onChallengeVerification;
277
+ // change state on publishing state change
278
+ publishVoteOptions.onPublishingStateChange = (publishingState) => {
279
+ setPublishingState(publishingState);
280
+ };
281
+ const publishVote = () => __awaiter(this, void 0, void 0, function* () {
282
+ try {
283
+ yield accountsActions.publishVote(publishVoteOptions, accountName);
284
+ }
285
+ catch (e) {
286
+ handlePublishVoteError(e, setErrors, originalOnError);
287
+ }
288
+ });
289
+ return useMemo(() => ({
290
+ challenge,
291
+ challengeVerification,
292
+ publishVote,
293
+ publishChallengeAnswers: publishChallengeAnswers || publishChallengeAnswersNotReady,
294
+ state: publishingState || initialState,
295
+ error: errors[errors.length - 1],
296
+ errors,
297
+ }), [
298
+ publishingState,
299
+ initialState,
300
+ errors,
301
+ challenge,
302
+ challengeVerification,
303
+ options,
304
+ accountName,
305
+ publishChallengeAnswers,
306
+ ]);
307
+ }
308
+ export function usePublishCommentEdit(options) {
309
+ assert(!options || typeof options === "object", `usePublishCommentEdit options argument '${options}' not an object`);
310
+ const _a = options || {}, { accountName } = _a, publishCommentEditOptions = __rest(_a, ["accountName"]);
311
+ const accountsActions = useAccountsStore((state) => state.accountsActions);
312
+ const accountId = useAccountId(accountName);
313
+ const [errors, setErrors] = useState([]);
314
+ const [publishingState, setPublishingState] = useState();
315
+ const [challenge, setChallenge] = useState();
316
+ const [challengeVerification, setChallengeVerification] = useState();
317
+ const [publishChallengeAnswers, setPublishChallengeAnswers] = useState();
318
+ let initialState = "initializing";
319
+ // before the accountId and options is defined, nothing can happen
320
+ if (accountId && options) {
321
+ initialState = "ready";
322
+ }
323
+ // define onError if not defined
324
+ const originalOnError = publishCommentEditOptions.onError;
325
+ const onError = (error) => __awaiter(this, void 0, void 0, function* () {
326
+ setErrors((errors) => [...errors, error]);
327
+ originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(error);
328
+ });
329
+ publishCommentEditOptions.onError = onError;
330
+ // define onChallenge if not defined
331
+ const originalOnChallenge = publishCommentEditOptions.onChallenge;
332
+ const onChallenge = (challenge, commentEdit) => __awaiter(this, void 0, void 0, function* () {
333
+ // cannot set a function directly with setState
334
+ setPublishChallengeAnswers(() => commentEdit === null || commentEdit === void 0 ? void 0 : commentEdit.publishChallengeAnswers.bind(commentEdit));
335
+ setChallenge(challenge);
336
+ originalOnChallenge === null || originalOnChallenge === void 0 ? void 0 : originalOnChallenge(challenge, commentEdit);
337
+ });
338
+ publishCommentEditOptions.onChallenge = onChallenge;
339
+ // define onChallengeVerification if not defined
340
+ const originalOnChallengeVerification = publishCommentEditOptions.onChallengeVerification;
341
+ const onChallengeVerification = (challengeVerification, commentEdit) => __awaiter(this, void 0, void 0, function* () {
342
+ setChallengeVerification(challengeVerification);
343
+ originalOnChallengeVerification === null || originalOnChallengeVerification === void 0 ? void 0 : originalOnChallengeVerification(challengeVerification, commentEdit);
344
+ });
345
+ publishCommentEditOptions.onChallengeVerification = onChallengeVerification;
346
+ // change state on publishing state change
347
+ publishCommentEditOptions.onPublishingStateChange = (publishingState) => {
348
+ setPublishingState(publishingState);
349
+ };
350
+ const publishCommentEdit = () => __awaiter(this, void 0, void 0, function* () {
351
+ try {
352
+ yield accountsActions.publishCommentEdit(publishCommentEditOptions, accountName);
353
+ }
354
+ catch (e) {
355
+ setErrors((errors) => [...errors, e]);
356
+ originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(e);
357
+ }
358
+ });
359
+ return useMemo(() => ({
360
+ challenge,
361
+ challengeVerification,
362
+ publishCommentEdit,
363
+ publishChallengeAnswers: publishChallengeAnswers || publishChallengeAnswersNotReady,
364
+ state: publishingState || initialState,
365
+ error: errors[errors.length - 1],
366
+ errors,
367
+ }), [
368
+ publishingState,
369
+ initialState,
370
+ errors,
371
+ challenge,
372
+ challengeVerification,
373
+ options,
374
+ accountName,
375
+ publishChallengeAnswers,
376
+ ]);
377
+ }
378
+ export function usePublishCommentModeration(options) {
379
+ assert(!options || typeof options === "object", `usePublishCommentModeration options argument '${options}' not an object`);
380
+ const _a = options || {}, { accountName } = _a, publishCommentModerationOptions = __rest(_a, ["accountName"]);
381
+ const accountsActions = useAccountsStore((state) => state.accountsActions);
382
+ const accountId = useAccountId(accountName);
383
+ const [errors, setErrors] = useState([]);
384
+ const [publishingState, setPublishingState] = useState();
385
+ const [challenge, setChallenge] = useState();
386
+ const [challengeVerification, setChallengeVerification] = useState();
387
+ const [publishChallengeAnswers, setPublishChallengeAnswers] = useState();
388
+ let initialState = "initializing";
389
+ // before the accountId and options is defined, nothing can happen
390
+ if (accountId && options) {
391
+ initialState = "ready";
392
+ }
393
+ // define onError if not defined
394
+ const originalOnError = publishCommentModerationOptions.onError;
395
+ const onError = (error) => __awaiter(this, void 0, void 0, function* () {
396
+ setErrors((errors) => [...errors, error]);
397
+ originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(error);
398
+ });
399
+ publishCommentModerationOptions.onError = onError;
400
+ // define onChallenge if not defined
401
+ const originalOnChallenge = publishCommentModerationOptions.onChallenge;
402
+ const onChallenge = (challenge, commentModeration) => __awaiter(this, void 0, void 0, function* () {
403
+ // cannot set a function directly with setState
404
+ setPublishChallengeAnswers(() => commentModeration === null || commentModeration === void 0 ? void 0 : commentModeration.publishChallengeAnswers.bind(commentModeration));
405
+ setChallenge(challenge);
406
+ originalOnChallenge === null || originalOnChallenge === void 0 ? void 0 : originalOnChallenge(challenge, commentModeration);
407
+ });
408
+ publishCommentModerationOptions.onChallenge = onChallenge;
409
+ // define onChallengeVerification if not defined
410
+ const originalOnChallengeVerification = publishCommentModerationOptions.onChallengeVerification;
411
+ const onChallengeVerification = (challengeVerification, commentModeration) => __awaiter(this, void 0, void 0, function* () {
412
+ setChallengeVerification(challengeVerification);
413
+ originalOnChallengeVerification === null || originalOnChallengeVerification === void 0 ? void 0 : originalOnChallengeVerification(challengeVerification, commentModeration);
414
+ });
415
+ publishCommentModerationOptions.onChallengeVerification = onChallengeVerification;
416
+ // change state on publishing state change
417
+ publishCommentModerationOptions.onPublishingStateChange = (publishingState) => {
418
+ setPublishingState(publishingState);
419
+ };
420
+ const publishCommentModeration = () => __awaiter(this, void 0, void 0, function* () {
421
+ try {
422
+ yield accountsActions.publishCommentModeration(publishCommentModerationOptions, accountName);
423
+ }
424
+ catch (e) {
425
+ setErrors((errors) => [...errors, e]);
426
+ originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(e);
427
+ }
428
+ });
429
+ return useMemo(() => ({
430
+ challenge,
431
+ challengeVerification,
432
+ publishCommentModeration,
433
+ publishChallengeAnswers: publishChallengeAnswers || publishChallengeAnswersNotReady,
434
+ state: publishingState || initialState,
435
+ error: errors[errors.length - 1],
436
+ errors,
437
+ }), [
438
+ publishingState,
439
+ initialState,
440
+ errors,
441
+ challenge,
442
+ challengeVerification,
443
+ options,
444
+ accountName,
445
+ publishChallengeAnswers,
446
+ ]);
447
+ }
448
+ export function usePublishCommunityEdit(options) {
449
+ assert(!options || typeof options === "object", `usePublishCommunityEdit options argument '${options}' not an object`);
450
+ const _a = options || {}, { accountName, communityAddress } = _a, publishCommunityEditOptions = __rest(_a, ["accountName", "communityAddress"]);
451
+ const accountsActions = useAccountsStore((state) => state.accountsActions);
452
+ const accountId = useAccountId(accountName);
453
+ const [errors, setErrors] = useState([]);
454
+ const [publishingState, setPublishingState] = useState();
455
+ const [challenge, setChallenge] = useState();
456
+ const [challengeVerification, setChallengeVerification] = useState();
457
+ const [publishChallengeAnswers, setPublishChallengeAnswers] = useState();
458
+ let initialState = "initializing";
459
+ // before the accountId and options is defined, nothing can happen
460
+ if (accountId && communityAddress) {
461
+ initialState = "ready";
462
+ }
463
+ // define onError if not defined
464
+ const originalOnError = publishCommunityEditOptions.onError;
465
+ const onError = (error) => __awaiter(this, void 0, void 0, function* () {
466
+ setErrors((errors) => [...errors, error]);
467
+ originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(error);
468
+ });
469
+ publishCommunityEditOptions.onError = onError;
470
+ // define onChallenge if not defined
471
+ const originalOnChallenge = publishCommunityEditOptions.onChallenge;
472
+ const onChallenge = (challenge, communityEdit) => __awaiter(this, void 0, void 0, function* () {
473
+ // cannot set a function directly with setState
474
+ setPublishChallengeAnswers(() => communityEdit === null || communityEdit === void 0 ? void 0 : communityEdit.publishChallengeAnswers.bind(communityEdit));
475
+ setChallenge(challenge);
476
+ originalOnChallenge === null || originalOnChallenge === void 0 ? void 0 : originalOnChallenge(challenge, communityEdit);
477
+ });
478
+ publishCommunityEditOptions.onChallenge = onChallenge;
479
+ // define onChallengeVerification if not defined
480
+ const originalOnChallengeVerification = publishCommunityEditOptions.onChallengeVerification;
481
+ const onChallengeVerification = (challengeVerification, communityEdit) => __awaiter(this, void 0, void 0, function* () {
482
+ setChallengeVerification(challengeVerification);
483
+ originalOnChallengeVerification === null || originalOnChallengeVerification === void 0 ? void 0 : originalOnChallengeVerification(challengeVerification, communityEdit);
484
+ });
485
+ publishCommunityEditOptions.onChallengeVerification = onChallengeVerification;
486
+ // change state on publishing state change
487
+ publishCommunityEditOptions.onPublishingStateChange = (publishingState) => {
488
+ setPublishingState(publishingState);
489
+ };
490
+ const publishCommunityEdit = () => __awaiter(this, void 0, void 0, function* () {
491
+ try {
492
+ yield accountsActions.publishCommunityEdit(communityAddress, publishCommunityEditOptions, accountName);
493
+ }
494
+ catch (e) {
495
+ setErrors((errors) => [...errors, e]);
496
+ originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(e);
497
+ }
498
+ });
499
+ return useMemo(() => ({
500
+ challenge,
501
+ challengeVerification,
502
+ publishCommunityEdit,
503
+ publishChallengeAnswers: publishChallengeAnswers || publishChallengeAnswersNotReady,
504
+ state: publishingState || initialState,
505
+ error: errors[errors.length - 1],
506
+ errors,
507
+ }), [
508
+ publishingState,
509
+ initialState,
510
+ errors,
511
+ challenge,
512
+ challengeVerification,
513
+ options,
514
+ accountName,
515
+ publishChallengeAnswers,
516
+ ]);
517
+ }
518
+ export function useCreateCommunity(options) {
519
+ assert(!options || typeof options === "object", `useCreateCommunity options argument '${options}' not an object`);
520
+ const _a = options || {}, { accountName, onError } = _a, createCommunityOptions = __rest(_a, ["accountName", "onError"]);
521
+ const accountId = useAccountId(accountName);
522
+ const accountsActions = useAccountsStore((state) => state.accountsActions);
523
+ const [errors, setErrors] = useState([]);
524
+ const [state, setState] = useState();
525
+ const [createdCommunity, setCreatedCommunity] = useState();
526
+ let initialState = "initializing";
527
+ // before the accountId and options is defined, nothing can happen
528
+ if (accountId && options) {
529
+ initialState = "ready";
530
+ }
531
+ const createCommunity = () => __awaiter(this, void 0, void 0, function* () {
532
+ try {
533
+ setState("creating");
534
+ const createdCommunity = yield accountsActions.createCommunity(createCommunityOptions, accountName);
535
+ setCreatedCommunity(createdCommunity);
536
+ setState("succeeded");
537
+ }
538
+ catch (e) {
539
+ setErrors((errors) => [...errors, e]);
540
+ setState("failed");
541
+ onError === null || onError === void 0 ? void 0 : onError(e);
542
+ }
543
+ });
544
+ return useMemo(() => ({
545
+ createdCommunity,
546
+ createCommunity,
547
+ state: state || initialState,
548
+ error: errors[errors.length - 1],
549
+ errors,
550
+ }), [state, errors, createdCommunity, options, accountName]);
551
+ }
552
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../src/hooks/actions/actions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,qCAAqC,CAAC,CAAC;AAC1D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEvD,iFAAiF;AACj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C;IACH,CAAC,CAAA,CAAC;IAEF,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,gBAAgB;QAChB,eAAe;QACf,KAAK,EAAE,KAAK,IAAI,YAAY;QAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,MAAM;KACP,CAAC,EACF,CAAC,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,CAAC,CACxD,CAAC;AACJ,CAAC","sourcesContent":["import { useMemo, useRef, useState } from \"react\";\nimport type { Dispatch, SetStateAction } from \"react\";\nimport useAccountsStore from \"../../stores/accounts\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:actions:hooks\");\nimport assert from \"assert\";\nimport { useAccount, useAccountId } from \"../accounts\";\n\n/** Wraps a callback to no-op when guard returns false. Exported for coverage. */\nexport function withGuardActive<T extends (...args: any[]) => void>(\n guardActive: () => boolean,\n fn: T,\n): T {\n return ((...args: Parameters<T>) => {\n if (!guardActive()) return;\n return fn(...args);\n }) as T;\n}\n\nconst noop = () => {};\n\n/** For usePublishComment: when abandoned, catch should no-op. Exported for coverage. */\nexport function handlePublishErrorWhenAbandoned(\n activeRequestIdRef: { current: number | undefined },\n requestId: number,\n error: Error,\n setErrors: Dispatch<SetStateAction<Error[]>>,\n onError?: (e: Error) => void,\n): void {\n if (activeRequestIdRef.current !== requestId) return;\n setErrors((errors) => [...errors, error]);\n (onError ?? noop)(error);\n}\n\n/** For usePublishVote catch. Exported for coverage. */\nexport function handlePublishVoteError(\n error: Error,\n setErrors: Dispatch<SetStateAction<Error[]>>,\n onError?: (e: Error) => void,\n): void {\n setErrors((errors) => [...errors, error]);\n (onError ?? noop)(error);\n}\nimport type {\n UseSubscribeOptions,\n UseSubscribeResult,\n UsePublishCommentOptions,\n UsePublishCommentResult,\n UseBlockOptions,\n UseBlockResult,\n UseCreateCommunityOptions,\n UseCreateCommunityResult,\n UsePublishVoteOptions,\n UsePublishVoteResult,\n UsePublishCommentEditOptions,\n UsePublishCommentEditResult,\n UsePublishCommentModerationOptions,\n UsePublishCommentModerationResult,\n UsePublishCommunityEditOptions,\n UsePublishCommunityEditResult,\n Challenge,\n ChallengeVerification,\n Comment,\n CommentEdit,\n CommentModeration,\n CommunityEdit,\n Vote,\n Community,\n} from \"../../types\";\n\ntype PublishChallengeAnswers = (challengeAnswers: string[]) => Promise<void>;\nconst publishChallengeAnswersNotReady: PublishChallengeAnswers = async (challengeAnswers) => {\n throw Error(\n `can't call publishChallengeAnswers() before result.challenge is defined (before the challenge message is received)`,\n );\n};\n\nexport function useSubscribe(options?: UseSubscribeOptions): UseSubscribeResult {\n assert(\n !options || typeof options === \"object\",\n `useSubscribe options argument '${options}' not an object`,\n );\n const { communityAddress, accountName, onError } = options || {};\n const account = useAccount({ accountName });\n const accountsActions = useAccountsStore((state) => state.accountsActions);\n const [errors, setErrors] = useState<Error[]>([]);\n let state = \"initializing\";\n let subscribed: boolean | undefined;\n\n // before the account and communityAddress is defined, nothing can happen\n if (account && communityAddress) {\n state = \"ready\";\n subscribed = Boolean(account.subscriptions?.includes(communityAddress));\n }\n\n const subscribe = async () => {\n try {\n await accountsActions.subscribe(communityAddress, accountName);\n } catch (e: any) {\n setErrors((errors) => [...errors, e]);\n onError?.(e);\n }\n };\n\n const unsubscribe = async () => {\n try {\n await accountsActions.unsubscribe(communityAddress, accountName);\n } catch (e: any) {\n setErrors((errors) => [...errors, e]);\n onError?.(e);\n }\n };\n\n return useMemo(\n () => ({\n subscribed,\n subscribe,\n unsubscribe,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [state, subscribed, errors, communityAddress, accountName],\n );\n}\n\nexport function useBlock(options?: UseBlockOptions): UseBlockResult {\n assert(\n !options || typeof options === \"object\",\n `useBlock options argument '${options}' not an object`,\n );\n const { address, cid, accountName, onError } = options || {};\n if (address && cid) {\n throw Error(\n `can't useBlock with both an address '${address}' and cid '${cid}' argument at the same time`,\n );\n }\n const account = useAccount({ accountName });\n const accountsActions = useAccountsStore((state) => state.accountsActions);\n const [errors, setErrors] = useState<Error[]>([]);\n let state = \"initializing\";\n let blocked: boolean | undefined;\n\n // before the account and address is defined, nothing can happen\n if (account && (address || cid)) {\n state = \"ready\";\n if (address) {\n blocked = Boolean(account.blockedAddresses[address]);\n }\n if (cid) {\n blocked = Boolean(account.blockedCids[cid]);\n }\n }\n\n const block = async () => {\n try {\n if (cid) {\n await accountsActions.blockCid(cid, accountName);\n } else {\n await accountsActions.blockAddress(address, accountName);\n }\n } catch (e: any) {\n setErrors((errors) => [...errors, e]);\n onError?.(e);\n }\n };\n\n const unblock = async () => {\n try {\n if (cid) {\n await accountsActions.unblockCid(cid, accountName);\n } else {\n await accountsActions.unblockAddress(address, accountName);\n }\n } catch (e: any) {\n setErrors((errors) => [...errors, e]);\n onError?.(e);\n }\n };\n\n return useMemo(\n () => ({\n blocked,\n block,\n unblock,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [state, blocked, errors, address, accountName],\n );\n}\n\nexport function usePublishComment(options?: UsePublishCommentOptions): UsePublishCommentResult {\n assert(\n !options || typeof options === \"object\",\n `usePublishComment options argument '${options}' not an object`,\n );\n const { accountName, ...publishCommentOptions } = options || {};\n const accountsActions = useAccountsStore((state) => state.accountsActions);\n const accountId = useAccountId(accountName);\n const [errors, setErrors] = useState<Error[]>([]);\n const [publishingState, setPublishingState] = useState<string>();\n const [index, setIndex] = useState<number>();\n const [challenge, setChallenge] = useState<Challenge>();\n const [challengeVerification, setChallengeVerification] = useState<ChallengeVerification>();\n const [publishChallengeAnswers, setPublishChallengeAnswers] = useState<PublishChallengeAnswers>();\n const indexRef = useRef<number | undefined>(undefined);\n const publishRequestIdRef = useRef(0);\n const activePublishRequestIdRef = useRef<number | undefined>(undefined);\n const guardActive = () => activePublishRequestIdRef.current !== undefined;\n publishCommentOptions._onPendingCommentIndex = withGuardActive(\n guardActive,\n (pendingIndex: number) => {\n indexRef.current = pendingIndex;\n setIndex(pendingIndex);\n },\n );\n\n let initialState = \"initializing\";\n if (accountId && options) initialState = \"ready\";\n\n const originalOnError = publishCommentOptions.onError;\n const onError = async (error: Error) => {\n setErrors((errors) => [...errors, error]);\n (originalOnError ?? noop)(error);\n };\n publishCommentOptions.onError = onError;\n\n const originalOnChallenge = publishCommentOptions.onChallenge;\n publishCommentOptions.onChallenge = withGuardActive(\n guardActive,\n async (challenge: Challenge, comment: Comment) => {\n setPublishChallengeAnswers(() => comment?.publishChallengeAnswers.bind(comment));\n setChallenge(challenge);\n (originalOnChallenge ?? noop)(challenge, comment);\n },\n );\n\n const originalOnChallengeVerification = publishCommentOptions.onChallengeVerification;\n publishCommentOptions.onChallengeVerification = withGuardActive(\n guardActive,\n async (challengeVerification: ChallengeVerification, comment: Comment) => {\n setChallengeVerification(challengeVerification);\n (originalOnChallengeVerification ?? noop)(challengeVerification, comment);\n },\n );\n\n publishCommentOptions.onPublishingStateChange = withGuardActive(\n guardActive,\n (publishingState: string) => setPublishingState(publishingState),\n );\n\n const publishComment = async () => {\n const requestId = publishRequestIdRef.current + 1;\n publishRequestIdRef.current = requestId;\n activePublishRequestIdRef.current = requestId;\n try {\n const { index } = await accountsActions.publishComment(publishCommentOptions, accountName);\n if (activePublishRequestIdRef.current !== requestId) {\n return;\n }\n indexRef.current = index;\n setIndex(index);\n } catch (e: any) {\n handlePublishErrorWhenAbandoned(\n activePublishRequestIdRef,\n requestId,\n e,\n setErrors,\n originalOnError,\n );\n }\n };\n\n const abandonPublish = async () => {\n activePublishRequestIdRef.current = undefined;\n const idx = indexRef.current;\n if (idx !== undefined) {\n await accountsActions.deleteComment(idx, accountName);\n }\n indexRef.current = undefined;\n setChallenge(undefined);\n setChallengeVerification(undefined);\n setPublishChallengeAnswers(undefined);\n setIndex(undefined);\n setPublishingState(undefined);\n };\n\n return useMemo(\n () => ({\n index,\n challenge,\n challengeVerification,\n publishComment,\n abandonPublish,\n publishChallengeAnswers: publishChallengeAnswers || publishChallengeAnswersNotReady,\n state: publishingState || initialState,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n publishingState,\n initialState,\n errors,\n index,\n challenge,\n challengeVerification,\n options,\n accountName,\n publishChallengeAnswers,\n ],\n );\n}\n\nexport function usePublishVote(options?: UsePublishVoteOptions): UsePublishVoteResult {\n assert(\n !options || typeof options === \"object\",\n `usePublishVote options argument '${options}' not an object`,\n );\n const { accountName, ...publishVoteOptions } = options || {};\n const accountsActions = useAccountsStore((state) => state.accountsActions);\n const accountId = useAccountId(accountName);\n const [errors, setErrors] = useState<Error[]>([]);\n const [publishingState, setPublishingState] = useState<string>();\n const [challenge, setChallenge] = useState<Challenge>();\n const [challengeVerification, setChallengeVerification] = useState<ChallengeVerification>();\n const [publishChallengeAnswers, setPublishChallengeAnswers] = useState<PublishChallengeAnswers>();\n\n let initialState = \"initializing\";\n // before the accountId and options is defined, nothing can happen\n if (accountId && options) {\n initialState = \"ready\";\n }\n\n // define onError if not defined\n const originalOnError = publishVoteOptions.onError;\n const onError = async (error: Error) => {\n setErrors((errors) => [...errors, error]);\n originalOnError?.(error);\n };\n publishVoteOptions.onError = onError;\n\n // define onChallenge if not defined\n const originalOnChallenge = publishVoteOptions.onChallenge;\n const onChallenge = async (challenge: Challenge, vote: Vote) => {\n setPublishChallengeAnswers(() => vote?.publishChallengeAnswers.bind(vote));\n setChallenge(challenge);\n (originalOnChallenge ?? (() => {}))(challenge, vote);\n };\n publishVoteOptions.onChallenge = onChallenge;\n\n const originalOnChallengeVerification = publishVoteOptions.onChallengeVerification;\n const onChallengeVerification = async (\n challengeVerification: ChallengeVerification,\n vote: Vote,\n ) => {\n setChallengeVerification(challengeVerification);\n (originalOnChallengeVerification ?? noop)(challengeVerification, vote);\n };\n publishVoteOptions.onChallengeVerification = onChallengeVerification;\n\n // change state on publishing state change\n publishVoteOptions.onPublishingStateChange = (publishingState: string) => {\n setPublishingState(publishingState);\n };\n\n const publishVote = async () => {\n try {\n await accountsActions.publishVote(publishVoteOptions, accountName);\n } catch (e: any) {\n handlePublishVoteError(e, setErrors, originalOnError);\n }\n };\n\n return useMemo(\n () => ({\n challenge,\n challengeVerification,\n publishVote,\n publishChallengeAnswers: publishChallengeAnswers || publishChallengeAnswersNotReady,\n state: publishingState || initialState,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n publishingState,\n initialState,\n errors,\n challenge,\n challengeVerification,\n options,\n accountName,\n publishChallengeAnswers,\n ],\n );\n}\n\nexport function usePublishCommentEdit(\n options?: UsePublishCommentEditOptions,\n): UsePublishCommentEditResult {\n assert(\n !options || typeof options === \"object\",\n `usePublishCommentEdit options argument '${options}' not an object`,\n );\n const { accountName, ...publishCommentEditOptions } = options || {};\n const accountsActions = useAccountsStore((state) => state.accountsActions);\n const accountId = useAccountId(accountName);\n const [errors, setErrors] = useState<Error[]>([]);\n const [publishingState, setPublishingState] = useState<string>();\n const [challenge, setChallenge] = useState<Challenge>();\n const [challengeVerification, setChallengeVerification] = useState<ChallengeVerification>();\n const [publishChallengeAnswers, setPublishChallengeAnswers] = useState<PublishChallengeAnswers>();\n\n let initialState = \"initializing\";\n // before the accountId and options is defined, nothing can happen\n if (accountId && options) {\n initialState = \"ready\";\n }\n\n // define onError if not defined\n const originalOnError = publishCommentEditOptions.onError;\n const onError = async (error: Error) => {\n setErrors((errors) => [...errors, error]);\n originalOnError?.(error);\n };\n publishCommentEditOptions.onError = onError;\n\n // define onChallenge if not defined\n const originalOnChallenge = publishCommentEditOptions.onChallenge;\n const onChallenge = async (challenge: Challenge, commentEdit: CommentEdit) => {\n // cannot set a function directly with setState\n setPublishChallengeAnswers(() => commentEdit?.publishChallengeAnswers.bind(commentEdit));\n setChallenge(challenge);\n originalOnChallenge?.(challenge, commentEdit);\n };\n publishCommentEditOptions.onChallenge = onChallenge;\n\n // define onChallengeVerification if not defined\n const originalOnChallengeVerification = publishCommentEditOptions.onChallengeVerification;\n const onChallengeVerification = async (\n challengeVerification: ChallengeVerification,\n commentEdit: CommentEdit,\n ) => {\n setChallengeVerification(challengeVerification);\n originalOnChallengeVerification?.(challengeVerification, commentEdit);\n };\n publishCommentEditOptions.onChallengeVerification = onChallengeVerification;\n\n // change state on publishing state change\n publishCommentEditOptions.onPublishingStateChange = (publishingState: string) => {\n setPublishingState(publishingState);\n };\n\n const publishCommentEdit = async () => {\n try {\n await accountsActions.publishCommentEdit(publishCommentEditOptions, accountName);\n } catch (e: any) {\n setErrors((errors) => [...errors, e]);\n originalOnError?.(e);\n }\n };\n\n return useMemo(\n () => ({\n challenge,\n challengeVerification,\n publishCommentEdit,\n publishChallengeAnswers: publishChallengeAnswers || publishChallengeAnswersNotReady,\n state: publishingState || initialState,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n publishingState,\n initialState,\n errors,\n challenge,\n challengeVerification,\n options,\n accountName,\n publishChallengeAnswers,\n ],\n );\n}\n\nexport function usePublishCommentModeration(\n options?: UsePublishCommentModerationOptions,\n): UsePublishCommentModerationResult {\n assert(\n !options || typeof options === \"object\",\n `usePublishCommentModeration options argument '${options}' not an object`,\n );\n const { accountName, ...publishCommentModerationOptions } = options || {};\n const accountsActions = useAccountsStore((state) => state.accountsActions);\n const accountId = useAccountId(accountName);\n const [errors, setErrors] = useState<Error[]>([]);\n const [publishingState, setPublishingState] = useState<string>();\n const [challenge, setChallenge] = useState<Challenge>();\n const [challengeVerification, setChallengeVerification] = useState<ChallengeVerification>();\n const [publishChallengeAnswers, setPublishChallengeAnswers] = useState<PublishChallengeAnswers>();\n\n let initialState = \"initializing\";\n // before the accountId and options is defined, nothing can happen\n if (accountId && options) {\n initialState = \"ready\";\n }\n\n // define onError if not defined\n const originalOnError = publishCommentModerationOptions.onError;\n const onError = async (error: Error) => {\n setErrors((errors) => [...errors, error]);\n originalOnError?.(error);\n };\n publishCommentModerationOptions.onError = onError;\n\n // define onChallenge if not defined\n const originalOnChallenge = publishCommentModerationOptions.onChallenge;\n const onChallenge = async (challenge: Challenge, commentModeration: CommentModeration) => {\n // cannot set a function directly with setState\n setPublishChallengeAnswers(() =>\n commentModeration?.publishChallengeAnswers.bind(commentModeration),\n );\n setChallenge(challenge);\n originalOnChallenge?.(challenge, commentModeration);\n };\n publishCommentModerationOptions.onChallenge = onChallenge;\n\n // define onChallengeVerification if not defined\n const originalOnChallengeVerification = publishCommentModerationOptions.onChallengeVerification;\n const onChallengeVerification = async (\n challengeVerification: ChallengeVerification,\n commentModeration: CommentModeration,\n ) => {\n setChallengeVerification(challengeVerification);\n originalOnChallengeVerification?.(challengeVerification, commentModeration);\n };\n publishCommentModerationOptions.onChallengeVerification = onChallengeVerification;\n\n // change state on publishing state change\n publishCommentModerationOptions.onPublishingStateChange = (publishingState: string) => {\n setPublishingState(publishingState);\n };\n\n const publishCommentModeration = async () => {\n try {\n await accountsActions.publishCommentModeration(publishCommentModerationOptions, accountName);\n } catch (e: any) {\n setErrors((errors) => [...errors, e]);\n originalOnError?.(e);\n }\n };\n\n return useMemo(\n () => ({\n challenge,\n challengeVerification,\n publishCommentModeration,\n publishChallengeAnswers: publishChallengeAnswers || publishChallengeAnswersNotReady,\n state: publishingState || initialState,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n publishingState,\n initialState,\n errors,\n challenge,\n challengeVerification,\n options,\n accountName,\n publishChallengeAnswers,\n ],\n );\n}\n\nexport function usePublishCommunityEdit(\n options?: UsePublishCommunityEditOptions,\n): UsePublishCommunityEditResult {\n assert(\n !options || typeof options === \"object\",\n `usePublishCommunityEdit options argument '${options}' not an object`,\n );\n const { accountName, communityAddress, ...publishCommunityEditOptions } = options || {};\n const accountsActions = useAccountsStore((state) => state.accountsActions);\n const accountId = useAccountId(accountName);\n const [errors, setErrors] = useState<Error[]>([]);\n const [publishingState, setPublishingState] = useState<string>();\n const [challenge, setChallenge] = useState<Challenge>();\n const [challengeVerification, setChallengeVerification] = useState<ChallengeVerification>();\n const [publishChallengeAnswers, setPublishChallengeAnswers] = useState<PublishChallengeAnswers>();\n\n let initialState = \"initializing\";\n // before the accountId and options is defined, nothing can happen\n if (accountId && communityAddress) {\n initialState = \"ready\";\n }\n\n // define onError if not defined\n const originalOnError = publishCommunityEditOptions.onError;\n const onError = async (error: Error) => {\n setErrors((errors) => [...errors, error]);\n originalOnError?.(error);\n };\n publishCommunityEditOptions.onError = onError;\n\n // define onChallenge if not defined\n const originalOnChallenge = publishCommunityEditOptions.onChallenge;\n const onChallenge = async (challenge: Challenge, communityEdit: CommunityEdit) => {\n // cannot set a function directly with setState\n setPublishChallengeAnswers(() => communityEdit?.publishChallengeAnswers.bind(communityEdit));\n setChallenge(challenge);\n originalOnChallenge?.(challenge, communityEdit);\n };\n publishCommunityEditOptions.onChallenge = onChallenge;\n\n // define onChallengeVerification if not defined\n const originalOnChallengeVerification = publishCommunityEditOptions.onChallengeVerification;\n const onChallengeVerification = async (\n challengeVerification: ChallengeVerification,\n communityEdit: CommunityEdit,\n ) => {\n setChallengeVerification(challengeVerification);\n originalOnChallengeVerification?.(challengeVerification, communityEdit);\n };\n publishCommunityEditOptions.onChallengeVerification = onChallengeVerification;\n\n // change state on publishing state change\n publishCommunityEditOptions.onPublishingStateChange = (publishingState: string) => {\n setPublishingState(publishingState);\n };\n\n const publishCommunityEdit = async () => {\n try {\n await accountsActions.publishCommunityEdit(\n communityAddress,\n publishCommunityEditOptions,\n accountName,\n );\n } catch (e: any) {\n setErrors((errors) => [...errors, e]);\n originalOnError?.(e);\n }\n };\n\n return useMemo(\n () => ({\n challenge,\n challengeVerification,\n publishCommunityEdit,\n publishChallengeAnswers: publishChallengeAnswers || publishChallengeAnswersNotReady,\n state: publishingState || initialState,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n publishingState,\n initialState,\n errors,\n challenge,\n challengeVerification,\n options,\n accountName,\n publishChallengeAnswers,\n ],\n );\n}\n\nexport function useCreateCommunity(options?: UseCreateCommunityOptions): UseCreateCommunityResult {\n assert(\n !options || typeof options === \"object\",\n `useCreateCommunity options argument '${options}' not an object`,\n );\n const { accountName, onError, ...createCommunityOptions } = options || {};\n const accountId = useAccountId(accountName);\n const accountsActions = useAccountsStore((state) => state.accountsActions);\n const [errors, setErrors] = useState<Error[]>([]);\n const [state, setState] = useState<string>();\n const [createdCommunity, setCreatedCommunity] = useState<Community>();\n\n let initialState = \"initializing\";\n // before the accountId and options is defined, nothing can happen\n if (accountId && options) {\n initialState = \"ready\";\n }\n\n const createCommunity = async () => {\n try {\n setState(\"creating\");\n const createdCommunity = await accountsActions.createCommunity(\n createCommunityOptions,\n accountName,\n );\n setCreatedCommunity(createdCommunity);\n setState(\"succeeded\");\n } catch (e: any) {\n setErrors((errors) => [...errors, e]);\n setState(\"failed\");\n onError?.(e);\n }\n };\n\n return useMemo(\n () => ({\n createdCommunity,\n createCommunity,\n state: state || initialState,\n error: errors[errors.length - 1],\n errors,\n }),\n [state, errors, createdCommunity, options, accountName],\n );\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./actions.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/actions/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./actions.js";
2
+ //# sourceMappingURL=index.js.map