add setPendingCommentIndex

This commit is contained in:
plebbitor
2023-04-24 15:48:30 +02:00
parent 04cdd9f445
commit 661f925f07
9 changed files with 41 additions and 4 deletions
+2
View File
@@ -0,0 +1,2 @@
REACT_APP_PLEBBIT_REACT_HOOKS_MOCK_CONTENT=1
REACT_APP_PLEBBIT_REACT_HOOKS_MOCK_CONTENT_LOADING_TIME=1000
+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#604eab550a9c480cee42bf414581c624ec316f27", "@plebbit/plebbit-react-hooks": "https://github.com/plebbit/plebbit-react-hooks.git#97b538693972e26f7c0f0f13ec6afab03b0e2e57",
"@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
View File
@@ -39,7 +39,6 @@ const CaptchaModal = () => {
const handleKeyDown = (event) => { const handleKeyDown = (event) => {
if (event.key === "Enter") { if (event.key === "Enter") {
event.preventDefault();
submitCaptcha(); submitCaptcha();
} }
}; };
+10 -1
View File
@@ -1,4 +1,5 @@
import React, { useRef, useState, useEffect } from 'react'; import React, { useRef, useState, useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { usePublishComment } from '@plebbit/plebbit-react-hooks'; import { usePublishComment } from '@plebbit/plebbit-react-hooks';
import { StyledModal } from './styled/ReplyModal.styled'; import { StyledModal } from './styled/ReplyModal.styled';
import useGeneralStore from '../hooks/stores/useGeneralStore'; import useGeneralStore from '../hooks/stores/useGeneralStore';
@@ -13,6 +14,7 @@ const ReplyModal = ({ isOpen, closeModal }) => {
setChallengesArray, setChallengesArray,
setIsCaptchaOpen, setIsCaptchaOpen,
setPendingComment, setPendingComment,
setPendingCommentIndex,
setResolveCaptchaPromise, setResolveCaptchaPromise,
selectedAddress, selectedAddress,
selectedParentCid, selectedParentCid,
@@ -29,6 +31,7 @@ const ReplyModal = ({ isOpen, closeModal }) => {
const [errorMessage, setErrorMessage] = useState(null); const [errorMessage, setErrorMessage] = useState(null);
useError(errorMessage, [errorMessage]); useError(errorMessage, [errorMessage]);
const location = useLocation();
const onChallengeVerification = (challengeVerification) => { const onChallengeVerification = (challengeVerification) => {
if (challengeVerification.challengeSuccess === true) { if (challengeVerification.challengeSuccess === true) {
@@ -74,7 +77,13 @@ const ReplyModal = ({ isOpen, closeModal }) => {
}); });
const { publishComment } = usePublishComment(publishCommentOptions); const { publishComment, index } = usePublishComment(publishCommentOptions);
useEffect(() => {
if (index !== undefined) {
setPendingCommentIndex(index);
}
}, [index, location]);
const resetFields = () => { const resetFields = () => {
+2
View File
@@ -32,6 +32,7 @@ const Board = () => {
setIsCaptchaOpen, setIsCaptchaOpen,
isSettingsOpen, setIsSettingsOpen, isSettingsOpen, setIsSettingsOpen,
setPendingComment, setPendingComment,
setPendingCommentIndex,
setResolveCaptchaPromise, setResolveCaptchaPromise,
selectedAddress, setSelectedAddress, selectedAddress, setSelectedAddress,
setSelectedParentCid, setSelectedParentCid,
@@ -145,6 +146,7 @@ const Board = () => {
useEffect(() => { useEffect(() => {
if (index !== undefined) { if (index !== undefined) {
setPendingCommentIndex(index);
navigate(`/profile/c/${index}`); navigate(`/profile/c/${index}`);
} }
}, [index]); }, [index]);
+2
View File
@@ -25,6 +25,7 @@ const Catalog = () => {
setIsCaptchaOpen, setIsCaptchaOpen,
isSettingsOpen, setIsSettingsOpen, isSettingsOpen, setIsSettingsOpen,
setPendingComment, setPendingComment,
setPendingCommentIndex,
setResolveCaptchaPromise, setResolveCaptchaPromise,
selectedAddress, setSelectedAddress, selectedAddress, setSelectedAddress,
selectedStyle, selectedStyle,
@@ -127,6 +128,7 @@ const Catalog = () => {
useEffect(() => { useEffect(() => {
if (index !== undefined) { if (index !== undefined) {
setPendingCommentIndex(index);
navigate(`/profile/c/${index}`); navigate(`/profile/c/${index}`);
} }
}, [index]); }, [index]);
+6 -1
View File
@@ -33,6 +33,7 @@ const Thread = () => {
isSettingsOpen, setIsSettingsOpen, isSettingsOpen, setIsSettingsOpen,
setResolveCaptchaPromise, setResolveCaptchaPromise,
pendingComment, setPendingComment, pendingComment, setPendingComment,
setPendingCommentIndex,
selectedAddress, setSelectedAddress, selectedAddress, setSelectedAddress,
setSelectedParentCid, setSelectedParentCid,
setSelectedShortCid, setSelectedShortCid,
@@ -137,7 +138,7 @@ const Thread = () => {
useEffect(() => { useEffect(() => {
if (index !== undefined) { if (index !== undefined) {
window.scrollTo(0, document.body.scrollHeight); setPendingCommentIndex(index);
} }
}, [index]); }, [index]);
@@ -151,6 +152,10 @@ const Thread = () => {
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
event.preventDefault(); event.preventDefault();
setTimeout(() => {
window.scrollTo(0, document.body.scrollHeight);
}, 100)
setPublishCommentOptions((prevPublishCommentOptions) => ({ setPublishCommentOptions((prevPublishCommentOptions) => ({
...prevPublishCommentOptions, ...prevPublishCommentOptions,
+3
View File
@@ -29,6 +29,9 @@ const useGeneralStore = create((set) => ({
pendingComment: '', pendingComment: '',
setPendingComment: (comment) => set({ pendingComment: comment }), setPendingComment: (comment) => set({ pendingComment: comment }),
pendingCommentIndex: null,
setPendingCommentIndex: (index) => set({ pendingCommentIndex: index }),
publishedComment: '', publishedComment: '',
setPublishedComment: (comment) => set({ publishedComment: comment }), setPublishedComment: (comment) => set({ publishedComment: comment }),
+15
View File
@@ -2487,6 +2487,21 @@
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#97b538693972e26f7c0f0f13ec6afab03b0e2e57":
version "0.0.1"
resolved "https://github.com/plebbit/plebbit-react-hooks.git#97b538693972e26f7c0f0f13ec6afab03b0e2e57"
dependencies:
"@plebbit/plebbit-js" "https://github.com/plebbit/plebbit-js.git#b3272c08bd3861322b7a5eef48992e1b73640098"
"@plebbit/plebbit-logger" "https://github.com/plebbit/plebbit-logger.git"
assert "2.0.0"
ethers "5.6.9"
localforage "1.10.0"
lodash.isequal "4.5.0"
memoizee "0.4.15"
quick-lru "5.1.1"
uuid "8.3.2"
zustand "4.0.0"
"@pmmmwh/react-refresh-webpack-plugin@^0.5.3": "@pmmmwh/react-refresh-webpack-plugin@^0.5.3":
version "0.5.10" version "0.5.10"
resolved "https://registry.yarnpkg.com/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.10.tgz#2eba163b8e7dbabb4ce3609ab5e32ab63dda3ef8" resolved "https://registry.yarnpkg.com/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.10.tgz#2eba163b8e7dbabb4ce3609ab5e32ab63dda3ef8"