mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(challenge flow): abandon publish immediately on modal close
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user