import { useState } from "react"; import { getHttpTimelineClient, HttpTimelinePostInfo } from "@/http/timeline"; import { pushAlert } from "@/services/alert"; import { useClickOutside } from "@/utilities/hooks"; import UserAvatar from "@/views/common/user/UserAvatar"; import { useDialog } from "@/views/common/dialog"; import FlatButton from "@/views/common/button/FlatButton"; import ConfirmDialog from "@/views/common/dialog/ConfirmDialog"; import TimelinePostContentView from "./TimelinePostContentView"; import IconButton from "@/views/common/button/IconButton"; import TimelinePostContainer from "./TimelinePostContainer"; import TimelinePostCard from "./TimelinePostCard"; import "./TimelinePostView.css"; interface TimelinePostViewProps { post: HttpTimelinePostInfo; className?: string; onChanged: (post: HttpTimelinePostInfo) => void; onDeleted: () => void; } export default function TimelinePostView(props: TimelinePostViewProps) { const { post, onDeleted } = props; const [operationMaskVisible, setOperationMaskVisible] = useState(false); const { switchDialog, dialogPropsMap } = useDialog(["delete"], { onClose: { delete: () => { setOperationMaskVisible(false); }, }, }); const [maskElement, setMaskElement] = useState(null); useClickOutside(maskElement, () => setOperationMaskVisible(false)); return ( {post.editable && ( { setOperationMaskVisible(true); e.stopPropagation(); }} /> )}
{post.author.nickname} {new Date(post.time).toLocaleTimeString()}
{operationMaskVisible ? (
{ setOperationMaskVisible(false); }} > { e.stopPropagation(); }} /> { switchDialog("delete"); e.stopPropagation(); }} />
) : null}
{ void getHttpTimelineClient() .deletePost(post.timelineOwnerV2, post.timelineNameV2, post.id) .then(onDeleted, () => { pushAlert({ type: "danger", message: "timeline.deletePostFailed", }); }); }} {...dialogPropsMap.delete} />
); }