From 2b72ec6841e3c90d8979432379a7a58ba8311531 Mon Sep 17 00:00:00 2001 From: plebbitor Date: Fri, 14 Apr 2023 15:59:57 +0200 Subject: [PATCH] fix getCommentMediaInfo --- package.json | 2 +- src/components/views/Board.jsx | 19 +++-------- src/components/views/Pending.jsx | 14 ++++++-- yarn.lock | 57 ++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 32508984..1f17804b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "@babel/core": "^7.21.3", "@babel/plugin-syntax-flow": "^7.18.6", "@babel/plugin-transform-react-jsx": "^7.21.0", - "@plebbit/plebbit-react-hooks": "https://github.com/plebbit/plebbit-react-hooks.git#87e3b09611c002ae385ca4517890fc2e139d3822", + "@plebbit/plebbit-react-hooks": "https://github.com/plebbit/plebbit-react-hooks.git#11b519a6ad7a9b96911b2ebb4b7f13cddf5233d5", "@testing-library/dom": "^9.0.1", "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^14.0.0", diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index 06a17410..5d4ebaa2 100644 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -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(); diff --git a/src/components/views/Pending.jsx b/src/components/views/Pending.jsx index e4fd3070..380363ef 100644 --- a/src/components/views/Pending.jsx +++ b/src/components/views/Pending.jsx @@ -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 (