import { useState } from "react"; import { getHttpTimelineClient, HttpTimelinePostInfo } from "~src/http/timeline"; import { pushAlert } from "~src/services/alert"; import { useClickOutside } from "~src/utilities/hooks"; import UserAvatar from "~src/components/user/UserAvatar"; import { useDialog } from "~src/components/dialog"; import FlatButton from "~src/components/button/FlatButton"; import ConfirmDialog from "~src/components/dialog/ConfirmDialog"; import TimelinePostContentView from "./TimelinePostContentView"; import IconButton from "~src/components/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} />
); }