6.5 개인화 위젯(최근 본 글/알림 요약)

This commit is contained in:
koreacomp5
2025-10-09 16:40:53 +09:00
parent c16b9c1a51
commit 663cf0f19e
4 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
"use client";
import useSWR from "swr";
type RecentItem = { id: string; title: string; viewedAt: string };
type NotiItem = { id: string; type: string; message: string; createdAt: string };
const fetcher = (url: string) => fetch(url).then((r) => r.json());
export function PersonalWidgets() {
const { data: recent } = useSWR<{ items: RecentItem[] }>("/api/me/recent", fetcher);
const { data: notis } = useSWR<{ items: NotiItem[] }>("/api/me/notifications", fetcher);
return (
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16, marginTop: 16 }}>
<section>
<h3 style={{ marginTop: 0 }}> </h3>
<ul style={{ display: "flex", flexDirection: "column", gap: 6 }}>
{(recent?.items ?? []).map((i) => (
<li key={i.id}>
<a href={`/posts/${i.id}`}>{i.title}</a>
</li>
))}
{(!recent || recent.items.length === 0) && <li> .</li>}
</ul>
</section>
<section>
<h3 style={{ marginTop: 0 }}> </h3>
<ul style={{ display: "flex", flexDirection: "column", gap: 6 }}>
{(notis?.items ?? []).map((n) => (
<li key={n.id}>{n.message}</li>
))}
{(!notis || notis.items.length === 0) && <li> .</li>}
</ul>
</section>
</div>
);
}