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 resetPublishPostStore = usePublishPostStore((state) => state.resetPublishPostStore);
|
||||||
const addChallenge = useChallengesStore((state) => state.addChallenge);
|
const addChallenge = useChallengesStore((state) => state.addChallenge);
|
||||||
const abandonPublishRef = useRef<(() => Promise<void>) | undefined>();
|
const abandonPublishRef = useRef<(() => Promise<void>) | undefined>();
|
||||||
|
const abandonCurrentPublish = useCallback(async () => {
|
||||||
|
await abandonPublishRef.current?.();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const createBaseOptions = useCallback(() => {
|
const createBaseOptions = useCallback(() => {
|
||||||
const baseOptions: Comment = {
|
const baseOptions: Comment = {
|
||||||
@@ -58,12 +61,10 @@ const usePublishPost = ({ subplebbitAddress }: { subplebbitAddress?: string }) =
|
|||||||
() => ({
|
() => ({
|
||||||
...publishCommentOptions,
|
...publishCommentOptions,
|
||||||
onChallenge: async (...args: any[]) => {
|
onChallenge: async (...args: any[]) => {
|
||||||
addChallenge(args, async () => {
|
addChallenge(args, abandonCurrentPublish);
|
||||||
await abandonPublishRef.current?.();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
[addChallenge, publishCommentOptions],
|
[abandonCurrentPublish, addChallenge, publishCommentOptions],
|
||||||
);
|
);
|
||||||
|
|
||||||
const { index, publishComment, abandonPublish } = usePublishComment(publishOptionsWithAbandon);
|
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 resetPublishReplyStore = usePublishReplyStore((state) => state.resetPublishReplyStore);
|
||||||
const addChallenge = useChallengesStore((state) => state.addChallenge);
|
const addChallenge = useChallengesStore((state) => state.addChallenge);
|
||||||
const abandonPublishRef = useRef<(() => Promise<void>) | undefined>();
|
const abandonPublishRef = useRef<(() => Promise<void>) | undefined>();
|
||||||
|
const abandonCurrentPublish = useCallback(async () => {
|
||||||
|
await abandonPublishRef.current?.();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const createBaseOptions = useCallback(() => {
|
const createBaseOptions = useCallback(() => {
|
||||||
const baseOptions: Comment = {
|
const baseOptions: Comment = {
|
||||||
@@ -66,12 +69,10 @@ const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; sub
|
|||||||
() => ({
|
() => ({
|
||||||
...mergedPublishOptions,
|
...mergedPublishOptions,
|
||||||
onChallenge: async (...args: any[]) => {
|
onChallenge: async (...args: any[]) => {
|
||||||
addChallenge(args, async () => {
|
addChallenge(args, abandonCurrentPublish);
|
||||||
await abandonPublishRef.current?.();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
[addChallenge, mergedPublishOptions],
|
[abandonCurrentPublish, addChallenge, mergedPublishOptions],
|
||||||
);
|
);
|
||||||
|
|
||||||
const { index, publishComment, abandonPublish } = usePublishComment(publishOptionsWithAbandon);
|
const { index, publishComment, abandonPublish } = usePublishComment(publishOptionsWithAbandon);
|
||||||
|
|||||||
@@ -26,12 +26,11 @@ const useChallengesStore = create<State>((set, get) => ({
|
|||||||
},
|
},
|
||||||
abandonCurrentChallenge: async () => {
|
abandonCurrentChallenge: async () => {
|
||||||
const currentChallenge = get().challenges[0];
|
const currentChallenge = get().challenges[0];
|
||||||
|
get().removeChallenge();
|
||||||
try {
|
try {
|
||||||
await currentChallenge?.onAbandon?.();
|
await currentChallenge?.onAbandon?.();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to abandon challenge publication:', error);
|
console.error('Failed to abandon challenge publication:', error);
|
||||||
} finally {
|
|
||||||
get().removeChallenge();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user