diff --git a/src/components/modals/CaptchaModal.jsx b/src/components/modals/CaptchaModal.jsx index 4efc02a4..e7f03027 100644 --- a/src/components/modals/CaptchaModal.jsx +++ b/src/components/modals/CaptchaModal.jsx @@ -11,7 +11,11 @@ const CaptchaModal = () => { pendingComment, selectedStyle, setCaptchaResponse, + isAuthorDelete, setIsAuthorDelete, + isAuthorEdit, setIsAuthorEdit, isCaptchaOpen, setIsCaptchaOpen, + isModEdit, setIsModEdit, + resolveCaptchaPromise, selectedShortCid, } = useGeneralStore(state => state); @@ -22,8 +26,18 @@ const CaptchaModal = () => { const responseRef = useRef(); const nodeRef = useRef(null); + + useEffect(() => { + if (!isCaptchaOpen) { + setIsAuthorDelete(false); + setIsAuthorEdit(false); + setIsModEdit(false); + } + }, [isCaptchaOpen, setIsAuthorDelete, setIsAuthorEdit, setIsModEdit]); - useEffect(() => { + + + useEffect(() => { const handleResize = () => setIsMobile(window.innerWidth <= 480); window.addEventListener('resize', handleResize); @@ -50,6 +64,7 @@ const CaptchaModal = () => { } }, [challengesArray]); + const handleKeyDown = (event) => { if (event.key === "Enter") { event.preventDefault(); @@ -57,10 +72,11 @@ const CaptchaModal = () => { } }; + const handleReturnKeyDown = () => { - submitCaptcha((response) => { - useGeneralStore.getState().setCaptchaResponse(response); - useGeneralStore.getState().resolveCaptchaPromise(response); + submitCaptcha((response) => { + setCaptchaResponse(response); + resolveCaptchaPromise(response); }); }; @@ -72,13 +88,15 @@ const CaptchaModal = () => { if (callback) { callback(responseRef.current.value); } -}; + }; return ( setIsCaptchaOpen(false)} + onRequestClose={() => { + submitCaptcha(); + setIsCaptchaOpen(false);}} contentLabel="Captcha Modal" shouldCloseOnEsc={false} shouldCloseOnOverlayClick={false} @@ -87,7 +105,10 @@ const CaptchaModal = () => {
- {pendingComment.parentCid ? + {isModEdit ? "Challenge for Moderator Action" : + isAuthorEdit ? "Challenge for Editing Post" : + isAuthorDelete ? "Challenge for Deleting Post" : + pendingComment.parentCid ? ("Challenges for Reply to c/" + selectedShortCid) : "Challenges for New Thread"}