fix(challenge flow): abandon publish immediately on modal close

This commit is contained in:
plebeius
2026-03-05 20:47:49 +08:00
parent 59851a4b01
commit 9cc6876887
3 changed files with 11 additions and 10 deletions
+5 -4
View File
@@ -17,6 +17,9 @@ const usePublishPost = ({ subplebbitAddress }: { subplebbitAddress?: string }) =
const resetPublishPostStore = usePublishPostStore((state) => state.resetPublishPostStore);
const addChallenge = useChallengesStore((state) => state.addChallenge);
const abandonPublishRef = useRef<(() => Promise<void>) | undefined>();
const abandonCurrentPublish = useCallback(async () => {
await abandonPublishRef.current?.();
}, []);
const createBaseOptions = useCallback(() => {
const baseOptions: Comment = {
@@ -58,12 +61,10 @@ const usePublishPost = ({ subplebbitAddress }: { subplebbitAddress?: string }) =
() => ({
...publishCommentOptions,
onChallenge: async (...args: any[]) => {
addChallenge(args, async () => {
await abandonPublishRef.current?.();
});
addChallenge(args, abandonCurrentPublish);
},
}),
[addChallenge, publishCommentOptions],
[abandonCurrentPublish, addChallenge, publishCommentOptions],
);
const { index, publishComment, abandonPublish } = usePublishComment(publishOptionsWithAbandon);
+5 -4
View File
@@ -20,6 +20,9 @@ const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; sub
const resetPublishReplyStore = usePublishReplyStore((state) => state.resetPublishReplyStore);
const addChallenge = useChallengesStore((state) => state.addChallenge);
const abandonPublishRef = useRef<(() => Promise<void>) | undefined>();
const abandonCurrentPublish = useCallback(async () => {
await abandonPublishRef.current?.();
}, []);
const createBaseOptions = useCallback(() => {
const baseOptions: Comment = {
@@ -66,12 +69,10 @@ const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; sub
() => ({
...mergedPublishOptions,
onChallenge: async (...args: any[]) => {
addChallenge(args, async () => {
await abandonPublishRef.current?.();
});
addChallenge(args, abandonCurrentPublish);
},
}),
[addChallenge, mergedPublishOptions],
[abandonCurrentPublish, addChallenge, mergedPublishOptions],
);
const { index, publishComment, abandonPublish } = usePublishComment(publishOptionsWithAbandon);
+1 -2
View File
@@ -26,12 +26,11 @@ const useChallengesStore = create<State>((set, get) => ({
},
abandonCurrentChallenge: async () => {
const currentChallenge = get().challenges[0];
get().removeChallenge();
try {
await currentChallenge?.onAbandon?.();
} catch (error) {
console.error('Failed to abandon challenge publication:', error);
} finally {
get().removeChallenge();
}
},
}));