mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
30 lines
778 B
TypeScript
30 lines
778 B
TypeScript
import { useState, useCallback } from 'react';
|
|||
|
|
|
||
|
|
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);
|
||
|
|
}, []);
|
||
|
|
|
||
|
|
return { showReplyModal, activeCid, openReplyModal, closeModal };
|
||
|
|
};
|
||
|
|
|
||
|
|
export default useReplyModal;
|