diff --git a/src/components/CaptchaModal.jsx b/src/components/CaptchaModal.jsx index fb9ac4e4..d2e85e9c 100644 --- a/src/components/CaptchaModal.jsx +++ b/src/components/CaptchaModal.jsx @@ -40,11 +40,27 @@ const CaptchaModal = () => { const handleKeyDown = (event) => { if (event.key === "Enter") { event.preventDefault(); - setCaptchaResponse(responseRef.current.value); - setIsCaptchaOpen(false); + submitCaptcha(); } }; + const handleReturnKeyDown = () => { + submitCaptcha((response) => { + useGeneralStore.getState().setCaptchaResponse(response); + useGeneralStore.getState().resolveCaptchaPromise(response); + }); + }; + + + const submitCaptcha = (callback) => { + setCaptchaResponse(responseRef.current.value); + setIsCaptchaOpen(false); + if (callback) { + callback(responseRef.current.value); + } + }; + + return ( { if (currentChallengeIndex + 1 < totalChallenges) { setCurrentChallengeIndex((currentChallengeIndex + 1) % totalChallenges); } else { - setCaptchaResponse(responseRef.current.value); - setIsCaptchaOpen(false); + handleReturnKeyDown(); } }} > diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index 933820d8..3504bdc7 100644 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -32,6 +32,7 @@ const Board = () => { setIsCaptchaOpen, isSettingsOpen, setIsSettingsOpen, setPendingComment, + setResolveCaptchaPromise, selectedAddress, setSelectedAddress, setSelectedParentCid, setSelectedShortCid, @@ -201,6 +202,8 @@ const Board = () => { setCaptchaResponse(''); document.addEventListener('keydown', handleKeyDown); + + useGeneralStore.getState().setResolveCaptchaPromise(resolve); }; challengeImg.onerror = () => { diff --git a/src/hooks/stores/useGeneralStore.js b/src/hooks/stores/useGeneralStore.js index 64598115..d05dec3b 100644 --- a/src/hooks/stores/useGeneralStore.js +++ b/src/hooks/stores/useGeneralStore.js @@ -31,6 +31,9 @@ const useGeneralStore = create((set) => ({ publishedComment: '', setPublishedComment: (comment) => set({ publishedComment: comment }), + + resolveCaptchaPromise: null, + setResolveCaptchaPromise: (resolve) => set({ resolveCaptchaPromise: resolve }), selectedAddress: '', setSelectedAddress: (address) => set({ selectedAddress: address }),