import React from "react"; import clsx from "clsx"; import { useTranslation } from "react-i18next"; import { Dropdown, Button } from "react-bootstrap"; import { getHttpHighlightClient } from "@/http/highlight"; import { getHttpBookmarkClient } from "@/http/bookmark"; import { useUser } from "@/services/user"; import { pushAlert } from "@/services/alert"; import { timelineVisibilityTooltipTranslationMap } from "@/services/timeline"; import { TimelinePageCardProps } from "./TimelinePageTemplate"; import CollapseButton from "./CollapseButton"; import { TimelineMemberDialog } from "./TimelineMember"; import TimelinePropertyChangeDialog from "./TimelinePropertyChangeDialog"; export interface TimelineCardTemplateProps extends TimelinePageCardProps { infoArea: React.ReactElement; manageArea: | { type: "member" } | { type: "manage"; items: ( | { type: "button"; text: string; color?: string; onClick: () => void; } | { type: "divider" } )[]; }; dialog: string | "property" | "member" | null; setDialog: (dialog: "property" | "member" | null) => void; } const TimelinePageCardTemplate: React.FC = ({ timeline, collapse, toggleCollapse, infoArea, manageArea, onReload, className, dialog, setDialog, }) => { const { t } = useTranslation(); const user = useUser(); return ( <>
{infoArea}

{timeline.description}

{t(timelineVisibilityTooltipTranslationMap[timeline.visibility])}
{ getHttpHighlightClient() [timeline.isHighlight ? "delete" : "put"](timeline.name) .then(onReload, () => { pushAlert({ message: timeline.isHighlight ? "timeline.removeHighlightFail" : "timeline.addHighlightFail", type: "danger", }); }); } : undefined } /> {user != null ? ( { getHttpBookmarkClient() [timeline.isBookmark ? "delete" : "put"](timeline.name) .then(onReload, () => { pushAlert({ message: timeline.isBookmark ? "timeline.removeBookmarkFail" : "timeline.addBookmarkFail", type: "danger", }); }); }} /> ) : null} {manageArea.type === "manage" ? ( {t("timeline.manage")} {manageArea.items.map((item, index) => { if (item.type === "divider") { return ; } else { return ( {t(item.text)} ); } })} ) : ( )}
{(() => { if (dialog === "member") { return ( setDialog(null)} open onChange={onReload} /> ); } else if (dialog === "property") { return ( setDialog(null)} open onChange={onReload} /> ); } })()} ); }; export default TimelinePageCardTemplate;