From 926372d503c8522c1b1c9cdfeb6b891b7f96e08d Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 5 Jun 2020 21:32:16 +0800 Subject: feat(front): Fix #73 . --- Timeline/ClientApp/src/timeline/TimelineItem.tsx | 112 ++++++++++++++++------- 1 file changed, 81 insertions(+), 31 deletions(-) (limited to 'Timeline/ClientApp/src/timeline/TimelineItem.tsx') diff --git a/Timeline/ClientApp/src/timeline/TimelineItem.tsx b/Timeline/ClientApp/src/timeline/TimelineItem.tsx index 0d2722c0..7d488826 100644 --- a/Timeline/ClientApp/src/timeline/TimelineItem.tsx +++ b/Timeline/ClientApp/src/timeline/TimelineItem.tsx @@ -1,18 +1,58 @@ import React from 'react'; -import { useTranslation } from 'react-i18next'; import clsx from 'clsx'; -import { Row, Col } from 'reactstrap'; +import { + Row, + Col, + Modal, + ModalHeader, + ModalBody, + ModalFooter, + Button, +} from 'reactstrap'; import { Link } from 'react-router-dom'; +import { useTranslation } from 'react-i18next'; import { TimelinePostInfo } from '../data/timeline'; import { useAvatarUrlWithGivenVersion } from '../user/api'; +const TimelinePostDeleteConfirmDialog: React.FC<{ + toggle: () => void; + onConfirm: () => void; +}> = ({ toggle, onConfirm }) => { + const { t } = useTranslation(); + + return ( + + + {t('timeline.post.deleteDialog.title')} + + {t('timeline.post.deleteDialog.prompt')} + + + + + + ); +}; + export interface TimelineItemProps { post: TimelinePostInfo; - showDeleteButton?: boolean; current?: boolean; - toggleMore?: () => void; - onDelete?: () => void; + more?: { + isOpen: boolean; + toggle: () => void; + onDelete: () => void; + }; onClick?: () => void; avatarVersion?: number; } @@ -22,25 +62,18 @@ const TimelineItem: React.FC = (props) => { const current = props.current === true; - const { toggleMore: toggleDelete } = props; + const { more } = props; const avatarUrl = useAvatarUrlWithGivenVersion( props.avatarVersion, props.post.author._links.avatar ); - const onOpenMore = React.useMemo< - React.MouseEventHandler | undefined - >(() => { - if (toggleDelete == null) { - return undefined; - } else { - return (e) => { - toggleDelete(); - e.stopPropagation(); - }; - } - }, [toggleDelete]); + const [deleteDialog, setDeleteDialog] = React.useState(false); + const toggleDeleteDialog = React.useCallback( + () => setDeleteDialog((old) => !old), + [] + ); return ( = (props) => { - {props.toggleMore != null ? ( + {more != null ? (
{ + more.toggle(); + e.stopPropagation(); + }} />
) : null} @@ -95,17 +131,31 @@ const TimelineItem: React.FC = (props) => { })()}

- {props.showDeleteButton ? ( -
- -
- ) : undefined} + {more != null && more.isOpen ? ( + <> +
+ { + toggleDeleteDialog(); + e.stopPropagation(); + }} + /> +
+ {deleteDialog ? ( + { + toggleDeleteDialog(); + more.toggle(); + }} + onConfirm={more.onDelete} + /> + ) : null} + + ) : null} ); }; -- cgit v1.2.3