From 51cc7fe3b684699889960d591483b852f8d1d90c Mon Sep 17 00:00:00 2001 From: plebbitor Date: Wed, 12 Apr 2023 14:02:35 +0200 Subject: [PATCH] added pending comment index --- package.json | 2 +- src/App.js | 2 +- src/components/views/Board.jsx | 41 +++++++++++++++------------- src/components/views/Catalog.jsx | 42 ++++++++++++++++------------- src/components/views/Pending.jsx | 5 ++-- src/components/views/Thread.jsx | 37 ++++++++++++++----------- yarn.lock | 46 +++----------------------------- 7 files changed, 75 insertions(+), 100 deletions(-) diff --git a/package.json b/package.json index b20d905c..32508984 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#33fca8ef1cfc78e5c16d7fcbe7effbeebeb082c8", + "@plebbit/plebbit-react-hooks": "https://github.com/plebbit/plebbit-react-hooks.git#87e3b09611c002ae385ca4517890fc2e139d3822", "@testing-library/dom": "^9.0.1", "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^14.0.0", diff --git a/src/App.js b/src/App.js index fe6e077a..67a46951 100644 --- a/src/App.js +++ b/src/App.js @@ -178,7 +178,7 @@ export default function App() { } /> } /> - } /> + } /> } /> diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index 0a12e9a5..57b63970 100644 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -96,23 +96,19 @@ const Board = () => { const onChallengeVerification = (challengeVerification) => { if (challengeVerification.challengeSuccess === true) { - setSuccessMessage('challenge success', {publishedCid: challengeVerification.publication?.cid}); + setSuccessMessage('Challenge success.', {publishedCid: challengeVerification.publication?.cid}); navigate(`/p/${selectedAddress}/c/${challengeVerification.publication?.cid}`); } else if (challengeVerification.challengeSuccess === false) { - setErrorMessage('challenge failed', {reason: challengeVerification.reason, errors: challengeVerification.errors}); + setErrorMessage('Challenge failed.', {reason: challengeVerification.reason, errors: challengeVerification.errors}); setErrorMessage("Error: You seem to have mistyped the CAPTCHA. Please try again."); } }; - onChallengeVerificationRef.current = onChallengeVerification; - - const onChallenge = async (challenges, comment) => { setPendingComment(comment); let challengeAnswers = []; - navigate(`/p/${selectedAddress}/c/pending`) try { challengeAnswers = await getChallengeAnswersFromUser(challenges) @@ -123,17 +119,9 @@ const Board = () => { if (challengeAnswers) { await comment.publishChallengeAnswers(challengeAnswers) } - } - - - const resetFields = () => { - nameRef.current.value = ''; - subjectRef.current.value = ''; - commentRef.current.value = ''; - linkRef.current.value = ''; }; - + const [publishCommentOptions, setPublishCommentOptions] = useState({ subplebbitAddress: selectedAddress, onChallenge, @@ -143,6 +131,26 @@ const Board = () => { }, }); + const { publishComment, index } = usePublishComment(publishCommentOptions); + + useEffect(() => { + if (index !== undefined) { + navigate(`/profile/c/${index}`); + setSuccessMessage('Comment pending with index ' + index + '.'); + } + }, [index]); + + + onChallengeVerificationRef.current = onChallengeVerification; + + + const resetFields = () => { + nameRef.current.value = ''; + subjectRef.current.value = ''; + commentRef.current.value = ''; + linkRef.current.value = ''; + }; + useEffect(() => { setPublishCommentOptions((prevPublishCommentOptions) => ({ @@ -174,9 +182,6 @@ const Board = () => { })(); } }, [publishCommentOptions]); - - - const { publishComment } = usePublishComment(publishCommentOptions); const getChallengeAnswersFromUser = async (challenges) => { diff --git a/src/components/views/Catalog.jsx b/src/components/views/Catalog.jsx index fe7aaa38..9904d63a 100644 --- a/src/components/views/Catalog.jsx +++ b/src/components/views/Catalog.jsx @@ -51,7 +51,6 @@ const Catalog = () => { useError(errorMessage, [errorMessage]); useSuccess(successMessage, [successMessage]); - // temporary title from JSON, gets subplebbitAddress from URL useEffect(() => { setSelectedAddress(subplebbitAddress); @@ -84,23 +83,19 @@ const Catalog = () => { const onChallengeVerification = (challengeVerification) => { if (challengeVerification.challengeSuccess === true) { - setSuccessMessage('challenge success', {publishedCid: challengeVerification.publication?.cid}); + setSuccessMessage('Challenge success.', {publishedCid: challengeVerification.publication?.cid}); navigate(`/p/${selectedAddress}/c/${challengeVerification.publication?.cid}`); } else if (challengeVerification.challengeSuccess === false) { - setErrorMessage('challenge failed', {reason: challengeVerification.reason, errors: challengeVerification.errors}); + setErrorMessage('Challenge failed.', {reason: challengeVerification.reason, errors: challengeVerification.errors}); setErrorMessage("Error: You seem to have mistyped the CAPTCHA. Please try again."); } }; - - onChallengeVerificationRef.current = onChallengeVerification; - const onChallenge = async (challenges, comment) => { setPendingComment(comment); let challengeAnswers = []; - navigate(`/p/${selectedAddress}/c/pending`) try { challengeAnswers = await getChallengeAnswersFromUser(challenges) @@ -111,14 +106,6 @@ const Catalog = () => { if (challengeAnswers) { await comment.publishChallengeAnswers(challengeAnswers) } - } - - - const resetFields = () => { - nameRef.current.value = ''; - subjectRef.current.value = ''; - commentRef.current.value = ''; - linkRef.current.value = ''; }; @@ -131,6 +118,28 @@ const Catalog = () => { }, }); + + const { publishComment, index } = usePublishComment(publishCommentOptions); + + useEffect(() => { + if (index !== undefined) { + navigate(`/profile/c/${index}`); + setSuccessMessage('Comment pending with index ' + index + '.'); + } + }, [index]); + + + onChallengeVerificationRef.current = onChallengeVerification; + + + const resetFields = () => { + nameRef.current.value = ''; + subjectRef.current.value = ''; + commentRef.current.value = ''; + linkRef.current.value = ''; + }; + + useEffect(() => { setPublishCommentOptions((prevPublishCommentOptions) => ({ ...prevPublishCommentOptions, @@ -161,9 +170,6 @@ const Catalog = () => { })(); } }, [publishCommentOptions]); - - - const { publishComment } = usePublishComment(publishCommentOptions); const getChallengeAnswersFromUser = async (challenges) => { diff --git a/src/components/views/Pending.jsx b/src/components/views/Pending.jsx index 1f58c149..303c3720 100644 --- a/src/components/views/Pending.jsx +++ b/src/components/views/Pending.jsx @@ -37,7 +37,6 @@ const Pending = () => { const commentMediaInfo = getCommentMediaInfo(comment); const fallbackImgUrl = "/assets/filedeleted-res.gif"; - const [selectedAddress, setSelectedAddress] = useState(comment.subplebbitAddress); const [selectedTitle, setSelectedTitle] = useState(null); @@ -119,8 +118,8 @@ const Pending = () => { <> -
{selectedTitle}
-
p/{selectedAddress}
+
{selectedTitle ?? null}
+
{selectedAddress ? ("p/" + selectedAddress) : null}
diff --git a/src/components/views/Thread.jsx b/src/components/views/Thread.jsx index f26979c7..596eccf8 100644 --- a/src/components/views/Thread.jsx +++ b/src/components/views/Thread.jsx @@ -58,7 +58,6 @@ const Thread = () => { useError(errorMessage, [errorMessage]); useSuccess(successMessage, [successMessage]); - // temporary title from JSON, gets subplebbitAddress and threadCid from URL useEffect(() => { setSelectedAddress(subplebbitAddress); @@ -95,13 +94,9 @@ const Thread = () => { }; - onChallengeVerificationRef.current = onChallengeVerification; - - const onChallenge = async (challenges, comment) => { setPendingComment(comment); let challengeAnswers = []; - navigate(`/p/${selectedAddress}/c/pending`) try { challengeAnswers = await getChallengeAnswersFromUser(challenges) @@ -112,13 +107,6 @@ const Thread = () => { if (challengeAnswers) { await comment.publishChallengeAnswers(challengeAnswers) } - } - - - const resetFields = () => { - nameRef.current.value = ''; - commentRef.current.value = ''; - linkRef.current.value = ''; }; @@ -132,6 +120,27 @@ const Thread = () => { }); + const { publishComment, index } = usePublishComment(publishCommentOptions); + + + useEffect(() => { + if (index !== undefined) { + navigate(`/profile/c/${index}`); + setSuccessMessage('Comment pending with index ' + index + '.'); + } + }, [index]); + + + onChallengeVerificationRef.current = onChallengeVerification; + + + const resetFields = () => { + nameRef.current.value = ''; + commentRef.current.value = ''; + linkRef.current.value = ''; + }; + + useEffect(() => { setPublishCommentOptions((prevPublishCommentOptions) => ({ ...prevPublishCommentOptions, @@ -163,9 +172,6 @@ const Thread = () => { }, [publishCommentOptions]); - const { publishComment } = usePublishComment(publishCommentOptions); - - const getChallengeAnswersFromUser = async (challenges) => { setChallengesArray(challenges); @@ -206,7 +212,6 @@ const Thread = () => { navigate(`/p/${selected}`); }; - // scroll to post when quote is clicked function handleQuoteClick(reply, event) { event.preventDefault(); diff --git a/yarn.lock b/yarn.lock index b576213f..042e6bb9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2459,46 +2459,6 @@ ts-custom-error "3.3.1" uuid "9.0.0" -"@plebbit/plebbit-js@https://github.com/plebbit/plebbit-js.git#ef0f3c6dd5e72c58dab1dffc486addf2819bd638": - version "0.0.3" - resolved "https://github.com/plebbit/plebbit-js.git#ef0f3c6dd5e72c58dab1dffc486addf2819bd638" - dependencies: - "@keyv/sqlite" "3.6.2" - "@plebbit/plebbit-logger" "github:plebbit/plebbit-logger" - "@types/node-fetch" "2.6.2" - "@types/proper-lockfile" "4.1.2" - "@types/uuid" "8.3.4" - assert "2.0.0" - async-wait-until "2.0.12" - buffer "6.0.3" - captcha-canvas "3.2.1" - err-code "3.0.1" - ethers "5.7.2" - file-type "16.5.4" - form-data "4.0.0" - hpagent "1.2.0" - ipfs-http-client "56.0.3" - ipfs-only-hash "4.0.0" - is-ipfs "6.0.2" - jose "4.11.0" - js-sha256 "0.9.0" - keyv "4.5.2" - knex "2.3.0" - libp2p-crypto "0.21.2" - limiter "2.1.0" - lodash-es "4.17.21" - open-graph-scraper "5.2.3" - peer-id "0.16.0" - proper-lockfile "github:plebbit/node-proper-lockfile" - retry "0.13.1" - safe-stable-stringify "2.4.1" - skia-canvas "1.0.0" - sqlite3 "5.1.2" - tiny-typed-emitter "2.1.0" - tinycache "1.1.2" - ts-custom-error "3.3.1" - uuid "9.0.0" - "@plebbit/plebbit-logger@github:plebbit/plebbit-logger": version "0.0.1" uid "9525ca9539479918931c3b334e8d490d1c87e507" @@ -2527,11 +2487,11 @@ uuid "8.3.2" zustand "4.0.0" -"@plebbit/plebbit-react-hooks@https://github.com/plebbit/plebbit-react-hooks.git#6de131a2e9f23578efd9faf4670d2cc43ce6d5ba": +"@plebbit/plebbit-react-hooks@https://github.com/plebbit/plebbit-react-hooks.git#87e3b09611c002ae385ca4517890fc2e139d3822": version "0.0.1" - resolved "https://github.com/plebbit/plebbit-react-hooks.git#6de131a2e9f23578efd9faf4670d2cc43ce6d5ba" + resolved "https://github.com/plebbit/plebbit-react-hooks.git#87e3b09611c002ae385ca4517890fc2e139d3822" dependencies: - "@plebbit/plebbit-js" "https://github.com/plebbit/plebbit-js.git#ef0f3c6dd5e72c58dab1dffc486addf2819bd638" + "@plebbit/plebbit-js" "https://github.com/plebbit/plebbit-js.git#c90a5a2920f763a32bedc0584606b358d83600e5" "@plebbit/plebbit-logger" "https://github.com/plebbit/plebbit-logger.git" assert "2.0.0" ethers "5.6.9"