fix getCommentMediaInfo

This commit is contained in:
plebbitor
2023-04-14 15:59:57 +02:00
parent 2a0bf0eec6
commit 2b72ec6841
4 changed files with 73 additions and 19 deletions
+4 -15
View File
@@ -44,8 +44,6 @@ const Board = () => {
const commentRef = useRef();
const linkRef = useRef();
const onChallengeVerificationRef = useRef();
const [isReplyOpen, setIsReplyOpen] = useState(false);
const navigate = useNavigate();
const [prevScrollPos, setPrevScrollPos] = useState(0);
@@ -100,10 +98,12 @@ const Board = () => {
const onChallengeVerification = (challengeVerification) => {
if (challengeVerification.challengeSuccess === true) {
setSuccessMessage('Challenge success.', {publishedCid: challengeVerification.publication?.cid});
console.log("challenge success", challengeVerification.publication?.cid, challengeVerification)
navigate(`/p/${selectedAddress}/c/${challengeVerification.publication?.cid}`);
}
else if (challengeVerification.challengeSuccess === false) {
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.");
}
};
@@ -128,11 +128,12 @@ const Board = () => {
const [publishCommentOptions, setPublishCommentOptions] = useState({
subplebbitAddress: selectedAddress,
onChallenge,
onChallengeVerification: onChallengeVerificationRef.current,
onChallengeVerification,
onError: (error) => {
setErrorMessage(error);
},
});
const { publishComment, index } = usePublishComment(publishCommentOptions);
@@ -142,9 +143,6 @@ const Board = () => {
setSuccessMessage('Comment pending with index ' + index + '.');
}
}, [index]);
onChallengeVerificationRef.current = onChallengeVerification;
const resetFields = () => {
@@ -154,15 +152,6 @@ const Board = () => {
linkRef.current.value = '';
};
useEffect(() => {
setPublishCommentOptions((prevPublishCommentOptions) => ({
...prevPublishCommentOptions,
subplebbitAddress: selectedAddress,
onChallengeVerification: onChallengeVerificationRef.current,
}));
}, [selectedAddress]);
const handleSubmit = async (event) => {
event.preventDefault();
+11 -3
View File
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { Tooltip } from 'react-tooltip';
import useGeneralStore from '../../hooks/stores/useGeneralStore';
@@ -36,10 +36,9 @@ const Pending = () => {
useError(errorMessage, [errorMessage]);
useSuccess(successMessage, [successMessage]);
const navigate = useNavigate();
const commentMediaInfo = getCommentMediaInfo(comment);
const [commentMediaInfo, setCommentMediaInfo] = useState(null);
const fallbackImgUrl = "/assets/filedeleted-res.gif";
// mobile navbar board select functionality
const handleSelectChange = (event) => {
const selected = event.target.value;
@@ -49,6 +48,15 @@ const Pending = () => {
navigate(`/p/${selected}`);
};
// get comment media info
useEffect(() => {
if (comment && comment.link) {
const mediaInfo = getCommentMediaInfo(comment);
setCommentMediaInfo(mediaInfo);
}
}, [comment]);
return (
<Container>
<SettingsModal