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/timeline/TimelineItem.tsx | 113 +++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 Timeline/ClientApp/src/timeline/TimelineItem.tsx (limited to 'Timeline/ClientApp/src/timeline/TimelineItem.tsx') diff --git a/Timeline/ClientApp/src/timeline/TimelineItem.tsx b/Timeline/ClientApp/src/timeline/TimelineItem.tsx new file mode 100644 index 00000000..402d51d9 --- /dev/null +++ b/Timeline/ClientApp/src/timeline/TimelineItem.tsx @@ -0,0 +1,113 @@ +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import clsx from 'clsx'; +import { Row, Col } from 'reactstrap'; +import { Link } from 'react-router-dom'; + +import { TimelinePostInfo } from '../data/timeline'; +import { useAvatarUrlWithGivenVersion } from '../user/api'; + +export interface TimelineItemProps { + post: TimelinePostInfo; + showDeleteButton?: boolean; + current?: boolean; + toggleMore?: () => void; + onDelete?: () => void; + onClick?: () => void; + avatarVersion?: number; +} + +const TimelineItem: React.FC = (props) => { + const { i18n } = useTranslation(); + + const current = props.current === true; + + const { toggleMore: toggleDelete } = props; + + const avatarUrl = useAvatarUrlWithGivenVersion( + props.avatarVersion, + props.post.author._links.avatar + ); + + const onOpenMore = React.useMemo< + React.MouseEventHandler | undefined + >(() => { + if (toggleDelete == null) { + return undefined; + } else { + return (e) => { + toggleDelete(); + e.stopPropagation(); + }; + } + }, [toggleDelete]); + + return ( + + +
+
+
+
+
+ {current &&
} + + + +
+ + + {props.post.time.toLocaleString(i18n.languages)} + + + {props.post.author.nickname} + + +
+ {props.toggleMore != null ? ( +
+ +
+ ) : null} +
+

+ + + + {(() => { + const { content } = props.post; + if (content.type === 'text') { + return content.text; + } else { + return ( + + ); + } + })()} +

+ + {props.showDeleteButton ? ( +
+ +
+ ) : undefined} + + ); +}; + +export default TimelineItem; -- cgit v1.2.3