import React from "react"; import classnames from "classnames"; import { Link } from "react-router-dom"; import { getHttpTimelineClient, HttpTimelinePostInfo } from "@/http/timeline"; import { pushAlert } from "@/services/alert"; import UserAvatar from "../common/user/UserAvatar"; import TimelineLine from "./TimelineLine"; import TimelinePostContentView from "./TimelinePostContentView"; import TimelinePostDeleteConfirmDialog from "./TimelinePostDeleteConfirmDialog"; export interface TimelinePostViewProps { post: HttpTimelinePostInfo; current?: boolean; className?: string; style?: React.CSSProperties; cardStyle?: React.CSSProperties; onDeleted?: () => void; } const TimelinePostView: React.FC = (props) => { const { post, className, style, cardStyle, onDeleted } = props; const current = props.current === true; const [operationMaskVisible, setOperationMaskVisible] = React.useState(false); const [deleteDialog, setDeleteDialog] = React.useState(false); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const cardRef = React.useRef(null!); React.useEffect(() => { const cardIntersectionObserver = new IntersectionObserver(([e]) => { if (e.intersectionRatio > 0) { cardRef.current.style.animationName = "timeline-post-enter"; } }); cardIntersectionObserver.observe(cardRef.current); return () => { cardIntersectionObserver.disconnect(); }; }, []); return (
{post.editable ? ( { setOperationMaskVisible(true); e.stopPropagation(); }} /> ) : null}
{post.author.nickname} {new Date(post.time).toLocaleTimeString()}
{operationMaskVisible ? (
{ setOperationMaskVisible(false); }} > { setDeleteDialog(true); e.stopPropagation(); }} />
) : null}
{deleteDialog ? ( { setDeleteDialog(false); setOperationMaskVisible(false); }} onConfirm={() => { void getHttpTimelineClient() .deletePost(post.timelineName, post.id) .then(onDeleted, () => { pushAlert({ type: "danger", message: "timeline.deletePostFailed", }); }); }} /> ) : null}
); }; export default TimelinePostView;