7.2 목록 페이징/정렬/검색(제목/태그/작성자/기간) o
This commit is contained in:
@@ -20,7 +20,7 @@ type Resp = {
|
||||
|
||||
const fetcher = (url: string) => fetch(url).then((r) => r.json());
|
||||
|
||||
export function PostList({ boardId, sort = "recent", q }: { boardId?: string; sort?: "recent" | "popular"; q?: string }) {
|
||||
export function PostList({ boardId, sort = "recent", q, tag, author, start, end }: { boardId?: string; sort?: "recent" | "popular"; q?: string; tag?: string; author?: string; start?: string; end?: string }) {
|
||||
const pageSize = 10;
|
||||
const getKey = (index: number, prev: Resp | null) => {
|
||||
if (prev && prev.items.length === 0) return null;
|
||||
@@ -28,6 +28,10 @@ export function PostList({ boardId, sort = "recent", q }: { boardId?: string; so
|
||||
const sp = new URLSearchParams({ page: String(page), pageSize: String(pageSize), sort });
|
||||
if (boardId) sp.set("boardId", boardId);
|
||||
if (q) sp.set("q", q);
|
||||
if (tag) sp.set("tag", tag);
|
||||
if (author) sp.set("author", author);
|
||||
if (start) sp.set("start", start);
|
||||
if (end) sp.set("end", end);
|
||||
return `/api/posts?${sp.toString()}`;
|
||||
};
|
||||
const { data, size, setSize, isLoading } = useSWRInfinite<Resp>(getKey, fetcher);
|
||||
|
||||
Reference in New Issue
Block a user