From 538d6830a0022b49b99695095d85e567b0c86e71 Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 30 Jul 2023 23:47:53 +0800 Subject: ... --- FrontEnd/src/pages/timeline/TimelineCard.tsx | 167 +++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 FrontEnd/src/pages/timeline/TimelineCard.tsx (limited to 'FrontEnd/src/pages/timeline/TimelineCard.tsx') diff --git a/FrontEnd/src/pages/timeline/TimelineCard.tsx b/FrontEnd/src/pages/timeline/TimelineCard.tsx new file mode 100644 index 00000000..8ce133c0 --- /dev/null +++ b/FrontEnd/src/pages/timeline/TimelineCard.tsx @@ -0,0 +1,167 @@ +import * as React from "react"; +import { useTranslation } from "react-i18next"; +import classnames from "classnames"; +import { HubConnectionState } from "@microsoft/signalr"; + +import { useIsSmallScreen } from "@/utilities/hooks"; +import { timelineVisibilityTooltipTranslationMap } from "@/services/timeline"; +import { useUser } from "@/services/user"; +import { pushAlert } from "@/services/alert"; +import { HttpTimelineInfo } from "@/http/timeline"; +import { getHttpBookmarkClient } from "@/http/bookmark"; + +import UserAvatar from "@/views/common/user/UserAvatar"; +import PopupMenu from "@/views/common/menu/PopupMenu"; +import FullPageDialog from "@/views/common/dialog/FullPageDialog"; +import Card from "@/views/common/Card"; +import TimelineDeleteDialog from "./TimelineDeleteDialog"; +import ConnectionStatusBadge from "./ConnectionStatusBadge"; +import CollapseButton from "./CollapseButton"; +import { TimelineMemberDialog } from "./TimelineMember"; +import TimelinePropertyChangeDialog from "./TimelinePropertyChangeDialog"; +import IconButton from "@/views/common/button/IconButton"; + +export interface TimelinePageCardProps { + timeline: HttpTimelineInfo; + connectionStatus: HubConnectionState; + className?: string; + onReload: () => void; +} + +const TimelineCard: React.FC = (props) => { + const { timeline, connectionStatus, onReload, className } = props; + + const { t } = useTranslation(); + + const [dialog, setDialog] = React.useState< + "member" | "property" | "delete" | null + >(null); + + const [collapse, setCollapse] = React.useState(true); + const toggleCollapse = (): void => { + setCollapse((o) => !o); + }; + + const isSmallScreen = useIsSmallScreen(); + + const user = useUser(); + + const content = ( + <> +

+ {timeline.title} + {timeline.nameV2} +

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

{timeline.description}

+ + {t(timelineVisibilityTooltipTranslationMap[timeline.visibility])} + +
+ {user != null ? ( + { + getHttpBookmarkClient() + [timeline.isBookmark ? "delete" : "post"]( + user.username, + timeline.owner.username, + timeline.nameV2, + ) + .then(onReload, () => { + pushAlert({ + message: timeline.isBookmark + ? "timeline.removeBookmarkFail" + : "timeline.addBookmarkFail", + type: "danger", + }); + }); + }} + /> + ) : null} + setDialog("member")} + /> + {timeline.manageable ? ( + setDialog("property"), + }, + { type: "divider" }, + { + type: "button", + onClick: () => setDialog("delete"), + color: "danger", + text: "timeline.manageItem.delete", + }, + ]} + containerClassName="d-inline" + > + + + ) : null} +
+ + ); + + return ( + <> + +
+ + +
+ {isSmallScreen ? ( + + {content} + + ) : ( +
{content}
+ )} +
+ setDialog(null)} + open={dialog === "member"} + onChange={onReload} + /> + setDialog(null)} + open={dialog === "property"} + onChange={onReload} + /> + setDialog(null)} + /> + + ); +}; + +export default TimelineCard; -- cgit v1.2.3