mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
reset reply store, memoize close modal
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user