added pending comment index

This commit is contained in:
plebbitor
2023-04-12 14:02:35 +02:00
parent 1596ac90c7
commit 51cc7fe3b6
7 changed files with 75 additions and 100 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
"@babel/core": "^7.21.3", "@babel/core": "^7.21.3",
"@babel/plugin-syntax-flow": "^7.18.6", "@babel/plugin-syntax-flow": "^7.18.6",
"@babel/plugin-transform-react-jsx": "^7.21.0", "@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/dom": "^9.0.1",
"@testing-library/jest-dom": "^5.14.1", "@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^14.0.0", "@testing-library/react": "^14.0.0",
+1 -1
View File
@@ -178,7 +178,7 @@ export default function App() {
<Route path='post' element={<Catalog />} /> <Route path='post' element={<Catalog />} />
<Route path='settings' element={<Catalog />} /> <Route path='settings' element={<Catalog />} />
</Route> </Route>
<Route path={`/p/:subplebbitAddress/c/pending`} element={<Pending setBodyStyle={setBodyStyle} /> } /> <Route path={`/profile/c/:index`} element={<Pending setBodyStyle={setBodyStyle} /> } />
<Route path='*' element={<NotFound setBodyStyle={setBodyStyle} />} /> <Route path='*' element={<NotFound setBodyStyle={setBodyStyle} />} />
</Routes> </Routes>
<StyledContainer /> <StyledContainer />
+23 -18
View File
@@ -96,23 +96,19 @@ 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});
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});
setErrorMessage("Error: You seem to have mistyped the CAPTCHA. Please try again."); setErrorMessage("Error: You seem to have mistyped the CAPTCHA. Please try again.");
} }
}; };
onChallengeVerificationRef.current = onChallengeVerification;
const onChallenge = async (challenges, comment) => { const onChallenge = async (challenges, comment) => {
setPendingComment(comment); setPendingComment(comment);
let challengeAnswers = []; let challengeAnswers = [];
navigate(`/p/${selectedAddress}/c/pending`)
try { try {
challengeAnswers = await getChallengeAnswersFromUser(challenges) challengeAnswers = await getChallengeAnswersFromUser(challenges)
@@ -123,17 +119,9 @@ const Board = () => {
if (challengeAnswers) { if (challengeAnswers) {
await comment.publishChallengeAnswers(challengeAnswers) await comment.publishChallengeAnswers(challengeAnswers)
} }
}
const resetFields = () => {
nameRef.current.value = '';
subjectRef.current.value = '';
commentRef.current.value = '';
linkRef.current.value = '';
}; };
const [publishCommentOptions, setPublishCommentOptions] = useState({ const [publishCommentOptions, setPublishCommentOptions] = useState({
subplebbitAddress: selectedAddress, subplebbitAddress: selectedAddress,
onChallenge, 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(() => { useEffect(() => {
setPublishCommentOptions((prevPublishCommentOptions) => ({ setPublishCommentOptions((prevPublishCommentOptions) => ({
@@ -174,9 +182,6 @@ const Board = () => {
})(); })();
} }
}, [publishCommentOptions]); }, [publishCommentOptions]);
const { publishComment } = usePublishComment(publishCommentOptions);
const getChallengeAnswersFromUser = async (challenges) => { const getChallengeAnswersFromUser = async (challenges) => {
+24 -18
View File
@@ -51,7 +51,6 @@ const Catalog = () => {
useError(errorMessage, [errorMessage]); useError(errorMessage, [errorMessage]);
useSuccess(successMessage, [successMessage]); useSuccess(successMessage, [successMessage]);
// temporary title from JSON, gets subplebbitAddress from URL // temporary title from JSON, gets subplebbitAddress from URL
useEffect(() => { useEffect(() => {
setSelectedAddress(subplebbitAddress); setSelectedAddress(subplebbitAddress);
@@ -84,23 +83,19 @@ 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});
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});
setErrorMessage("Error: You seem to have mistyped the CAPTCHA. Please try again."); setErrorMessage("Error: You seem to have mistyped the CAPTCHA. Please try again.");
} }
}; };
onChallengeVerificationRef.current = onChallengeVerification;
const onChallenge = async (challenges, comment) => { const onChallenge = async (challenges, comment) => {
setPendingComment(comment); setPendingComment(comment);
let challengeAnswers = []; let challengeAnswers = [];
navigate(`/p/${selectedAddress}/c/pending`)
try { try {
challengeAnswers = await getChallengeAnswersFromUser(challenges) challengeAnswers = await getChallengeAnswersFromUser(challenges)
@@ -111,14 +106,6 @@ const Catalog = () => {
if (challengeAnswers) { if (challengeAnswers) {
await comment.publishChallengeAnswers(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(() => { useEffect(() => {
setPublishCommentOptions((prevPublishCommentOptions) => ({ setPublishCommentOptions((prevPublishCommentOptions) => ({
...prevPublishCommentOptions, ...prevPublishCommentOptions,
@@ -161,9 +170,6 @@ const Catalog = () => {
})(); })();
} }
}, [publishCommentOptions]); }, [publishCommentOptions]);
const { publishComment } = usePublishComment(publishCommentOptions);
const getChallengeAnswersFromUser = async (challenges) => { const getChallengeAnswersFromUser = async (challenges) => {
+2 -3
View File
@@ -37,7 +37,6 @@ const Pending = () => {
const commentMediaInfo = getCommentMediaInfo(comment); const commentMediaInfo = getCommentMediaInfo(comment);
const fallbackImgUrl = "/assets/filedeleted-res.gif"; const fallbackImgUrl = "/assets/filedeleted-res.gif";
const [selectedAddress, setSelectedAddress] = useState(comment.subplebbitAddress); const [selectedAddress, setSelectedAddress] = useState(comment.subplebbitAddress);
const [selectedTitle, setSelectedTitle] = useState(null); const [selectedTitle, setSelectedTitle] = useState(null);
@@ -119,8 +118,8 @@ const Pending = () => {
<ImageBanner /> <ImageBanner />
</div> </div>
<> <>
<div className="board-title">{selectedTitle}</div> <div className="board-title">{selectedTitle ?? null}</div>
<div className="board-address">p/{selectedAddress}</div> <div className="board-address">{selectedAddress ? ("p/" + selectedAddress) : null}</div>
</> </>
</> </>
</Header> </Header>
+21 -16
View File
@@ -58,7 +58,6 @@ const Thread = () => {
useError(errorMessage, [errorMessage]); useError(errorMessage, [errorMessage]);
useSuccess(successMessage, [successMessage]); useSuccess(successMessage, [successMessage]);
// temporary title from JSON, gets subplebbitAddress and threadCid from URL // temporary title from JSON, gets subplebbitAddress and threadCid from URL
useEffect(() => { useEffect(() => {
setSelectedAddress(subplebbitAddress); setSelectedAddress(subplebbitAddress);
@@ -95,13 +94,9 @@ const Thread = () => {
}; };
onChallengeVerificationRef.current = onChallengeVerification;
const onChallenge = async (challenges, comment) => { const onChallenge = async (challenges, comment) => {
setPendingComment(comment); setPendingComment(comment);
let challengeAnswers = []; let challengeAnswers = [];
navigate(`/p/${selectedAddress}/c/pending`)
try { try {
challengeAnswers = await getChallengeAnswersFromUser(challenges) challengeAnswers = await getChallengeAnswersFromUser(challenges)
@@ -112,13 +107,6 @@ const Thread = () => {
if (challengeAnswers) { if (challengeAnswers) {
await comment.publishChallengeAnswers(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(() => { useEffect(() => {
setPublishCommentOptions((prevPublishCommentOptions) => ({ setPublishCommentOptions((prevPublishCommentOptions) => ({
...prevPublishCommentOptions, ...prevPublishCommentOptions,
@@ -163,9 +172,6 @@ const Thread = () => {
}, [publishCommentOptions]); }, [publishCommentOptions]);
const { publishComment } = usePublishComment(publishCommentOptions);
const getChallengeAnswersFromUser = async (challenges) => { const getChallengeAnswersFromUser = async (challenges) => {
setChallengesArray(challenges); setChallengesArray(challenges);
@@ -206,7 +212,6 @@ const Thread = () => {
navigate(`/p/${selected}`); navigate(`/p/${selected}`);
}; };
// scroll to post when quote is clicked // scroll to post when quote is clicked
function handleQuoteClick(reply, event) { function handleQuoteClick(reply, event) {
event.preventDefault(); event.preventDefault();
+3 -43
View File
@@ -2459,46 +2459,6 @@
ts-custom-error "3.3.1" ts-custom-error "3.3.1"
uuid "9.0.0" 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": "@plebbit/plebbit-logger@github:plebbit/plebbit-logger":
version "0.0.1" version "0.0.1"
uid "9525ca9539479918931c3b334e8d490d1c87e507" uid "9525ca9539479918931c3b334e8d490d1c87e507"
@@ -2527,11 +2487,11 @@
uuid "8.3.2" uuid "8.3.2"
zustand "4.0.0" 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" 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: 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" "@plebbit/plebbit-logger" "https://github.com/plebbit/plebbit-logger.git"
assert "2.0.0" assert "2.0.0"
ethers "5.6.9" ethers "5.6.9"