format code

This commit is contained in:
2025-07-04 15:27:11 +08:00
parent 54ab93ea7b
commit d661ac3e17
5 changed files with 82 additions and 58 deletions

View File

@@ -25,7 +25,7 @@ export function CommentInput({
// Auto-resize textarea based on content // Auto-resize textarea based on content
const adjustTextareaHeight = () => { const adjustTextareaHeight = () => {
if (textareaRef.current) { if (textareaRef.current) {
textareaRef.current.style.height = 'auto'; textareaRef.current.style.height = "auto";
let height = textareaRef.current.scrollHeight; let height = textareaRef.current.scrollHeight;
if (height < 128) { if (height < 128) {
height = 128; height = 128;
@@ -37,7 +37,7 @@ export function CommentInput({
// Reset textarea height to default // Reset textarea height to default
const resetTextareaHeight = () => { const resetTextareaHeight = () => {
if (textareaRef.current) { if (textareaRef.current) {
textareaRef.current.style.height = '128px'; textareaRef.current.style.height = "128px";
} }
}; };
@@ -175,9 +175,7 @@ export function CommentInput({
</button> </button>
<Badge className="badge-ghost"> <Badge className="badge-ghost">
<MdOutlineInfo size={18} /> <MdOutlineInfo size={18} />
<span> <span>{t("Use markdown format")}</span>
{t("Use markdown format")}
</span>
</Badge> </Badge>
<span className={"grow"} /> <span className={"grow"} />
<button <button

View File

@@ -1,7 +1,11 @@
import { useState } from "react"; import { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router"; import { useNavigate } from "react-router";
import { MdOutlineComment, MdOutlineDelete, MdOutlineEdit, MdOutlineReply } from "react-icons/md"; import {
MdOutlineComment,
MdOutlineDelete,
MdOutlineEdit,
} from "react-icons/md";
import { TextArea } from "./input"; import { TextArea } from "./input";
import { Comment } from "../network/models"; import { Comment } from "../network/models";
import { network } from "../network/network"; import { network } from "../network/network";
@@ -30,7 +34,9 @@ export function CommentTile({
href={link} href={link}
className={ className={
"block card bg-base-100 p-2 my-3 transition-shadow cursor-pointer" + "block card bg-base-100 p-2 my-3 transition-shadow cursor-pointer" +
(!elevation || elevation == "normal" ? " shadow-xs hover:shadow" : " shadow hover:shadow-md") (!elevation || elevation == "normal"
? " shadow-xs hover:shadow"
: " shadow hover:shadow-md")
} }
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
@@ -44,19 +50,14 @@ export function CommentTile({
onClick={(e) => { onClick={(e) => {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
navigate(userLink) navigate(userLink);
} }}
}
> >
<span className="w-8 h-8 rounded-full"> <span className="w-8 h-8 rounded-full">
<img src={network.getUserAvatar(comment.user)} alt={"avatar"} /> <img src={network.getUserAvatar(comment.user)} alt={"avatar"} />
</span> </span>
<span className={"w-2"}></span> <span className={"w-2"}></span>
<span <span className={"text-sm font-bold"}>{comment.user.username}</span>
className={"text-sm font-bold"}
>
{comment.user.username}
</span>
</a> </a>
<div className={"grow"}></div> <div className={"grow"}></div>
@@ -144,10 +145,14 @@ function EditCommentDialog({
<MdOutlineEdit size={16} className={"inline-block"} /> <MdOutlineEdit size={16} className={"inline-block"} />
{t("Edit")} {t("Edit")}
</button> </button>
<dialog id={`edit_comment_dialog_${comment.id}`} className="modal" onClick={(e) => { <dialog
id={`edit_comment_dialog_${comment.id}`}
className="modal"
onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
}}> }}
>
<div className="modal-box" id={"dialog_box"}> <div className="modal-box" id={"dialog_box"}>
<h3 className="font-bold text-lg">{t("Edit Comment")}</h3> <h3 className="font-bold text-lg">{t("Edit Comment")}</h3>
<TextArea <TextArea
@@ -156,12 +161,17 @@ function EditCommentDialog({
onChange={(e) => setContent(e.target.value)} onChange={(e) => setContent(e.target.value)}
/> />
<div className="modal-action"> <div className="modal-action">
<button className="btn btn-ghost" onClick={() => { <button
className="btn btn-ghost"
onClick={() => {
const dialog = document.getElementById( const dialog = document.getElementById(
`edit_comment_dialog_${comment.id}`, `edit_comment_dialog_${comment.id}`,
) as HTMLDialogElement; ) as HTMLDialogElement;
dialog.close(); dialog.close();
}}>{t("Close")}</button> }}
>
{t("Close")}
</button>
<button className="btn btn-primary" onClick={handleUpdate}> <button className="btn btn-primary" onClick={handleUpdate}>
{isLoading ? ( {isLoading ? (
<span className={"loading loading-spinner loading-sm"}></span> <span className={"loading loading-spinner loading-sm"}></span>
@@ -221,10 +231,14 @@ function DeleteCommentDialog({
<MdOutlineDelete size={16} className={"inline-block"} /> <MdOutlineDelete size={16} className={"inline-block"} />
{t("Delete")} {t("Delete")}
</button> </button>
<dialog id={id} className="modal" onClick={(e) => { <dialog
id={id}
className="modal"
onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
}}> }}
>
<div className="modal-box"> <div className="modal-box">
<h3 className="font-bold text-lg">{t("Delete Comment")}</h3> <h3 className="font-bold text-lg">{t("Delete Comment")}</h3>
<p className="py-4"> <p className="py-4">
@@ -233,10 +247,15 @@ function DeleteCommentDialog({
)} )}
</p> </p>
<div className="modal-action"> <div className="modal-action">
<button className="btn btn-ghost" onClick={() => { <button
className="btn btn-ghost"
onClick={() => {
const dialog = document.getElementById(id) as HTMLDialogElement; const dialog = document.getElementById(id) as HTMLDialogElement;
dialog.close(); dialog.close();
}}>{t("Close")}</button> }}
>
{t("Close")}
</button>
<button className="btn btn-error" onClick={handleDelete}> <button className="btn btn-error" onClick={handleDelete}>
{isLoading ? ( {isLoading ? (
<span className={"loading loading-spinner loading-sm"}></span> <span className={"loading loading-spinner loading-sm"}></span>

View File

@@ -165,7 +165,8 @@ function CommentReply({ comment }: { comment: CommentWithRef }) {
setListKey((prev) => prev + 1); setListKey((prev) => prev + 1);
}, []); }, []);
return <> return (
<>
<h2 className="text-xl font-bold my-2">{t("Replies")}</h2> <h2 className="text-xl font-bold my-2">{t("Replies")}</h2>
<CommentInput replyTo={comment.id} reload={reload} /> <CommentInput replyTo={comment.id} reload={reload} />
<CommentsList <CommentsList
@@ -183,6 +184,7 @@ function CommentReply({ comment }: { comment: CommentWithRef }) {
</div> </div>
) : null} ) : null}
</> </>
);
} }
function CommentsList({ function CommentsList({
@@ -224,7 +226,12 @@ function CommentsList({
<> <>
{comments.map((comment) => { {comments.map((comment) => {
return ( return (
<CommentTile elevation="high" comment={comment} key={comment.id} onUpdated={reload} /> <CommentTile
elevation="high"
comment={comment}
key={comment.id}
onUpdated={reload}
/>
); );
})} })}
</> </>