diff --git a/app/components/shared/comment/index.tsx b/app/components/shared/comment/index.tsx index f988422..5fbec19 100644 --- a/app/components/shared/comment/index.tsx +++ b/app/components/shared/comment/index.tsx @@ -163,7 +163,7 @@ export default function Comments({ className, refs }: CommentsProps) { }; return ( -
评论
diff --git a/app/routes/note-detail.tsx b/app/routes/note-detail.tsx index 085e121..c404a9f 100644 --- a/app/routes/note-detail.tsx +++ b/app/routes/note-detail.tsx @@ -4,12 +4,14 @@ import { useParams } from "react-router"; import Article from "~/components/common/article"; import LightBox, { useLightBox } from "~/components/biz/gallery/image-box"; import Comments from "~/components/shared/comment"; +import { add } from "~/components/ui/notice/utils"; import { CupFill, ShareFill, ThumbUpFill } from "~/components/ui/icons"; import { useHydrated } from "~/hooks/use-hydrated"; -import { siteTitle } from "~/utils"; +import { clsn, siteTitle } from "~/utils"; import { getImageThumbUrl } from "~/utils/media"; import type { Route } from "./+types/note-detail"; +import { RiLoader5Fill } from "@remixicon/react"; const { APP_APIURL } = import.meta.env; @@ -43,6 +45,8 @@ export default function NoteDetail({ loaderData }: Route.ComponentProps) { const { ref: mediaLightBoxRef, open: onShowMediaLightBox } = useLightBox(); const [likes, setLikes] = useState(note.data.likes); + const [liked, setLiked] = useState(false); + const [liking, setLiking] = useState(false); const mediaList = note.data.media?.length ? note.data.media.map((item) => ({ @@ -54,8 +58,55 @@ export default function NoteDetail({ loaderData }: Route.ComponentProps) { const hasMedia = mediaList.length > 0; const commentRef = `note-${params.year}-${params.id}`; - const onLike = () => { + const onLike = async () => { + if (liking) { + return; + } + + setLiking(true); setLikes((prevLike) => prevLike + 1); + + const formData = new FormData(); + formData.append("id", String(params.id)); + formData.append("year", String(params.year)); + + try { + const res = (await fetch(`${APP_APIURL}/api/note/like`, { + method: "POST", + body: formData, + }).then((r) => r.json())) as API.Response