From e6f3459f811c34b3ae76b521cdfb668f95b79f77 Mon Sep 17 00:00:00 2001 From: tone Date: Fri, 12 Dec 2025 20:48:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E5=89=8D=E7=AB=AFblo?= =?UTF-8?q?g=E5=88=97=E8=A1=A8=E4=B8=BA=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/(with-header-footer)/blog/page.tsx | 25 ++++--------------- apps/frontend/lib/api/blog/list.ts | 4 +-- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/apps/frontend/app/(with-header-footer)/blog/page.tsx b/apps/frontend/app/(with-header-footer)/blog/page.tsx index 85fed75..3f4a4d9 100644 --- a/apps/frontend/app/(with-header-footer)/blog/page.tsx +++ b/apps/frontend/app/(with-header-footer)/blog/page.tsx @@ -1,9 +1,5 @@ -"use client" - -import { Skeleton } from "@/components/ui/skeleton"; import { BlogApi } from "@/lib/api"; import { useCallback } from "react" -import useSWR from "swr"; import { Alert, AlertDescription, @@ -12,7 +8,7 @@ import { import { AlertCircle } from "lucide-react"; import { base62 } from "@/lib/utils"; -export default function Blog() { +export default async function Blog() { const formatNumber = useCallback((num: number) => { if (num >= 1000) { return (num / 1000).toFixed(1) + 'K'; @@ -22,29 +18,18 @@ export default function Blog() { return num.toString(); }, []); - const { data: blogs, error, isLoading } = useSWR( - '/api/blogs', - () => BlogApi.list(), - ) + let errorMsg = ''; + const blogs = await BlogApi.list().catch(e => { errorMsg = `${e}`; return null }); return (
{ - isLoading && ( -
- - - -
- ) - } - { - error && ( + errorMsg && ( 出错啦 - {error.message} + {errorMsg} ) diff --git a/apps/frontend/lib/api/blog/list.ts b/apps/frontend/lib/api/blog/list.ts index 5fcd43c..5c17716 100644 --- a/apps/frontend/lib/api/blog/list.ts +++ b/apps/frontend/lib/api/blog/list.ts @@ -1,6 +1,6 @@ import { Blog } from "@/lib/types/blog"; -import fetcher from "../fetcher"; +import { apiFetch } from "../client"; export async function list() { - return fetcher('/api/blog'); + return apiFetch('/api/blog'); } \ No newline at end of file