import { LoaderFunctionArgs, MetaFunction, json } from "@remix-run/node"; import { useLoaderData } from "@remix-run/react"; import { useState } from "react"; import Article from "~/components/common/article"; import { CupFill, ShareFill, ThumbUpFill } from "~/components/common/icons"; import { siteTitle } from "~/utils"; export const meta: MetaFunction = ({ data }) => { return [ { title: data ? siteTitle(data.data.title) : "404" }, { name: "description", content: data?.data.except }, ]; } export async function loader({ params }: LoaderFunctionArgs) { if (Number.isNaN(Number(params.year)) || Number.isNaN(Number(params.id))) { throw json("Not Found", { status: 404, statusText: "链接格式错误" }); } const note = await fetch(`https://paul.ren/api/note/get?id=${params.id}&year=${params.year}`).then((res) => res.json()) as API.Response; if (note.status === "Failed") { throw json("Not Found", { status: 404, statusText: note.msg }); } return json(note); } export default function Detail() { const note = useLoaderData(); const [likes, setLikes] = useState(note.data.likes); const onLike = () => { setLikes((prevLike) => prevLike + 1); } const onShare = () => { const shareData = { title: note.data.title, text: note.data.except, url: `${location.protocol}//${location.host}${location.pathname}`, }; if ("share" in navigator) { navigator.share(shareData); } else { alert("当前操作系统尚未实现此 API"); } } return (

{note.data.title}

{note.data.date}

); };