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