import React from 'react'; import clsx from 'clsx'; import { Row, Col, Modal, ModalHeader, ModalBody, ModalFooter, Button, } from 'reactstrap'; import { Link } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import Svg from 'react-inlinesvg'; import chevronDownIcon from 'bootstrap-icons/icons/chevron-down.svg'; import trashIcon from 'bootstrap-icons/icons/trash.svg'; 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')} {t('operationDialog.cancel')} { onConfirm(); toggle(); }} > {t('operationDialog.confirm')} ); }; export interface TimelineItemProps { post: TimelinePostInfo; current?: boolean; more?: { isOpen: boolean; toggle: () => void; onDelete: () => void; }; onClick?: () => void; avatarVersion?: number; onResize?: () => void; className?: string; style?: React.CSSProperties; } const TimelineItem: React.FC = (props) => { const { i18n } = useTranslation(); const current = props.current === true; const { more, onResize } = props; const avatarUrl = useAvatarUrlWithGivenVersion( props.avatarVersion, props.post.author._links.avatar ); const [deleteDialog, setDeleteDialog] = React.useState(false); const toggleDeleteDialog = React.useCallback( () => setDeleteDialog((old) => !old), [] ); return ( {current && } {props.post.time.toLocaleString(i18n.languages)} {props.post.author.nickname} {more != null ? ( { more.toggle(); e.stopPropagation(); }} /> ) : null} {(() => { const { content } = props.post; if (content.type === 'text') { return content.text; } else { return ( ); } })()} {more != null && more.isOpen ? ( <> { toggleDeleteDialog(); e.stopPropagation(); }} /> {deleteDialog ? ( { toggleDeleteDialog(); more.toggle(); }} onConfirm={more.onDelete} /> ) : null} > ) : null} ); }; export default TimelineItem;