fix(reply modal): add minimal timeout to allow rerender when already opened

This commit is contained in:
plebeius.eth
2024-04-29 13:34:46 +02:00
parent d6179d0fdc
commit 05cc3c4174
3 changed files with 21 additions and 15 deletions
+16 -14
View File
@@ -4,25 +4,27 @@ const useReplyModal = () => {
const [showReplyModal, setShowReplyModal] = useState(false);
const [activeCid, setActiveCid] = useState<string | null>(null);
const openReplyModal = useCallback(
(cid: string) => {
if (activeCid && activeCid !== cid) {
closeModal(); // close modal if a different CID is clicked
setActiveCid(cid);
setShowReplyModal(true);
} else if (!activeCid) {
setActiveCid(cid);
setShowReplyModal(true);
}
},
[activeCid],
);
const closeModal = useCallback(() => {
setActiveCid(null);
setShowReplyModal(false);
}, []);
const openReplyModal = useCallback(
(cid: string) => {
if (activeCid && activeCid !== cid) {
closeModal();
setTimeout(() => {
setActiveCid(cid);
setShowReplyModal(true);
}, 0); // minimal timeout to allow for state reset
} else if (!activeCid) {
setActiveCid(cid);
setShowReplyModal(true);
}
},
[activeCid, closeModal],
);
return { showReplyModal, activeCid, openReplyModal, closeModal };
};