From 416071d718ed8dd390d64abb47e4dd03d0842984 Mon Sep 17 00:00:00 2001 From: koreacomp5 Date: Thu, 9 Oct 2025 17:11:50 +0900 Subject: [PATCH] =?UTF-8?q?7.8=20=EC=9D=BC=EB=B0=98=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=ED=8C=90=20=EA=B3=B5=EC=9A=A9=20=ED=8F=BC/=EB=9D=BC=EC=9A=B0?= =?UTF-8?q?=ED=8A=B8=20=ED=85=9C=ED=94=8C=EB=A6=BF=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/boards/[id]/page.tsx | 16 ++++++++++++ src/app/boards/page.tsx | 16 ++++++++++++ src/app/components/PostForm.tsx | 44 +++++++++++++++++++++++++++++++++ src/app/posts/new/page.tsx | 4 +-- todolist.txt | 2 +- 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/app/boards/[id]/page.tsx create mode 100644 src/app/boards/page.tsx create mode 100644 src/app/components/PostForm.tsx diff --git a/src/app/boards/[id]/page.tsx b/src/app/boards/[id]/page.tsx new file mode 100644 index 0000000..1c7aa9f --- /dev/null +++ b/src/app/boards/[id]/page.tsx @@ -0,0 +1,16 @@ +import { PostList } from "@/app/components/PostList"; + +export default async function BoardDetail({ params, searchParams }: { params: { id: string }; searchParams?: { sort?: "recent" | "popular" } }) { + const sort = searchParams?.sort ?? "recent"; + return ( +
+
+

게시판

+ +
+ +
+ ); +} + + diff --git a/src/app/boards/page.tsx b/src/app/boards/page.tsx new file mode 100644 index 0000000..a5ea9a4 --- /dev/null +++ b/src/app/boards/page.tsx @@ -0,0 +1,16 @@ +export default async function BoardsPage() { + const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL ?? ""}/api/boards`, { cache: "no-store" }); + const { boards } = await res.json(); + return ( +
+

게시판

+ +
+ ); +} + + diff --git a/src/app/components/PostForm.tsx b/src/app/components/PostForm.tsx new file mode 100644 index 0000000..9e22da7 --- /dev/null +++ b/src/app/components/PostForm.tsx @@ -0,0 +1,44 @@ +"use client"; +import { useState } from "react"; +import { useRouter } from "next/navigation"; +import { useToast } from "@/app/components/ui/ToastProvider"; +import { UploadButton } from "@/app/components/UploadButton"; + +type Values = { title: string; content: string }; + +export function PostForm({ + initial, + onSubmit, + submitText = "등록", +}: { + initial?: Partial; + onSubmit: (values: Values) => Promise<{ id: string } | void>; + submitText?: string; +}) { + const router = useRouter(); + const { show } = useToast(); + const [form, setForm] = useState({ title: initial?.title ?? "", content: initial?.content ?? "" }); + const [loading, setLoading] = useState(false); + async function handleSubmit() { + try { + setLoading(true); + const res = await onSubmit(form); + show("저장되었습니다"); + if (res && res.id) router.push(`/posts/${res.id}`); + } catch (e) { + show("저장 실패"); + } finally { + setLoading(false); + } + } + return ( +
+ setForm({ ...form, title: e.target.value })} /> +