update posting logic

This commit is contained in:
plebbitor
2023-04-16 11:21:05 +02:00
parent bccfde6572
commit 688fc80bae
6 changed files with 34 additions and 37 deletions
+3
View File
@@ -0,0 +1,3 @@
REACT_APP_PLEBBIT_REACT_HOOKS_MOCK_CONTENT=1
REACT_APP_PLEBBIT_REACT_HOOKS_MOCK_CONTENT_LOADING_TIME=1000
REACT_APP_PLEBBIT_REACT_HOOKS_MOCK_CONTENT_DOUBLE_MEDIA=1
+2 -2
View File
@@ -62,9 +62,9 @@ const CaptchaModal = () => {
<button className="icon" onClick={() => setIsCaptchaOpen(false)} title="close" /> <button className="icon" onClick={() => setIsCaptchaOpen(false)} title="close" />
</div> </div>
<div id="form"> <div id="form">
{pendingComment.displayName ? ( {pendingComment.author?.displayName ? (
<div> <div>
<input id="field" type="text" placeholder={pendingComment.displayName} disabled /> <input id="field" type="text" placeholder={pendingComment.author?.displayName} disabled />
</div> </div>
) : null} ) : null}
{pendingComment.title ? ( {pendingComment.title ? (
+3 -1
View File
@@ -111,7 +111,9 @@ const ReplyModal = ({ isOpen, closeModal }) => {
setPublishCommentOptions((prevPublishCommentOptions) => ({ setPublishCommentOptions((prevPublishCommentOptions) => ({
...prevPublishCommentOptions, ...prevPublishCommentOptions,
displayName: nameRef.current.value || undefined, author: {
displayName: nameRef.current.value || undefined,
},
content: commentRef.current.value || undefined, content: commentRef.current.value || undefined,
link: linkRef.current.value || undefined, link: linkRef.current.value || undefined,
parentCid: selectedParentCid, parentCid: selectedParentCid,
+3 -2
View File
@@ -98,7 +98,6 @@ const Board = () => {
const onChallengeVerification = (challengeVerification) => { const onChallengeVerification = (challengeVerification) => {
if (challengeVerification.challengeSuccess === true) { if (challengeVerification.challengeSuccess === true) {
setSuccessMessage('Challenge success.', {publishedCid: challengeVerification.publication?.cid}); setSuccessMessage('Challenge success.', {publishedCid: challengeVerification.publication?.cid});
console.log("challenge success", challengeVerification.publication?.cid, challengeVerification)
navigate(`/p/${selectedAddress}/c/${challengeVerification.publication?.cid}`); navigate(`/p/${selectedAddress}/c/${challengeVerification.publication?.cid}`);
} }
else if (challengeVerification.challengeSuccess === false) { else if (challengeVerification.challengeSuccess === false) {
@@ -158,7 +157,9 @@ const Board = () => {
setPublishCommentOptions((prevPublishCommentOptions) => ({ setPublishCommentOptions((prevPublishCommentOptions) => ({
...prevPublishCommentOptions, ...prevPublishCommentOptions,
displayName: nameRef.current.value || undefined, author: {
displayName: nameRef.current.value || undefined,
},
title: subjectRef.current.value || undefined, title: subjectRef.current.value || undefined,
content: commentRef.current.value || undefined, content: commentRef.current.value || undefined,
link: linkRef.current.value || undefined, link: linkRef.current.value || undefined,
+13 -22
View File
@@ -19,7 +19,7 @@ import useSuccess from '../../hooks/useSuccess';
const Catalog = () => { const Catalog = () => {
const { const {
captchaResponse, setCaptchaResponse, setCaptchaResponse,
setChallengesArray, setChallengesArray,
defaultSubplebbits, defaultSubplebbits,
setIsCaptchaOpen, setIsCaptchaOpen,
@@ -38,8 +38,6 @@ const Catalog = () => {
const commentRef = useRef(); const commentRef = useRef();
const linkRef = useRef(); const linkRef = useRef();
const onChallengeVerificationRef = useRef();
const navigate = useNavigate(); const navigate = useNavigate();
const [prevScrollPos, setPrevScrollPos] = useState(0); const [prevScrollPos, setPrevScrollPos] = useState(0);
const [visible, setVisible] = useState(true); const [visible, setVisible] = useState(true);
@@ -84,10 +82,12 @@ const Catalog = () => {
const onChallengeVerification = (challengeVerification) => { const onChallengeVerification = (challengeVerification) => {
if (challengeVerification.challengeSuccess === true) { if (challengeVerification.challengeSuccess === true) {
setSuccessMessage('Challenge success.', {publishedCid: challengeVerification.publication?.cid}); setSuccessMessage('Challenge success.', {publishedCid: challengeVerification.publication?.cid});
console.log("challenge success", challengeVerification.publication?.cid, challengeVerification)
navigate(`/p/${selectedAddress}/c/${challengeVerification.publication?.cid}`); navigate(`/p/${selectedAddress}/c/${challengeVerification.publication?.cid}`);
} }
else if (challengeVerification.challengeSuccess === false) { else if (challengeVerification.challengeSuccess === false) {
setErrorMessage('Challenge failed.', {reason: challengeVerification.reason, errors: challengeVerification.errors}); setErrorMessage('Challenge failed.', {reason: challengeVerification.reason, errors: challengeVerification.errors});
console.log("challenge failed", challengeVerification.reason, challengeVerification.errors)
setErrorMessage("Error: You seem to have mistyped the CAPTCHA. Please try again."); setErrorMessage("Error: You seem to have mistyped the CAPTCHA. Please try again.");
} }
}; };
@@ -107,17 +107,17 @@ const Catalog = () => {
await comment.publishChallengeAnswers(challengeAnswers) await comment.publishChallengeAnswers(challengeAnswers)
} }
}; };
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);
}, },
}); });
const { publishComment, index } = usePublishComment(publishCommentOptions); const { publishComment, index } = usePublishComment(publishCommentOptions);
@@ -127,11 +127,8 @@ const Catalog = () => {
setSuccessMessage('Comment pending with index ' + index + '.'); setSuccessMessage('Comment pending with index ' + index + '.');
} }
}, [index]); }, [index]);
onChallengeVerificationRef.current = onChallengeVerification;
const resetFields = () => { const resetFields = () => {
nameRef.current.value = ''; nameRef.current.value = '';
subjectRef.current.value = ''; subjectRef.current.value = '';
@@ -140,21 +137,14 @@ const Catalog = () => {
}; };
useEffect(() => {
setPublishCommentOptions((prevPublishCommentOptions) => ({
...prevPublishCommentOptions,
subplebbitAddress: selectedAddress,
onChallengeVerification: onChallengeVerificationRef.current,
}));
}, [selectedAddress]);
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
event.preventDefault(); event.preventDefault();
setPublishCommentOptions((prevPublishCommentOptions) => ({ setPublishCommentOptions((prevPublishCommentOptions) => ({
...prevPublishCommentOptions, ...prevPublishCommentOptions,
displayName: nameRef.current.value || undefined, author: {
displayName: nameRef.current.value || undefined,
},
title: subjectRef.current.value || undefined, title: subjectRef.current.value || undefined,
content: commentRef.current.value || undefined, content: commentRef.current.value || undefined,
link: linkRef.current.value || undefined, link: linkRef.current.value || undefined,
@@ -184,9 +174,10 @@ const Catalog = () => {
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 = useGeneralStore.getState().captchaResponse;
resolve(currentCaptchaResponse);
setIsCaptchaOpen(false); setIsCaptchaOpen(false);
document.removeEventListener('keydown', handleKeyDown); document.removeEventListener('keydown', handleKeyDown);
event.preventDefault(); event.preventDefault();
+10 -10
View File
@@ -223,18 +223,18 @@ const Pending = () => {
</span>) </span>)
: null} : null}
&nbsp; &nbsp;
{comment.displayName {comment.author?.displayName
? comment.displayName.length > 20 ? comment.author?.displayName.length > 20
? <> ? <>
<span key={`n-${"pending"}`} className="name" <span key={`n-${"pending"}`} className="name"
data-tooltip-id="tooltip" data-tooltip-id="tooltip"
data-tooltip-content={comment.displayName} data-tooltip-content={comment.author?.displayName}
data-tooltip-place="top"> data-tooltip-place="top">
{comment.displayName.slice(0, 20) + " (...)"} {comment.author?.displayName.slice(0, 20) + " (...)"}
</span> </span>
</> </>
: <span key={`n-${"pending"}`} className="name"> : <span key={`n-${"pending"}`} className="name">
{comment.displayName}</span> {comment.author?.displayName}</span>
: <span key={`n-${"pending"}`} className="name"> : <span key={`n-${"pending"}`} className="name">
Anonymous</span>} Anonymous</span>}
&nbsp; &nbsp;
@@ -269,18 +269,18 @@ const Pending = () => {
<div key={`mob-pi-${"pending"}`} className="post-info-mobile"> <div key={`mob-pi-${"pending"}`} className="post-info-mobile">
<button style={{ all: 'unset', cursor: 'pointer' }} key={`mob-pb-${"pending"}`} className="post-menu-button-mobile" onClick={() => {}}>...</button> <button style={{ all: 'unset', cursor: 'pointer' }} key={`mob-pb-${"pending"}`} className="post-menu-button-mobile" onClick={() => {}}>...</button>
<span className="name-block-mobile"> <span className="name-block-mobile">
{comment.displayName {comment.author?.displayName
? comment.displayName.length > 15 ? comment.author?.displayName.length > 15
? <> ? <>
<span key={`mob-n-${"pending"}`} className="name-mobile" <span key={`mob-n-${"pending"}`} className="name-mobile"
data-tooltip-id="tooltip" data-tooltip-id="tooltip"
data-tooltip-content={comment.displayName} data-tooltip-content={comment.author?.displayName}
data-tooltip-place="top"> data-tooltip-place="top">
{comment.displayName.slice(0, 15) + " (...)"} {comment.author?.displayName.slice(0, 15) + " (...)"}
</span> </span>
</> </>
: <span key={`mob-n-${"pending"}`} className="name-mobile"> : <span key={`mob-n-${"pending"}`} className="name-mobile">
{comment.displayName}</span> {comment.author?.displayName}</span>
: <span key={`mob-n-${"pending"}`} className="name-mobile"> : <span key={`mob-n-${"pending"}`} className="name-mobile">
Anonymous</span>} Anonymous</span>}
&nbsp; &nbsp;