From 232a19d7dfe0e3847b3a9a9a9be83485ffb9031c Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 30 May 2020 16:23:25 +0800 Subject: Merge front end to this repo. But I need to wait for aspnet core support for custom port and package manager for dev server. --- Timeline/ClientApp/src/user/UserInfoCard.tsx | 126 +++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Timeline/ClientApp/src/user/UserInfoCard.tsx (limited to 'Timeline/ClientApp/src/user/UserInfoCard.tsx') diff --git a/Timeline/ClientApp/src/user/UserInfoCard.tsx b/Timeline/ClientApp/src/user/UserInfoCard.tsx new file mode 100644 index 00000000..280cddce --- /dev/null +++ b/Timeline/ClientApp/src/user/UserInfoCard.tsx @@ -0,0 +1,126 @@ +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 { + TimelineInfo, + timelineVisibilityTooltipTranslationMap, +} from '../data/timeline'; +import { useAvatarVersion, useAvatarUrlWithGivenVersion } from './api'; +import { useUser } from '../data/user'; + +import { TimelineCardComponentProps } from '../timeline/TimelinePageTemplateUI'; + +export type PersonalTimelineManageItem = 'avatar' | 'nickname'; + +export type UserInfoCardProps = TimelineCardComponentProps< + TimelineInfo, + PersonalTimelineManageItem +>; + +const UserInfoCard: React.FC = (props) => { + const { onHeight, onManage } = props; + const { t } = useTranslation(); + const user = useUser(); + + const avatarVersion = useAvatarVersion(); + const avatarUrl = useAvatarUrlWithGivenVersion( + user != null && user.username === props.timeline.owner.username + ? avatarVersion + : undefined, + props.timeline.owner._links.avatar + ); + + const containerRef = React.useRef(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( + false + ); + const toggleManageDropdown = React.useCallback( + (): void => setManageDropdownOpen((old) => !old), + [] + ); + const onManageProperty = React.useCallback( + (): void => onManage!('property'), + [onManage] + ); + const onManageAvatar = React.useCallback((): void => onManage!('avatar'), [ + onManage, + ]); + const onManageNickname = React.useCallback( + (): void => onManage!('nickname'), + [onManage] + ); + + return ( +
+ +
+ {props.timeline.owner.nickname} + + @{props.timeline.owner.username} + +
+

{props.timeline.description}

+ + {t(timelineVisibilityTooltipTranslationMap[props.timeline.visibility])} + +
+ {props.onManage != null ? ( + + + {t('timeline.manage')} + + + + {t('timeline.manageItem.nickname')} + + + {t('timeline.manageItem.avatar')} + + + {t('timeline.manageItem.property')} + + + {t('timeline.manageItem.member')} + + + + ) : ( + + )} +
+
+ ); +}; + +export default UserInfoCard; -- cgit v1.2.3