import { useState } from "react"; import { HubConnectionState } from "@microsoft/signalr"; import { useUser } from "~src/services/user"; import { pushAlert } from "~src/services/alert"; import { HttpTimelineInfo } from "~src/http/timeline"; import { getHttpBookmarkClient } from "~src/http/bookmark"; import { useMobile } from "~src/components/hooks"; import { Dialog, useDialog } from "~src/components/dialog"; import UserAvatar from "~src/components/user/UserAvatar"; import PopupMenu from "~src/components/menu/PopupMenu"; import FullPageDialog from "~src/components/dialog/FullPageDialog"; import Card from "~src/components/Card"; import TimelineDeleteDialog from "./TimelineDeleteDialog"; import ConnectionStatusBadge from "./ConnectionStatusBadge"; import CollapseButton from "./CollapseButton"; import TimelineMember from "./TimelineMember"; import TimelinePropertyChangeDialog from "./TimelinePropertyChangeDialog"; import IconButton from "~src/components/button/IconButton"; import "./TimelineCard.css"; interface TimelinePageCardProps { timeline: HttpTimelineInfo; connectionStatus: HubConnectionState; onReload: () => void; } export default function TimelineCard(props: TimelinePageCardProps) { const { timeline, connectionStatus, onReload } = props; const user = useUser(); const [collapse, setCollapse] = useState(true); const toggleCollapse = (): void => { setCollapse((o) => !o); }; const isMobile = useMobile(); const { createDialogSwitch, dialogPropsMap } = useDialog([ "member", "property", "delete", ]); const content = (

{timeline.title} {timeline.nameV2}

{timeline.owner.nickname} @{timeline.owner.username}

{timeline.description}

{user && ( { getHttpBookmarkClient() [timeline.isBookmark ? "delete" : "post"]( user.username, timeline.owner.username, timeline.nameV2, ) .then(onReload, () => { pushAlert({ message: timeline.isBookmark ? "timeline.removeBookmarkFail" : "timeline.addBookmarkFail", type: "danger", }); }); }} /> )} {timeline.manageable && ( )}
); return (
{isMobile ? ( {content} ) : (
{content}
)}
); }