diff --git a/frontend/src/i18n.ts b/frontend/src/i18n.ts index f5be7e5..55352db 100644 --- a/frontend/src/i18n.ts +++ b/frontend/src/i18n.ts @@ -202,6 +202,8 @@ export const i18nData = { "Optionally, you can specify a type for the new tags.": "Optionally, you can specify a type for the new tags.", "Upload Clipboard Image": "Upload Clipboard Image", + "Show more": "Show more", + "Show less": "Show less", }, }, "zh-CN": { @@ -396,6 +398,8 @@ export const i18nData = { "Optionally, you can specify a type for the new tags.": "您可以选择为新标签指定一个类型。", "Upload Clipboard Image": "上传剪贴板图片", + "Show more": "显示更多", + "Show less": "显示更少", }, }, "zh-TW": { @@ -590,6 +594,8 @@ export const i18nData = { "Optionally, you can specify a type for the new tags.": "您可以選擇為新標籤指定一個類型。", "Upload Clipboard Image": "上傳剪貼板圖片", + "Show more": "顯示更多", + "Show less": "顯示更少", }, }, }; diff --git a/frontend/src/pages/resource_details_page.tsx b/frontend/src/pages/resource_details_page.tsx index 7f945db..442fda8 100644 --- a/frontend/src/pages/resource_details_page.tsx +++ b/frontend/src/pages/resource_details_page.tsx @@ -23,7 +23,7 @@ import Markdown from "react-markdown"; import "../markdown.css"; import Loading from "../components/loading.tsx"; import { - MdAdd, + MdAdd, MdArrowDownward, MdArrowUpward, MdOutlineArticle, MdOutlineComment, MdOutlineDataset, @@ -360,11 +360,12 @@ function Article({ resource }: { resource: ResourceDetails }) { > ); } - // @ts-ignore } else if ( typeof props.children === "object" && - props.children.props && - props.children.props.href + // @ts-ignore + props.children?.props && + // @ts-ignore + props.children?.props.href ) { const a = props.children as ReactElement; const childProps = a.props as any; @@ -1140,11 +1141,11 @@ function Comments({ resourceId }: { resourceId: number }) { maxPageCallback={setMaxPage} key={listKey} /> - {maxPage && ( + {maxPage ? (
- )} + ) : null} ); } @@ -1193,6 +1194,15 @@ function CommentsList({ function CommentTile({ comment }: { comment: Comment }) { const navigate = useNavigate(); + const [expanded, setExpanded] = useState(false); + const { t } = useTranslation(); + + const isLongComment = comment.content.length > 300; + const displayContent = + expanded || !isLongComment + ? comment.content + : comment.content.substring(0, 300) + "..."; + return (
@@ -1216,7 +1226,21 @@ function CommentTile({ comment }: { comment: Comment }) { {new Date(comment.created_at).toLocaleString()}
-
{comment.content}
+
+ {displayContent} + {isLongComment && ( +
+ +
+ )} +
); } diff --git a/frontend/src/pages/user_page.tsx b/frontend/src/pages/user_page.tsx index e2bc743..b5d66d6 100644 --- a/frontend/src/pages/user_page.tsx +++ b/frontend/src/pages/user_page.tsx @@ -73,7 +73,7 @@ function UserCard({ user }: { user: User }) {
- + {"avatar"}
@@ -175,6 +175,13 @@ function CommentsList({ ); } +function limitArticleLength(content: string, maxLength: number): string { + if (content.length <= maxLength) { + return content; + } + return content.slice(0, maxLength) + "..."; +} + function CommentTile({ comment }: { comment: CommentWithResource }) { const navigate = useNavigate(); @@ -193,7 +200,9 @@ function CommentTile({ comment }: { comment: CommentWithResource }) { {new Date(comment.created_at).toLocaleString()}
-
{comment.content}
+
+ {limitArticleLength(comment.content, 200)} +
{