@bitsocial/bitsocial-react-hooks 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +2 -0
- package/dist/hooks/accounts/accounts.d.ts.map +1 -1
- package/dist/hooks/accounts/accounts.js +35 -10
- package/dist/hooks/accounts/accounts.js.map +1 -1
- package/dist/hooks/actions/actions.d.ts.map +1 -1
- package/dist/hooks/actions/actions.js +166 -93
- package/dist/hooks/actions/actions.js.map +1 -1
- package/dist/hooks/authors/author-avatars.d.ts +2 -2
- package/dist/hooks/authors/author-avatars.d.ts.map +1 -1
- package/dist/hooks/authors/author-avatars.js +48 -20
- package/dist/hooks/authors/author-avatars.js.map +1 -1
- package/dist/hooks/authors/authors.d.ts.map +1 -1
- package/dist/hooks/authors/authors.js +68 -22
- package/dist/hooks/authors/authors.js.map +1 -1
- package/dist/hooks/comments.d.ts.map +1 -1
- package/dist/hooks/comments.js +54 -3
- package/dist/hooks/comments.js.map +1 -1
- package/dist/hooks/communities.d.ts.map +1 -1
- package/dist/hooks/communities.js +41 -12
- package/dist/hooks/communities.js.map +1 -1
- package/dist/hooks/feeds/feeds.d.ts.map +1 -1
- package/dist/hooks/feeds/feeds.js +47 -11
- package/dist/hooks/feeds/feeds.js.map +1 -1
- package/dist/hooks/pkc-rpc.d.ts.map +1 -1
- package/dist/hooks/pkc-rpc.js +33 -20
- package/dist/hooks/pkc-rpc.js.map +1 -1
- package/dist/hooks/replies.d.ts.map +1 -1
- package/dist/hooks/replies.js +30 -4
- package/dist/hooks/replies.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/debug-utils.d.ts +4 -4
- package/dist/lib/debug-utils.d.ts.map +1 -1
- package/dist/lib/debug-utils.js +56 -11
- package/dist/lib/debug-utils.js.map +1 -1
- package/dist/lib/localforage-lru/localforage-lru.d.ts +1 -0
- package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -1
- package/dist/lib/localforage-lru/localforage-lru.js +48 -10
- package/dist/lib/localforage-lru/localforage-lru.js.map +1 -1
- package/dist/lib/page-sorts.d.ts +6 -0
- package/dist/lib/page-sorts.d.ts.map +1 -1
- package/dist/lib/page-sorts.js +45 -9
- package/dist/lib/page-sorts.js.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.js +5 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -1
- package/dist/lib/utils/utils.d.ts.map +1 -1
- package/dist/lib/utils/utils.js +24 -16
- package/dist/lib/utils/utils.js.map +1 -1
- package/dist/lib/validator.d.ts +1 -1
- package/dist/lib/validator.d.ts.map +1 -1
- package/dist/lib/validator.js +7 -1
- package/dist/lib/validator.js.map +1 -1
- package/dist/stores/accounts/account-generator.d.ts +1 -0
- package/dist/stores/accounts/account-generator.d.ts.map +1 -1
- package/dist/stores/accounts/account-generator.js +12 -4
- package/dist/stores/accounts/account-generator.js.map +1 -1
- package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions-internal.js +24 -6
- package/dist/stores/accounts/accounts-actions-internal.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +339 -98
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/accounts/accounts-database.d.ts +1 -0
- package/dist/stores/accounts/accounts-database.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-database.js +82 -15
- package/dist/stores/accounts/accounts-database.js.map +1 -1
- package/dist/stores/accounts/accounts-store.d.ts +1 -1
- package/dist/stores/accounts/accounts-store.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-store.js +1 -1
- package/dist/stores/accounts/accounts-store.js.map +1 -1
- package/dist/stores/accounts/utils.d.ts +5 -1
- package/dist/stores/accounts/utils.d.ts.map +1 -1
- package/dist/stores/accounts/utils.js +58 -0
- package/dist/stores/accounts/utils.js.map +1 -1
- package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -1
- package/dist/stores/authors-comments/authors-comments-store.js +39 -12
- package/dist/stores/authors-comments/authors-comments-store.js.map +1 -1
- package/dist/stores/comments/comments-store.d.ts +2 -0
- package/dist/stores/comments/comments-store.d.ts.map +1 -1
- package/dist/stores/comments/comments-store.js +170 -21
- package/dist/stores/comments/comments-store.js.map +1 -1
- package/dist/stores/communities/communities-store.d.ts.map +1 -1
- package/dist/stores/communities/communities-store.js +27 -7
- package/dist/stores/communities/communities-store.js.map +1 -1
- package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -1
- package/dist/stores/communities-pages/communities-pages-store.js +131 -12
- package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
- package/dist/stores/feeds/feed-sorter.d.ts +5 -2
- package/dist/stores/feeds/feed-sorter.d.ts.map +1 -1
- package/dist/stores/feeds/feed-sorter.js +15 -4
- package/dist/stores/feeds/feed-sorter.js.map +1 -1
- package/dist/stores/feeds/feeds-store.d.ts +3 -0
- package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
- package/dist/stores/feeds/feeds-store.js +36 -26
- package/dist/stores/feeds/feeds-store.js.map +1 -1
- package/dist/stores/feeds/utils.d.ts +16 -0
- package/dist/stores/feeds/utils.d.ts.map +1 -1
- package/dist/stores/feeds/utils.js +82 -26
- package/dist/stores/feeds/utils.js.map +1 -1
- package/dist/stores/replies/replies-store.d.ts.map +1 -1
- package/dist/stores/replies/replies-store.js +32 -6
- package/dist/stores/replies/replies-store.js.map +1 -1
- package/dist/stores/replies/utils.d.ts +3 -2
- package/dist/stores/replies/utils.d.ts.map +1 -1
- package/dist/stores/replies/utils.js +38 -5
- package/dist/stores/replies/utils.js.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.js +68 -13
- package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
- package/dist/types.d.ts +11 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -40,6 +40,11 @@ export function handlePublishErrorWhenAbandoned(activeRequestIdRef, requestId, e
|
|
|
40
40
|
setErrors((errors) => [...errors, error]);
|
|
41
41
|
(onError !== null && onError !== void 0 ? onError : noop)(error);
|
|
42
42
|
}
|
|
43
|
+
/** Clears what the previous publication left in a publish hook's result. */
|
|
44
|
+
const clearPublicationResult = (...setters) => {
|
|
45
|
+
for (const setState of setters)
|
|
46
|
+
setState(undefined);
|
|
47
|
+
};
|
|
43
48
|
/** For usePublishVote catch. Exported for coverage. */
|
|
44
49
|
export function handlePublishVoteError(error, setErrors, onError) {
|
|
45
50
|
setErrors((errors) => [...errors, error]);
|
|
@@ -197,12 +202,12 @@ export function usePublishComment(options) {
|
|
|
197
202
|
const [challenge, setChallenge] = useState();
|
|
198
203
|
const [challengeVerification, setChallengeVerification] = useState();
|
|
199
204
|
const [publishChallengeAnswers, setPublishChallengeAnswers] = useState();
|
|
200
|
-
const indexRef = useRef(undefined);
|
|
201
205
|
const publishRequestIdRef = useRef(0);
|
|
206
|
+
// the latest publication, until it is abandoned or the store rejects it. Only its events write the
|
|
207
|
+
// hook state, and abandonPublish() abandons it.
|
|
202
208
|
const activePublishRequestIdRef = useRef(undefined);
|
|
203
|
-
const
|
|
209
|
+
const abandonActivePublishRef = useRef(() => __awaiter(this, void 0, void 0, function* () { }));
|
|
204
210
|
const mountedRef = useRef(true);
|
|
205
|
-
const guardActiveHook = () => mountedRef.current && activePublishRequestIdRef.current !== undefined;
|
|
206
211
|
useEffect(() => {
|
|
207
212
|
mountedRef.current = true;
|
|
208
213
|
return () => {
|
|
@@ -212,116 +217,122 @@ export function usePublishComment(options) {
|
|
|
212
217
|
let initialState = "initializing";
|
|
213
218
|
if (accountId && options)
|
|
214
219
|
initialState = "ready";
|
|
215
|
-
const
|
|
216
|
-
const onError = (error) => __awaiter(this, void 0, void 0, function* () {
|
|
217
|
-
if (activePublishRequestIdRef.current === undefined)
|
|
218
|
-
return;
|
|
219
|
-
if (mountedRef.current) {
|
|
220
|
-
setErrors((errors) => [...errors, error]);
|
|
221
|
-
}
|
|
222
|
-
(originalOnError !== null && originalOnError !== void 0 ? originalOnError : noop)(error);
|
|
223
|
-
});
|
|
224
|
-
publishCommentOptions.onError = onError;
|
|
225
|
-
const originalOnChallenge = publishCommentOptions.onChallenge;
|
|
226
|
-
publishCommentOptions.onChallenge = (challenge, comment) => __awaiter(this, void 0, void 0, function* () {
|
|
227
|
-
if (activePublishRequestIdRef.current === undefined)
|
|
228
|
-
return;
|
|
229
|
-
if (mountedRef.current) {
|
|
230
|
-
setPublishChallengeAnswers(() => comment === null || comment === void 0 ? void 0 : comment.publishChallengeAnswers.bind(comment));
|
|
231
|
-
setChallenge(challenge);
|
|
232
|
-
}
|
|
233
|
-
(originalOnChallenge !== null && originalOnChallenge !== void 0 ? originalOnChallenge : noop)(challenge, comment);
|
|
234
|
-
});
|
|
235
|
-
const originalOnChallengeVerification = publishCommentOptions.onChallengeVerification;
|
|
236
|
-
publishCommentOptions.onChallengeVerification = (challengeVerification, comment) => __awaiter(this, void 0, void 0, function* () {
|
|
237
|
-
if (activePublishRequestIdRef.current === undefined)
|
|
238
|
-
return;
|
|
239
|
-
if (mountedRef.current) {
|
|
240
|
-
setChallengeVerification(challengeVerification);
|
|
241
|
-
}
|
|
242
|
-
(originalOnChallengeVerification !== null && originalOnChallengeVerification !== void 0 ? originalOnChallengeVerification : noop)(challengeVerification, comment);
|
|
243
|
-
});
|
|
244
|
-
publishCommentOptions.onPublishingStateChange = withGuardActive(guardActiveHook, (publishingState) => setPublishingState(publishingState));
|
|
220
|
+
const resetPublishState = () => clearPublicationResult(setChallenge, setChallengeVerification, setPublishChallengeAnswers, setIndex, setPublishingState);
|
|
245
221
|
const publishComment = () => __awaiter(this, void 0, void 0, function* () {
|
|
246
222
|
const requestId = publishRequestIdRef.current + 1;
|
|
247
223
|
publishRequestIdRef.current = requestId;
|
|
248
224
|
activePublishRequestIdRef.current = requestId;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
225
|
+
const isActive = () => activePublishRequestIdRef.current === requestId;
|
|
226
|
+
const updatesHookState = () => mountedRef.current && isActive();
|
|
227
|
+
if (mountedRef.current) {
|
|
228
|
+
resetPublishState();
|
|
229
|
+
setErrors([]);
|
|
230
|
+
}
|
|
231
|
+
// once abandoned, the publication's late events reach neither the hook state nor the callbacks
|
|
232
|
+
let abandoned = false;
|
|
233
|
+
let settled = false;
|
|
234
|
+
// given by the store with the pending comment index, bound to the account that publishes and to
|
|
235
|
+
// the index the comment has now
|
|
236
|
+
let abandonPendingComment;
|
|
237
|
+
let deferredAbandon;
|
|
238
|
+
const resolveDeferredAbandon = () => {
|
|
239
|
+
deferredAbandon === null || deferredAbandon === void 0 ? void 0 : deferredAbandon.resolve();
|
|
240
|
+
deferredAbandon = undefined;
|
|
241
|
+
};
|
|
242
|
+
const abandon = () => __awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
if (abandoned)
|
|
244
|
+
return;
|
|
245
|
+
abandoned = true;
|
|
246
|
+
if (isActive()) {
|
|
247
|
+
activePublishRequestIdRef.current = undefined;
|
|
248
|
+
if (mountedRef.current)
|
|
249
|
+
resetPublishState();
|
|
250
|
+
}
|
|
251
|
+
if (abandonPendingComment) {
|
|
252
|
+
yield abandonPendingComment();
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (settled)
|
|
256
|
+
return;
|
|
257
|
+
// abandon the comment once the store reports it, or resolve if the store never does
|
|
258
|
+
yield new Promise((resolve, reject) => {
|
|
259
|
+
deferredAbandon = { resolve, reject };
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
abandonActivePublishRef.current = abandon;
|
|
263
|
+
const { onError: originalOnError, onChallenge: originalOnChallenge, onChallengeVerification: originalOnChallengeVerification, onPendingComment: originalOnPendingComment, } = publishCommentOptions;
|
|
264
|
+
const activePublishCommentOptions = Object.assign(Object.assign({}, publishCommentOptions), { onError: (error) => __awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
if (abandoned)
|
|
266
|
+
return;
|
|
267
|
+
if (updatesHookState()) {
|
|
268
|
+
setErrors((errors) => [...errors, error]);
|
|
269
|
+
}
|
|
270
|
+
(originalOnError !== null && originalOnError !== void 0 ? originalOnError : noop)(error);
|
|
271
|
+
}), onChallenge: (challenge, comment) => __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
if (abandoned)
|
|
259
273
|
return;
|
|
274
|
+
if (updatesHookState()) {
|
|
275
|
+
setPublishChallengeAnswers(() => comment === null || comment === void 0 ? void 0 : comment.publishChallengeAnswers.bind(comment));
|
|
276
|
+
setChallenge(challenge);
|
|
277
|
+
// an automatic republish's challenge replaces the previous attempt's failed verification
|
|
278
|
+
setChallengeVerification(undefined);
|
|
260
279
|
}
|
|
261
|
-
|
|
280
|
+
(originalOnChallenge !== null && originalOnChallenge !== void 0 ? originalOnChallenge : noop)(challenge, comment, abandon);
|
|
281
|
+
}), onChallengeVerification: (challengeVerification, comment) => __awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
if (abandoned)
|
|
262
283
|
return;
|
|
284
|
+
if (updatesHookState()) {
|
|
285
|
+
setChallengeVerification(challengeVerification);
|
|
263
286
|
}
|
|
264
|
-
|
|
265
|
-
|
|
287
|
+
(originalOnChallengeVerification !== null && originalOnChallengeVerification !== void 0 ? originalOnChallengeVerification : noop)(challengeVerification, comment);
|
|
288
|
+
}), onPublishingStateChange: withGuardActive(updatesHookState, (publishingState) => setPublishingState(publishingState)),
|
|
289
|
+
// called once the pending comment is stored, and again when a deletion shifts its index
|
|
290
|
+
_onPendingCommentIndex: (pendingIndex, _pendingComment, abandonComment) => {
|
|
291
|
+
abandonPendingComment = abandonComment;
|
|
292
|
+
if (deferredAbandon) {
|
|
293
|
+
const { resolve, reject } = deferredAbandon;
|
|
294
|
+
deferredAbandon = undefined;
|
|
295
|
+
void abandonComment().then(resolve, reject);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (updatesHookState()) {
|
|
266
299
|
setIndex(pendingIndex);
|
|
267
300
|
}
|
|
268
|
-
}, onPendingComment: withGuardActive(
|
|
301
|
+
}, onPendingComment: withGuardActive(isActive, (pendingIndex, pendingComment) => originalOnPendingComment === null || originalOnPendingComment === void 0 ? void 0 : originalOnPendingComment(pendingIndex, pendingComment)) });
|
|
269
302
|
try {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
indexRef.current = index;
|
|
275
|
-
if (mountedRef.current) {
|
|
276
|
-
setIndex(index);
|
|
277
|
-
}
|
|
303
|
+
yield accountsActions.publishComment(activePublishCommentOptions, accountName);
|
|
304
|
+
settled = true;
|
|
305
|
+
// the comment was deleted before the store reported it, so there is nothing left to abandon
|
|
306
|
+
resolveDeferredAbandon();
|
|
278
307
|
}
|
|
279
308
|
catch (e) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
deferredAbandonsRef.current.delete(requestId);
|
|
283
|
-
deferredAbandon.resolve();
|
|
284
|
-
}
|
|
309
|
+
settled = true;
|
|
310
|
+
resolveDeferredAbandon();
|
|
285
311
|
try {
|
|
286
|
-
if (!mountedRef.current &&
|
|
312
|
+
if (!mountedRef.current && isActive()) {
|
|
287
313
|
(originalOnError !== null && originalOnError !== void 0 ? originalOnError : noop)(e);
|
|
288
314
|
}
|
|
289
315
|
else {
|
|
316
|
+
if (isActive()) {
|
|
317
|
+
setPublishingState("failed");
|
|
318
|
+
}
|
|
290
319
|
handlePublishErrorWhenAbandoned(activePublishRequestIdRef, requestId, e, setErrors, originalOnError);
|
|
291
320
|
}
|
|
292
321
|
}
|
|
293
322
|
finally {
|
|
294
|
-
if (
|
|
323
|
+
if (isActive()) {
|
|
295
324
|
activePublishRequestIdRef.current = undefined;
|
|
296
325
|
}
|
|
297
326
|
}
|
|
298
327
|
}
|
|
299
328
|
});
|
|
300
329
|
const abandonPublish = () => __awaiter(this, void 0, void 0, function* () {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const idx = indexRef.current;
|
|
304
|
-
indexRef.current = undefined;
|
|
305
|
-
if (mountedRef.current) {
|
|
306
|
-
setChallenge(undefined);
|
|
307
|
-
setChallengeVerification(undefined);
|
|
308
|
-
setPublishChallengeAnswers(undefined);
|
|
309
|
-
setIndex(undefined);
|
|
310
|
-
setPublishingState(undefined);
|
|
311
|
-
}
|
|
312
|
-
if (idx !== undefined) {
|
|
313
|
-
yield accountsActions.deleteComment(idx, accountName);
|
|
330
|
+
if (activePublishRequestIdRef.current !== undefined) {
|
|
331
|
+
yield abandonActivePublishRef.current();
|
|
314
332
|
return;
|
|
315
333
|
}
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
let reject;
|
|
319
|
-
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
320
|
-
resolve = resolvePromise;
|
|
321
|
-
reject = rejectPromise;
|
|
322
|
-
});
|
|
323
|
-
deferredAbandonsRef.current.set(requestId, { promise, resolve, reject });
|
|
324
|
-
yield promise;
|
|
334
|
+
if (mountedRef.current) {
|
|
335
|
+
resetPublishState();
|
|
325
336
|
}
|
|
326
337
|
});
|
|
327
338
|
return useMemo(() => ({
|
|
@@ -361,6 +372,8 @@ export function usePublishVote(options) {
|
|
|
361
372
|
// the cleared hook state nor leak into the next publication
|
|
362
373
|
const publishVoteRequestIdRef = useRef(0);
|
|
363
374
|
const activePublishVoteRequestIdRef = useRef(undefined);
|
|
375
|
+
// given by the store as publishVote() starts, it abandons the vote in the account that publishes it
|
|
376
|
+
const abandonActiveVoteRef = useRef(undefined);
|
|
364
377
|
let initialState = "initializing";
|
|
365
378
|
// before the accountId and options is defined, nothing can happen
|
|
366
379
|
if (accountId && options) {
|
|
@@ -378,6 +391,8 @@ export function usePublishVote(options) {
|
|
|
378
391
|
const onChallenge = (challenge, vote) => __awaiter(this, void 0, void 0, function* () {
|
|
379
392
|
setPublishChallengeAnswers(() => vote === null || vote === void 0 ? void 0 : vote.publishChallengeAnswers.bind(vote));
|
|
380
393
|
setChallenge(challenge);
|
|
394
|
+
// an automatic republish's challenge replaces the previous attempt's failed verification
|
|
395
|
+
setChallengeVerification(undefined);
|
|
381
396
|
(originalOnChallenge !== null && originalOnChallenge !== void 0 ? originalOnChallenge : (() => { }))(challenge, vote);
|
|
382
397
|
});
|
|
383
398
|
publishVoteOptions.onChallenge = onChallenge;
|
|
@@ -395,7 +410,10 @@ export function usePublishVote(options) {
|
|
|
395
410
|
const requestId = publishVoteRequestIdRef.current + 1;
|
|
396
411
|
publishVoteRequestIdRef.current = requestId;
|
|
397
412
|
activePublishVoteRequestIdRef.current = requestId;
|
|
413
|
+
abandonActiveVoteRef.current = undefined;
|
|
398
414
|
const isActiveRequest = () => activePublishVoteRequestIdRef.current === requestId;
|
|
415
|
+
clearPublicationResult(setChallenge, setChallengeVerification, setPublishChallengeAnswers, setPublishingState);
|
|
416
|
+
setErrors([]);
|
|
399
417
|
const activePublishVoteOptions = Object.assign(Object.assign({}, publishVoteOptions), { onChallenge: (challenge, vote) => {
|
|
400
418
|
if (isActiveRequest())
|
|
401
419
|
onChallenge(challenge, vote);
|
|
@@ -405,23 +423,39 @@ export function usePublishVote(options) {
|
|
|
405
423
|
}, onPublishingStateChange: (publishingState) => {
|
|
406
424
|
if (isActiveRequest())
|
|
407
425
|
setPublishingState(publishingState);
|
|
426
|
+
},
|
|
427
|
+
// an earlier or abandoned vote's error still reaches the app's onError, but not the result
|
|
428
|
+
onError: (error) => {
|
|
429
|
+
if (isActiveRequest())
|
|
430
|
+
onError(error);
|
|
431
|
+
else
|
|
432
|
+
originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(error);
|
|
433
|
+
}, _onVotePublishSession: (abandonVote) => {
|
|
434
|
+
if (isActiveRequest())
|
|
435
|
+
abandonActiveVoteRef.current = abandonVote;
|
|
408
436
|
} });
|
|
409
437
|
try {
|
|
410
438
|
yield accountsActions.publishVote(activePublishVoteOptions, accountName);
|
|
411
439
|
}
|
|
412
440
|
catch (e) {
|
|
413
|
-
|
|
441
|
+
if (isActiveRequest()) {
|
|
442
|
+
setPublishingState("failed");
|
|
443
|
+
handlePublishVoteError(e, setErrors, originalOnError);
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(e);
|
|
447
|
+
}
|
|
414
448
|
}
|
|
415
449
|
});
|
|
416
450
|
const abandonPublish = () => __awaiter(this, void 0, void 0, function* () {
|
|
451
|
+
const abandonVote = abandonActiveVoteRef.current;
|
|
417
452
|
activePublishVoteRequestIdRef.current = undefined;
|
|
453
|
+
abandonActiveVoteRef.current = undefined;
|
|
418
454
|
setChallenge(undefined);
|
|
419
455
|
setChallengeVerification(undefined);
|
|
420
456
|
setPublishChallengeAnswers(undefined);
|
|
421
457
|
setPublishingState(undefined);
|
|
422
|
-
|
|
423
|
-
return;
|
|
424
|
-
yield accountsActions.abandonVote(publishVoteOptions.commentCid, accountName);
|
|
458
|
+
yield (abandonVote === null || abandonVote === void 0 ? void 0 : abandonVote());
|
|
425
459
|
});
|
|
426
460
|
return useMemo(() => ({
|
|
427
461
|
challenge,
|
|
@@ -458,6 +492,8 @@ export function usePublishCommentEdit(options) {
|
|
|
458
492
|
if (accountId && options) {
|
|
459
493
|
initialState = "ready";
|
|
460
494
|
}
|
|
495
|
+
// the latest publishCommentEdit() call owns the result
|
|
496
|
+
const publishRequestIdRef = useRef(0);
|
|
461
497
|
// define onError if not defined
|
|
462
498
|
const originalOnError = publishCommentEditOptions.onError;
|
|
463
499
|
const onError = (error) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -471,6 +507,8 @@ export function usePublishCommentEdit(options) {
|
|
|
471
507
|
// cannot set a function directly with setState
|
|
472
508
|
setPublishChallengeAnswers(() => commentEdit === null || commentEdit === void 0 ? void 0 : commentEdit.publishChallengeAnswers.bind(commentEdit));
|
|
473
509
|
setChallenge(challenge);
|
|
510
|
+
// an automatic republish's challenge replaces the previous attempt's failed verification
|
|
511
|
+
setChallengeVerification(undefined);
|
|
474
512
|
originalOnChallenge === null || originalOnChallenge === void 0 ? void 0 : originalOnChallenge(challenge, commentEdit);
|
|
475
513
|
});
|
|
476
514
|
publishCommentEditOptions.onChallenge = onChallenge;
|
|
@@ -486,11 +524,17 @@ export function usePublishCommentEdit(options) {
|
|
|
486
524
|
setPublishingState(publishingState);
|
|
487
525
|
};
|
|
488
526
|
const publishCommentEdit = () => __awaiter(this, void 0, void 0, function* () {
|
|
527
|
+
const requestId = ++publishRequestIdRef.current;
|
|
528
|
+
clearPublicationResult(setChallenge, setChallengeVerification, setPublishChallengeAnswers, setPublishingState);
|
|
529
|
+
setErrors([]);
|
|
489
530
|
try {
|
|
490
531
|
yield accountsActions.publishCommentEdit(publishCommentEditOptions, accountName);
|
|
491
532
|
}
|
|
492
533
|
catch (e) {
|
|
493
|
-
|
|
534
|
+
if (publishRequestIdRef.current === requestId) {
|
|
535
|
+
setPublishingState("failed");
|
|
536
|
+
setErrors((errors) => [...errors, e]);
|
|
537
|
+
}
|
|
494
538
|
originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(e);
|
|
495
539
|
}
|
|
496
540
|
});
|
|
@@ -528,6 +572,8 @@ export function usePublishCommentModeration(options) {
|
|
|
528
572
|
if (accountId && options) {
|
|
529
573
|
initialState = "ready";
|
|
530
574
|
}
|
|
575
|
+
// the latest publishCommentModeration() call owns the result
|
|
576
|
+
const publishRequestIdRef = useRef(0);
|
|
531
577
|
// define onError if not defined
|
|
532
578
|
const originalOnError = publishCommentModerationOptions.onError;
|
|
533
579
|
const onError = (error) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -541,6 +587,8 @@ export function usePublishCommentModeration(options) {
|
|
|
541
587
|
// cannot set a function directly with setState
|
|
542
588
|
setPublishChallengeAnswers(() => commentModeration === null || commentModeration === void 0 ? void 0 : commentModeration.publishChallengeAnswers.bind(commentModeration));
|
|
543
589
|
setChallenge(challenge);
|
|
590
|
+
// an automatic republish's challenge replaces the previous attempt's failed verification
|
|
591
|
+
setChallengeVerification(undefined);
|
|
544
592
|
originalOnChallenge === null || originalOnChallenge === void 0 ? void 0 : originalOnChallenge(challenge, commentModeration);
|
|
545
593
|
});
|
|
546
594
|
publishCommentModerationOptions.onChallenge = onChallenge;
|
|
@@ -556,11 +604,17 @@ export function usePublishCommentModeration(options) {
|
|
|
556
604
|
setPublishingState(publishingState);
|
|
557
605
|
};
|
|
558
606
|
const publishCommentModeration = () => __awaiter(this, void 0, void 0, function* () {
|
|
607
|
+
const requestId = ++publishRequestIdRef.current;
|
|
608
|
+
clearPublicationResult(setChallenge, setChallengeVerification, setPublishChallengeAnswers, setPublishingState);
|
|
609
|
+
setErrors([]);
|
|
559
610
|
try {
|
|
560
611
|
yield accountsActions.publishCommentModeration(publishCommentModerationOptions, accountName);
|
|
561
612
|
}
|
|
562
613
|
catch (e) {
|
|
563
|
-
|
|
614
|
+
if (publishRequestIdRef.current === requestId) {
|
|
615
|
+
setPublishingState("failed");
|
|
616
|
+
setErrors((errors) => [...errors, e]);
|
|
617
|
+
}
|
|
564
618
|
originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(e);
|
|
565
619
|
}
|
|
566
620
|
});
|
|
@@ -598,6 +652,8 @@ export function usePublishCommunityEdit(options) {
|
|
|
598
652
|
if (accountId && communityAddress) {
|
|
599
653
|
initialState = "ready";
|
|
600
654
|
}
|
|
655
|
+
// the latest publishCommunityEdit() call owns the result
|
|
656
|
+
const publishRequestIdRef = useRef(0);
|
|
601
657
|
// define onError if not defined
|
|
602
658
|
const originalOnError = publishCommunityEditOptions.onError;
|
|
603
659
|
const onError = (error) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -611,6 +667,8 @@ export function usePublishCommunityEdit(options) {
|
|
|
611
667
|
// cannot set a function directly with setState
|
|
612
668
|
setPublishChallengeAnswers(() => communityEdit === null || communityEdit === void 0 ? void 0 : communityEdit.publishChallengeAnswers.bind(communityEdit));
|
|
613
669
|
setChallenge(challenge);
|
|
670
|
+
// an automatic republish's challenge replaces the previous attempt's failed verification
|
|
671
|
+
setChallengeVerification(undefined);
|
|
614
672
|
originalOnChallenge === null || originalOnChallenge === void 0 ? void 0 : originalOnChallenge(challenge, communityEdit);
|
|
615
673
|
});
|
|
616
674
|
publishCommunityEditOptions.onChallenge = onChallenge;
|
|
@@ -626,11 +684,17 @@ export function usePublishCommunityEdit(options) {
|
|
|
626
684
|
setPublishingState(publishingState);
|
|
627
685
|
};
|
|
628
686
|
const publishCommunityEdit = () => __awaiter(this, void 0, void 0, function* () {
|
|
687
|
+
const requestId = ++publishRequestIdRef.current;
|
|
688
|
+
clearPublicationResult(setChallenge, setChallengeVerification, setPublishChallengeAnswers, setPublishingState);
|
|
689
|
+
setErrors([]);
|
|
629
690
|
try {
|
|
630
691
|
yield accountsActions.publishCommunityEdit(communityAddress, publishCommunityEditOptions, accountName);
|
|
631
692
|
}
|
|
632
693
|
catch (e) {
|
|
633
|
-
|
|
694
|
+
if (publishRequestIdRef.current === requestId) {
|
|
695
|
+
setPublishingState("failed");
|
|
696
|
+
setErrors((errors) => [...errors, e]);
|
|
697
|
+
}
|
|
634
698
|
originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(e);
|
|
635
699
|
}
|
|
636
700
|
});
|
|
@@ -704,6 +768,7 @@ export function useExportCommunity(options) {
|
|
|
704
768
|
]);
|
|
705
769
|
const previousExportContextKeyRef = useRef(exportContextKey);
|
|
706
770
|
const exportContextVersionRef = useRef(0);
|
|
771
|
+
const exportRequestIdRef = useRef(0);
|
|
707
772
|
if (previousExportContextKeyRef.current !== exportContextKey) {
|
|
708
773
|
previousExportContextKeyRef.current = exportContextKey;
|
|
709
774
|
exportContextVersionRef.current += 1;
|
|
@@ -717,19 +782,27 @@ export function useExportCommunity(options) {
|
|
|
717
782
|
(exportingContext === null || exportingContext === void 0 ? void 0 : exportingContext.key) === exportContextKey &&
|
|
718
783
|
exportingContext.version === exportContextVersionRef.current;
|
|
719
784
|
const exportCommunity = () => __awaiter(this, void 0, void 0, function* () {
|
|
785
|
+
// only the latest export writes the result, whatever context an earlier one was started in
|
|
786
|
+
const requestId = ++exportRequestIdRef.current;
|
|
720
787
|
try {
|
|
721
788
|
setExportingContext({
|
|
722
789
|
key: exportContextKey,
|
|
723
790
|
version: exportContextVersionRef.current,
|
|
724
791
|
});
|
|
725
792
|
setExportingState("exporting");
|
|
793
|
+
setCommunityExports([]);
|
|
794
|
+
setErrors([]);
|
|
726
795
|
const communityExports = yield accountsActions.exportCommunity(targetCommunityAddresses, exportCommunityOptions, accountName);
|
|
796
|
+
if (exportRequestIdRef.current !== requestId)
|
|
797
|
+
return;
|
|
727
798
|
setCommunityExports(communityExports);
|
|
728
799
|
setExportingState("succeeded");
|
|
729
800
|
}
|
|
730
801
|
catch (e) {
|
|
731
|
-
|
|
732
|
-
|
|
802
|
+
if (exportRequestIdRef.current === requestId) {
|
|
803
|
+
setExportingState("failed");
|
|
804
|
+
setErrors((errors) => [...errors, e]);
|
|
805
|
+
}
|
|
733
806
|
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
734
807
|
}
|
|
735
808
|
});
|