fix posting logic

This commit is contained in:
plebbitor
2023-04-22 17:37:53 +02:00
parent b9ee9894df
commit a0d35dfd61
3 changed files with 15 additions and 41 deletions
+5 -18
View File
@@ -31,8 +31,6 @@ const ReplyModal = ({ isOpen, closeModal }) => {
const commentRef = useRef(); const commentRef = useRef();
const linkRef = useRef(); const linkRef = useRef();
const onChallengeVerificationRef = useRef();
const [errorMessage, setErrorMessage] = useState(null); const [errorMessage, setErrorMessage] = useState(null);
const [successMessage] = useState(null); const [successMessage] = useState(null);
useError(errorMessage, [errorMessage]); useError(errorMessage, [errorMessage]);
@@ -68,7 +66,7 @@ const ReplyModal = ({ isOpen, closeModal }) => {
const [publishCommentOptions, setPublishCommentOptions] = useState({ const [publishCommentOptions, setPublishCommentOptions] = useState({
subplebbitAddress: selectedAddress, subplebbitAddress: selectedAddress,
onChallenge, onChallenge,
onChallengeVerification: onChallengeVerificationRef.current, onChallengeVerification,
onError: (error) => { onError: (error) => {
setErrorMessage(error); setErrorMessage(error);
}, },
@@ -84,9 +82,6 @@ const ReplyModal = ({ isOpen, closeModal }) => {
localStorage.setItem("toastMessage", `Comment pending with index ${index}.`); localStorage.setItem("toastMessage", `Comment pending with index ${index}.`);
} }
}, [index]); }, [index]);
onChallengeVerificationRef.current = onChallengeVerification;
const resetFields = () => { const resetFields = () => {
@@ -96,15 +91,6 @@ const ReplyModal = ({ isOpen, closeModal }) => {
}; };
useEffect(() => {
setPublishCommentOptions((prevPublishCommentOptions) => ({
...prevPublishCommentOptions,
subplebbitAddress: selectedAddress,
onChallengeVerification: onChallengeVerificationRef.current,
}));
}, [selectedAddress]);
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
event.preventDefault(); event.preventDefault();
@@ -143,9 +129,10 @@ const ReplyModal = ({ isOpen, closeModal }) => {
challengeImg.onload = () => { challengeImg.onload = () => {
setIsCaptchaOpen(true); setIsCaptchaOpen(true);
const handleKeyDown = (event) => { const handleKeyDown = async (event) => {
if (event.key === 'Enter') { if (event.key === 'Enter') {
resolve(captchaResponse); const currentCaptchaResponse = captchaResponse;
resolve(currentCaptchaResponse);
setIsCaptchaOpen(false); setIsCaptchaOpen(false);
document.removeEventListener('keydown', handleKeyDown); document.removeEventListener('keydown', handleKeyDown);
event.preventDefault(); event.preventDefault();
@@ -155,7 +142,7 @@ const ReplyModal = ({ isOpen, closeModal }) => {
setCaptchaResponse(''); setCaptchaResponse('');
document.addEventListener('keydown', handleKeyDown); document.addEventListener('keydown', handleKeyDown);
useGeneralStore.getState().setResolveCaptchaPromise(resolve); setResolveCaptchaPromise(resolve);
}; };
challengeImg.onerror = () => { challengeImg.onerror = () => {
+2 -2
View File
@@ -20,7 +20,7 @@ import useSuccess from '../../hooks/useSuccess';
const Catalog = () => { const Catalog = () => {
const { const {
setCaptchaResponse, captchaResponse, setCaptchaResponse,
setChallengesArray, setChallengesArray,
defaultSubplebbits, defaultSubplebbits,
setIsCaptchaOpen, setIsCaptchaOpen,
@@ -175,7 +175,7 @@ const Catalog = () => {
const handleKeyDown = async (event) => { const handleKeyDown = async (event) => {
if (event.key === 'Enter') { if (event.key === 'Enter') {
const currentCaptchaResponse = useGeneralStore.getState().captchaResponse; const currentCaptchaResponse = captchaResponse;
resolve(currentCaptchaResponse); resolve(currentCaptchaResponse);
setIsCaptchaOpen(false); setIsCaptchaOpen(false);
document.removeEventListener('keydown', handleKeyDown); document.removeEventListener('keydown', handleKeyDown);
+8 -21
View File
@@ -47,8 +47,6 @@ const Thread = () => {
const commentRef = useRef(); const commentRef = useRef();
const linkRef = useRef(); const linkRef = useRef();
const onChallengeVerificationRef = useRef();
const [isReplyOpen, setIsReplyOpen] = useState(false); const [isReplyOpen, setIsReplyOpen] = useState(false);
const navigate = useNavigate(); const navigate = useNavigate();
const [prevScrollPos, setPrevScrollPos] = useState(0); const [prevScrollPos, setPrevScrollPos] = useState(0);
@@ -121,7 +119,7 @@ const Thread = () => {
const [publishCommentOptions, setPublishCommentOptions] = useState({ const [publishCommentOptions, setPublishCommentOptions] = useState({
subplebbitAddress: selectedAddress, subplebbitAddress: selectedAddress,
onChallenge, onChallenge,
onChallengeVerification: onChallengeVerificationRef.current, onChallengeVerification,
onError: (error) => { onError: (error) => {
setErrorMessage(error); setErrorMessage(error);
}, },
@@ -137,9 +135,6 @@ const Thread = () => {
setSuccessMessage('Comment pending with index ' + index + '.'); setSuccessMessage('Comment pending with index ' + index + '.');
} }
}, [index]); }, [index]);
onChallengeVerificationRef.current = onChallengeVerification;
const resetFields = () => { const resetFields = () => {
@@ -149,15 +144,6 @@ const Thread = () => {
}; };
useEffect(() => {
setPublishCommentOptions((prevPublishCommentOptions) => ({
...prevPublishCommentOptions,
subplebbitAddress: selectedAddress,
onChallengeVerification: onChallengeVerificationRef.current,
}));
}, [selectedAddress]);
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
event.preventDefault(); event.preventDefault();
@@ -195,9 +181,10 @@ const Thread = () => {
challengeImg.onload = () => { challengeImg.onload = () => {
setIsCaptchaOpen(true); setIsCaptchaOpen(true);
const handleKeyDown = (event) => { const handleKeyDown = async (event) => {
if (event.key === 'Enter') { if (event.key === 'Enter') {
resolve(captchaResponse); const currentCaptchaResponse = captchaResponse;
resolve(currentCaptchaResponse);
setIsCaptchaOpen(false); setIsCaptchaOpen(false);
document.removeEventListener('keydown', handleKeyDown); document.removeEventListener('keydown', handleKeyDown);
event.preventDefault(); event.preventDefault();
@@ -562,10 +549,10 @@ const Thread = () => {
) : ( ) : (
<span key={`mob-ha-${index}`} <span key={`mob-ha-${index}`}
data-tooltip-id="tooltip" data-tooltip-id="tooltip"
data-tooltip-content={account.author.address} data-tooltip-content={account?.author?.address}
data-tooltip-place="top" data-tooltip-place="top"
> >
{account.author.address.slice(0, 10) + "(...)"} {account?.author?.address.slice(0, 10) + "(...)"}
</span> </span>
) )
} }
@@ -795,10 +782,10 @@ const Thread = () => {
) : ( ) : (
<span key={`mob-ha-${index}`} <span key={`mob-ha-${index}`}
data-tooltip-id="tooltip" data-tooltip-id="tooltip"
data-tooltip-content={account.author.address} data-tooltip-content={account?.author?.address}
data-tooltip-place="top" data-tooltip-place="top"
> >
{account.author.address.slice(0, 6) + "(...)"} {account?.author?.address.slice(0, 6) + "(...)"}
</span> </span>
) )
} }