fixed CaptchaModal post button

This commit is contained in:
plebbitor
2023-04-22 14:02:20 +02:00
parent 103ff3fa6a
commit 9a6cf2710c
3 changed files with 25 additions and 4 deletions
+19 -4
View File
@@ -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 (
<StyledModal
isOpen={isCaptchaOpen}
@@ -109,8 +125,7 @@ const CaptchaModal = () => {
if (currentChallengeIndex + 1 < totalChallenges) {
setCurrentChallengeIndex((currentChallengeIndex + 1) % totalChallenges);
} else {
setCaptchaResponse(responseRef.current.value);
setIsCaptchaOpen(false);
handleReturnKeyDown();
}
}}
>
+3
View File
@@ -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 = () => {
+3
View File
@@ -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 }),