diff options
author | crupest <crupest@outlook.com> | 2021-07-05 22:27:30 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-07-05 22:27:30 +0800 |
commit | e2c6cd83c9ca770bbd1b16029987d97f88facf14 (patch) | |
tree | 95d763c4f43d8caaed0fded4d8e99376de5b436e /FrontEnd/src/views/timeline-common/TimelinePostView.tsx | |
parent | 00e6794abdfb39cf5bbfcb0d89fc2baa9a83a738 (diff) | |
download | timeline-e2c6cd83c9ca770bbd1b16029987d97f88facf14.tar.gz timeline-e2c6cd83c9ca770bbd1b16029987d97f88facf14.tar.bz2 timeline-e2c6cd83c9ca770bbd1b16029987d97f88facf14.zip |
refactor: Extract out useClickOutside.
Diffstat (limited to 'FrontEnd/src/views/timeline-common/TimelinePostView.tsx')
-rw-r--r-- | FrontEnd/src/views/timeline-common/TimelinePostView.tsx | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/FrontEnd/src/views/timeline-common/TimelinePostView.tsx b/FrontEnd/src/views/timeline-common/TimelinePostView.tsx index 0954b912..de6c3e7c 100644 --- a/FrontEnd/src/views/timeline-common/TimelinePostView.tsx +++ b/FrontEnd/src/views/timeline-common/TimelinePostView.tsx @@ -6,6 +6,8 @@ import { getHttpTimelineClient, HttpTimelinePostInfo } from "@/http/timeline"; import { pushAlert } from "@/services/alert"; +import useClickOutside from "@/utilities/useClickOutside"; + import UserAvatar from "../common/user/UserAvatar"; import Card from "../common/Card"; import FlatButton from "../common/button/FlatButton"; @@ -32,6 +34,12 @@ const TimelinePostView: React.FC<TimelinePostViewProps> = (props) => { "delete" | "changeproperty" | null >(null); + const [maskElement, setMaskElement] = React.useState<HTMLElement | null>( + null + ); + + useClickOutside(maskElement, () => setOperationMaskVisible(false)); + const cardRef = React.useRef<HTMLDivElement>(null); React.useEffect(() => { const cardIntersectionObserver = new IntersectionObserver(([e]) => { @@ -92,6 +100,7 @@ const TimelinePostView: React.FC<TimelinePostViewProps> = (props) => { </div> {operationMaskVisible ? ( <div + ref={setMaskElement} className="timeline-post-item-options-mask" onClick={() => { setOperationMaskVisible(false); |