From d44d687762f3abd833540085bc6d70eaeb8aa64d Mon Sep 17 00:00:00 2001 From: sansai-SNCT Date: Fri, 16 Dec 2022 23:57:45 +0900 Subject: [PATCH] fix: Fix submit logic and fetch data --- src/pages/edit/[id].tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/pages/edit/[id].tsx b/src/pages/edit/[id].tsx index 70b48c6e..d519d1ff 100644 --- a/src/pages/edit/[id].tsx +++ b/src/pages/edit/[id].tsx @@ -15,10 +15,15 @@ import Image from "next/image"; import { onAuthStateChanged } from "firebase/auth"; import type { User } from "firebase/auth"; import { auth } from "../../libs/firebase/init"; -import { getCardList, createCardListItem } from "../../libs/firebase/store"; +import { + getCardList, + createCardListItem, + getInfo, +} from "../../libs/firebase/store"; import type { StoreCardList, CreateStoreCardListItem, + ListInfo, } from "../../libs/firebase/types"; import { EditCard } from "../../components/card/edit"; import { createGetLayout } from "../../components/layout/edit"; @@ -36,8 +41,7 @@ const Edit: NextPageWithLayout = () => { const [file, setFile] = useState(); const listid = id; - // TODO: fetchData - const title = "Title"; + const [title, setTitle] = useState(""); const { register, handleSubmit, reset } = useForm(); @@ -53,12 +57,7 @@ const Edit: NextPageWithLayout = () => { }; const onSubmit: SubmitHandler = async (result) => { - if ( - !user || - !(typeof id === "string") || - !file || - !inputRef.current?.value - ) { + if (!user || !(typeof id === "string")) { return; } const data: CreateStoreCardListItem = { @@ -75,6 +74,8 @@ const Edit: NextPageWithLayout = () => { const authStateChanged = onAuthStateChanged(auth, async (u) => { if (u && typeof listid === "string") { const res = await getCardList(u.uid, listid); + const info: ListInfo = await getInfo(u.uid, listid); + if (typeof info !== "undefined") setTitle(info.title); setList(res); setUser(u); }