From 8d0ffd1f742f95a97cc8593578b43fe48236c8f5 Mon Sep 17 00:00:00 2001 From: Tom Date: Fri, 26 May 2023 10:10:51 +0200 Subject: [PATCH] add dynamic challenge modal title --- src/components/modals/CaptchaModal.jsx | 35 ++++++++++++++++++----- src/components/modals/ModerationModal.jsx | 2 ++ src/components/views/Board.jsx | 6 ++++ src/components/views/Catalog.jsx | 6 ++++ src/components/views/Thread.jsx | 10 +++++-- src/hooks/stores/useGeneralStore.js | 9 ++++++ 6 files changed, 59 insertions(+), 9 deletions(-) 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"}