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
+23 -18
View File
@@ -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) => {