From 098dac5ab74100f157204e55ac737ad3fb0e3c05 Mon Sep 17 00:00:00 2001 From: pbzweihander Date: Wed, 29 Nov 2023 14:38:03 +0900 Subject: [PATCH] Implement posting note --- frontend/src/pages/login/LogInIndex.tsx | 55 +++++++++++++++++++++---- frontend/src/queries/note.ts | 23 +++++++++++ 2 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 frontend/src/queries/note.ts diff --git a/frontend/src/pages/login/LogInIndex.tsx b/frontend/src/pages/login/LogInIndex.tsx index a7973bf..3d6bc2d 100644 --- a/frontend/src/pages/login/LogInIndex.tsx +++ b/frontend/src/pages/login/LogInIndex.tsx @@ -1,22 +1,59 @@ +import { SubmitHandler, useForm } from "react-hook-form"; +import z from "zod"; + +import { CreatePost } from "../../dto"; +import { useNotes, usePostNoteMutation } from "../../queries/note"; + export function LogInIndexPage() { - const notes = new Array(40).fill("foobar"); // TODO: stub + const { data: notes } = useNotes(); + const { register, handleSubmit, reset } = + useForm>(); + const { + mutate: postNote, + isLoading, + error, + } = usePostNoteMutation(() => { + reset(); + }); + + const onSubmit: SubmitHandler> = (data) => { + postNote(data); + }; return (
- {notes.map((note, i) => ( -
-
- {note} {i} -
+ {(notes ?? []).map((note) => ( +
+ {note.user && ( +
+ {note.user.name != null ? ( + + {note.user.name} + + @{note.user.handle} + + + ) : ( + @{note.user.handle} + )} +
+ )} +
{note.text}
))}
-
+ +