diff options
| author | crupest <crupest@outlook.com> | 2020-09-01 02:32:06 +0800 |
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2020-09-01 02:32:06 +0800 |
| commit | a314b5350e269676e8c39eda4cc7842751b1a7fc (patch) | |
| tree | ab3e8c96f18c8e9f6e8c613ace0e04329614304c /Timeline/ClientApp/src/app/views/timeline/TimelineInfoCard.tsx | |
| parent | 02a9bf9ecfe1659b3481a5386e7a06ee2f0e5fc5 (diff) | |
| download | timeline-a314b5350e269676e8c39eda4cc7842751b1a7fc.tar.gz timeline-a314b5350e269676e8c39eda4cc7842751b1a7fc.tar.bz2 timeline-a314b5350e269676e8c39eda4cc7842751b1a7fc.zip | |
...
Diffstat (limited to 'Timeline/ClientApp/src/app/views/timeline/TimelineInfoCard.tsx')
| -rw-r--r-- | Timeline/ClientApp/src/app/views/timeline/TimelineInfoCard.tsx | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/Timeline/ClientApp/src/app/views/timeline/TimelineInfoCard.tsx b/Timeline/ClientApp/src/app/views/timeline/TimelineInfoCard.tsx new file mode 100644 index 00000000..e3e89057 --- /dev/null +++ b/Timeline/ClientApp/src/app/views/timeline/TimelineInfoCard.tsx @@ -0,0 +1,110 @@ +import React from "react"; +import clsx from "clsx"; +import { + Dropdown, + DropdownToggle, + DropdownMenu, + DropdownItem, + Button, +} from "reactstrap"; +import { useTranslation } from "react-i18next"; +import { fromEvent } from "rxjs"; + +import { useAvatar } from "@/services/user"; +import { timelineVisibilityTooltipTranslationMap } from "@/services/timeline"; + +import BlobImage from "../common/BlobImage"; +import { TimelineCardComponentProps } from "../timeline-common/TimelinePageTemplateUI"; + +export type OrdinaryTimelineManageItem = "delete"; + +export type TimelineInfoCardProps = TimelineCardComponentProps< + OrdinaryTimelineManageItem +>; + +const TimelineInfoCard: React.FC<TimelineInfoCardProps> = (props) => { + const { onHeight, onManage } = props; + + const { t } = useTranslation(); + + const avatar = useAvatar(props.timeline.owner.username); + + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const containerRef = React.useRef<HTMLDivElement>(null!); + + const notifyHeight = React.useCallback((): void => { + if (onHeight) { + onHeight(containerRef.current.getBoundingClientRect().height); + } + }, [onHeight]); + + React.useEffect(() => { + const subscription = fromEvent(window, "resize").subscribe(notifyHeight); + return () => subscription.unsubscribe(); + }); + + const [manageDropdownOpen, setManageDropdownOpen] = React.useState<boolean>( + false + ); + const toggleManageDropdown = React.useCallback( + (): void => setManageDropdownOpen((old) => !old), + [] + ); + + return ( + <div + ref={containerRef} + className={clsx("rounded border p-2 bg-light", props.className)} + onTransitionEnd={notifyHeight} + > + <h3 className="text-primary mx-3 d-inline-block align-middle"> + {props.timeline.name} + </h3> + <div className="d-inline-block align-middle"> + <BlobImage + blob={avatar} + onLoad={notifyHeight} + className="avatar small rounded-circle" + /> + {props.timeline.owner.nickname} + <small className="ml-3 text-secondary"> + @{props.timeline.owner.username} + </small> + </div> + <p className="mb-0">{props.timeline.description}</p> + <small className="mt-1 d-block"> + {t(timelineVisibilityTooltipTranslationMap[props.timeline.visibility])} + </small> + <div className="text-right mt-2"> + {onManage != null ? ( + <Dropdown isOpen={manageDropdownOpen} toggle={toggleManageDropdown}> + <DropdownToggle outline color="primary"> + {t("timeline.manage")} + </DropdownToggle> + <DropdownMenu> + <DropdownItem onClick={() => onManage("property")}> + {t("timeline.manageItem.property")} + </DropdownItem> + <DropdownItem onClick={props.onMember}> + {t("timeline.manageItem.member")} + </DropdownItem> + <DropdownItem divider /> + <DropdownItem + className="text-danger" + onClick={() => onManage("delete")} + > + {t("timeline.manageItem.delete")} + </DropdownItem> + </DropdownMenu> + </Dropdown> + ) : ( + <Button color="primary" outline onClick={props.onMember}> + {t("timeline.memberButton")} + </Button> + )} + </div> + </div> + ); +}; + +export default TimelineInfoCard; |
