From 1decddb8109de9a14b4fcbeda7dcb9443fe87b7b Mon Sep 17 00:00:00 2001 From: nyne Date: Fri, 4 Jul 2025 15:42:46 +0800 Subject: [PATCH] Improve comment UI. --- frontend/src/components/comment_tile.tsx | 4 +- frontend/src/i18n.ts | 3 ++ frontend/src/markdown.css | 30 +++++++++++++-- frontend/src/pages/user_page.tsx | 47 ++---------------------- 4 files changed, 35 insertions(+), 49 deletions(-) diff --git a/frontend/src/components/comment_tile.tsx b/frontend/src/components/comment_tile.tsx index 6c15386..6906b49 100644 --- a/frontend/src/components/comment_tile.tsx +++ b/frontend/src/components/comment_tile.tsx @@ -53,7 +53,7 @@ export function CommentTile({ navigate(userLink); }} > - + {"avatar"} @@ -70,7 +70,7 @@ export function CommentTile({
{comment.content_truncated && ( - {t("Click to view more")} + {t("Click to view more")} )} {comment.reply_count > 0 && ( diff --git a/frontend/src/i18n.ts b/frontend/src/i18n.ts index e5a56a7..4eef591 100644 --- a/frontend/src/i18n.ts +++ b/frontend/src/i18n.ts @@ -230,6 +230,7 @@ export const i18nData = { "Reply": "Reply", "Commented on": "Commented on", "Write down your comment": "Write down your comment", + "Click to view more": "Click to view more", }, }, "zh-CN": { @@ -452,6 +453,7 @@ export const i18nData = { "Reply": "回复", "Commented on": "评论于", "Write down your comment": "写下您的评论", + "Click to view more": "点击查看更多", }, }, "zh-TW": { @@ -674,6 +676,7 @@ export const i18nData = { "Reply": "回覆", "Commented on": "評論於", "Write down your comment": "寫下您的評論", + "Click to view more": "點擊查看更多", }, }, }; diff --git a/frontend/src/markdown.css b/frontend/src/markdown.css index 6f427d6..dbd20eb 100644 --- a/frontend/src/markdown.css +++ b/frontend/src/markdown.css @@ -115,6 +115,18 @@ article { ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, system-ui; } + code { + width: 100%; + display: block; + overflow-x: auto; + background-color: var(--color-base-200); + padding: 4px 8px; + border-radius: 4px; + font-family: + ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, system-ui; + font-size: 12px; + } + iframe { width: 100%; height: 100%; @@ -138,21 +150,21 @@ article { font-size: 18px; font-weight: bold; padding: 6px 0; - margin: 12px 0 6px; + margin: 6px 0 6px; } h3 { font-size: 15px; font-weight: bold; padding: 4px 0; - margin: 8px 0 4px; + margin: 4px 0 4px; } h4 { font-size: 13px; font-weight: bold; padding: 3px 0; - margin: 8px 0 4px; + margin: 4px 0 4px; } h5 { @@ -243,6 +255,18 @@ article { ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, system-ui; font-size: 12px; } + + code { + width: 100%; + display: block; + overflow-x: auto; + background-color: var(--color-base-200); + padding: 4px 8px; + border-radius: 4px; + font-family: + ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, system-ui; + font-size: 12px; + } } a.no-underline { diff --git a/frontend/src/pages/user_page.tsx b/frontend/src/pages/user_page.tsx index 8f53262..bbad258 100644 --- a/frontend/src/pages/user_page.tsx +++ b/frontend/src/pages/user_page.tsx @@ -8,6 +8,7 @@ import Loading from "../components/loading"; import Pagination from "../components/pagination"; import { MdOutlineArrowRight } from "react-icons/md"; import { ImageGrid } from "../components/image.tsx"; +import { CommentTile } from "../components/comment_tile.tsx"; export default function UserPage() { const [user, setUser] = useState(null); @@ -174,50 +175,8 @@ function CommentsList({ return ( <> {comments.map((comment) => { - return ; + return ; })} ); -} - -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(); - - return ( -
-
-
-
- {"avatar"} -
-
-
-
{comment.user.username}
-
-
- {new Date(comment.created_at).toLocaleString()} -
-
-
- {limitArticleLength(comment.content, 200)} -
- - { - navigate("/resources/" + comment.resource.id); - }} - > - - {comment.resource.title} - -
- ); -} +} \ No newline at end of file