From 928ba0ce419bacba113951095278a5138ead34cf Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 10 Apr 2022 16:04:03 +0800 Subject: ... --- FrontEnd/src/views/timeline/TimelineCard.tsx | 210 +++++++++++++++++++++------ 1 file changed, 165 insertions(+), 45 deletions(-) (limited to 'FrontEnd/src/views/timeline/TimelineCard.tsx') diff --git a/FrontEnd/src/views/timeline/TimelineCard.tsx b/FrontEnd/src/views/timeline/TimelineCard.tsx index 339fbfa0..156c581e 100644 --- a/FrontEnd/src/views/timeline/TimelineCard.tsx +++ b/FrontEnd/src/views/timeline/TimelineCard.tsx @@ -1,62 +1,182 @@ import React from "react"; +import { useTranslation } from "react-i18next"; +import classnames from "classnames"; +import { HubConnectionState } from "@microsoft/signalr"; -import { TimelinePageCardProps } from "../timeline-common/TimelinePageTemplate"; -import TimelinePageCardTemplate from "../timeline-common/TimelinePageCardTemplate"; +import { useIsSmallScreen } from "@/utilities/mediaQuery"; +import { timelineVisibilityTooltipTranslationMap } from "@/services/timeline"; +import { useUser } from "@/services/user"; +import { pushAlert } from "@/services/alert"; +import { HttpTimelineInfo } from "@/http/timeline"; +import { getHttpHighlightClient } from "@/http/highlight"; +import { getHttpBookmarkClient } from "@/http/bookmark"; import UserAvatar from "../common/user/UserAvatar"; +import PopupMenu from "../common/menu/PopupMenu"; +import FullPageDialog from "../common/dailog/FullPageDialog"; +import Card from "../common/Card"; import TimelineDeleteDialog from "./TimelineDeleteDialog"; +import ConnectionStatusBadge from "./ConnectionStatusBadge"; +import CollapseButton from "./CollapseButton"; +import { TimelineMemberDialog } from "./TimelineMember"; +import TimelinePropertyChangeDialog from "./TimelinePropertyChangeDialog"; + +export interface TimelinePageCardProps { + timeline: HttpTimelineInfo; + collapse: boolean; + toggleCollapse: () => void; + connectionStatus: HubConnectionState; + className?: string; + onReload: () => void; +} const TimelineCard: React.FC = (props) => { - const { timeline } = props; + const { + timeline, + collapse, + toggleCollapse, + connectionStatus, + onReload, + className, + } = props; + + const { t } = useTranslation(); const [dialog, setDialog] = React.useState< "member" | "property" | "delete" | null >(null); + const isSmallScreen = useIsSmallScreen(); + + const user = useUser(); + + const content = ( + <> +

+ {timeline.title} + {timeline.name} +

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

{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} + setDialog("member")} + /> + {timeline.manageable ? ( + setDialog("property"), + }, + { type: "divider" }, + { + type: "button", + onClick: () => setDialog("delete"), + color: "danger", + text: "timeline.manageItem.delete", + }, + ]} + containerClassName="d-inline" + > + + + ) : null} +
+ + ); + return ( <> - -

- {timeline.title} - - {timeline.name} - -

-
- - {timeline.owner.nickname} - - @{timeline.owner.username} - -
- - } - manageItems={ - timeline.manageable - ? [ - { - type: "button", - text: "timeline.manageItem.property", - onClick: () => setDialog("property"), - }, - { type: "divider" }, - { - type: "button", - onClick: () => setDialog("delete"), - color: "danger", - text: "timeline.manageItem.delete", - }, - ] - : undefined - } - dialog={dialog} - setDialog={setDialog} - {...props} + +
+ + +
+ {isSmallScreen ? ( + + {content} + + ) : ( +
{content}
+ )} +
+ setDialog(null)} + open={dialog === "member"} + onChange={onReload} + /> + setDialog(null)} + open={dialog === "property"} + onChange={onReload} />