diff options
author | crupest <crupest@outlook.com> | 2023-08-29 01:30:30 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-08-29 01:30:30 +0800 |
commit | b05860b6d2ea17db29a338659def49dc31082346 (patch) | |
tree | cbbd9d99af5e6b006f142effeae5222278dad02f /FrontEnd/src/pages/timeline/TimelinePostView.tsx | |
parent | 502dd817c79018c84b0a958dd4b2e24781e68ae1 (diff) | |
download | timeline-b05860b6d2ea17db29a338659def49dc31082346.tar.gz timeline-b05860b6d2ea17db29a338659def49dc31082346.tar.bz2 timeline-b05860b6d2ea17db29a338659def49dc31082346.zip |
Refactor dialog module.
Diffstat (limited to 'FrontEnd/src/pages/timeline/TimelinePostView.tsx')
-rw-r--r-- | FrontEnd/src/pages/timeline/TimelinePostView.tsx | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/FrontEnd/src/pages/timeline/TimelinePostView.tsx b/FrontEnd/src/pages/timeline/TimelinePostView.tsx index 6b87ef2a..5de09b28 100644 --- a/FrontEnd/src/pages/timeline/TimelinePostView.tsx +++ b/FrontEnd/src/pages/timeline/TimelinePostView.tsx @@ -9,7 +9,7 @@ import { pushAlert } from "~src/services/alert"; import { useClickOutside } from "~src/components/hooks"; import UserAvatar from "~src/components/user/UserAvatar"; -import { useDialog } from "~src/components/dialog"; +import { DialogProvider, useDialog } from "~src/components/dialog"; import FlatButton from "~src/components/button/FlatButton"; import ConfirmDialog from "~src/components/dialog/ConfirmDialog"; import TimelinePostContentView from "./TimelinePostContentView"; @@ -33,13 +33,33 @@ export default function TimelinePostView(props: TimelinePostViewProps) { const [operationMaskVisible, setOperationMaskVisible] = useState<boolean>(false); - const { switchDialog, dialogPropsMap } = useDialog(["delete"], { - onClose: { - delete: () => { - setOperationMaskVisible(false); + const { controller, switchDialog } = useDialog( + { + delete: ( + <ConfirmDialog + title="timeline.post.deleteDialog.title" + body="timeline.post.deleteDialog.prompt" + onConfirm={() => { + void getHttpTimelineClient() + .deletePost(post.timelineOwnerV2, post.timelineNameV2, post.id) + .then(onDeleted, () => { + pushAlert({ + type: "danger", + message: "timeline.deletePostFailed", + }); + }); + }} + /> + ), + }, + { + onClose: { + delete: () => { + setOperationMaskVisible(false); + }, }, }, - }); + ); const [maskElement, setMaskElement] = useState<HTMLElement | null>(null); useClickOutside(maskElement, () => setOperationMaskVisible(false)); @@ -98,21 +118,7 @@ export default function TimelinePostView(props: TimelinePostViewProps) { </div> ) : null} </TimelinePostCard> - <ConfirmDialog - title="timeline.post.deleteDialog.title" - body="timeline.post.deleteDialog.prompt" - onConfirm={() => { - void getHttpTimelineClient() - .deletePost(post.timelineOwnerV2, post.timelineNameV2, post.id) - .then(onDeleted, () => { - pushAlert({ - type: "danger", - message: "timeline.deletePostFailed", - }); - }); - }} - {...dialogPropsMap.delete} - /> + <DialogProvider controller={controller} /> </TimelinePostContainer> ); } |