import { useState } from "react"; import classNames from "classnames"; 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 Card from "@/views/common/Card"; import FlatButton from "@/views/common/button/FlatButton"; import ConfirmDialog from "@/views/common/dialog/ConfirmDialog"; import TimelineLine from "./TimelineLine"; import TimelinePostContentView from "./TimelinePostContentView"; import IconButton from "@/views/common/button/IconButton"; import "./TimelinePostView.css"; export interface TimelinePostViewProps { post: HttpTimelinePostInfo; className?: string; onChanged: (post: HttpTimelinePostInfo) => void; onDeleted: () => void; } export function TimelinePostView(props: TimelinePostViewProps) { const { post, className, 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} />
); } export default TimelinePostView;