reset reply store, memoize close modal

This commit is contained in:
Tom (plebeius.eth)
2024-08-21 11:11:19 +02:00
parent e76262bd50
commit 999990bee1
2 changed files with 12 additions and 6 deletions
+9 -3
View File
@@ -26,7 +26,7 @@ interface ReplyModalProps {
const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, subplebbitAddress }: ReplyModalProps) => {
const { t } = useTranslation();
const { setPublishReplyOptions, publishReply } = usePublishReply({ cid: parentCid, subplebbitAddress });
const { setPublishReplyOptions, publishReply, resetPublishReplyOptions, replyIndex } = usePublishReply({ cid: parentCid, subplebbitAddress });
const account = useAccount();
const { displayName } = account?.author || {};
const [url, setUrl] = useState('');
@@ -69,7 +69,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s
}
}, [anonMode, getAnonAddressForReply]);
const onPublishReply = async () => {
const onPublishReply = () => {
const currentContent = textRef.current?.value || '';
const currentUrl = urlRef.current?.value || '';
@@ -84,9 +84,15 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s
}
publishReply();
closeModal();
};
useEffect(() => {
if (typeof replyIndex === 'number') {
resetPublishReplyOptions();
closeModal();
}
}, [replyIndex, resetPublishReplyOptions, closeModal]);
const hasSetInitialDisplayName = useRef(false);
useEffect(() => {
if (!hasSetInitialDisplayName.current && displayName) {
+3 -3
View File
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useCallback, useState } from 'react';
import useIsMobile from './use-is-mobile';
import useSelectedTextStore from '../stores/use-selected-text-store';
@@ -13,11 +13,11 @@ const useReplyModal = () => {
const isMobile = useIsMobile();
const [scrollY, setScrollY] = useState<number>(0);
const closeModal = () => {
const closeModal = useCallback(() => {
resetSelectedText();
setActiveCid(null);
setShowReplyModal(false);
};
}, [resetSelectedText, setActiveCid, setShowReplyModal]);
const getSelectedText = () => {
let text = document.getSelection()?.toString();