From 225179dd6d910e86f6d12838127ab6817c7f812d Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Thu, 25 May 2023 08:24:24 +0700 Subject: [PATCH] update create block form --- src/app/chat/components/item.tsx | 2 +- src/app/chat/components/self.tsx | 8 +- src/app/space/components/create.tsx | 64 ++++++++++------ src/app/space/components/imageUploader.tsx | 86 ++++++++++++++++++++++ 4 files changed, 133 insertions(+), 27 deletions(-) create mode 100644 src/app/space/components/imageUploader.tsx diff --git a/src/app/chat/components/item.tsx b/src/app/chat/components/item.tsx index 370e3682..8809634d 100644 --- a/src/app/chat/components/item.tsx +++ b/src/app/chat/components/item.tsx @@ -44,7 +44,7 @@ export default function ChatsListItem({ pubkey }: { pubkey: string }) { />
-
+
{user.nip05 || user.name || shortenKey(pubkey)}
diff --git a/src/app/chat/components/self.tsx b/src/app/chat/components/self.tsx index 58148fc5..0a1dbed8 100644 --- a/src/app/chat/components/self.tsx +++ b/src/app/chat/components/self.tsx @@ -44,11 +44,11 @@ export default function ChatsListSelfItem() { className="h-5 w-5 rounded bg-white object-cover" /> -
-
- {profile?.nip05 || profile?.name || shortenKey(account.pubkey)}{" "} - (you) +
+
+ {profile?.nip05 || profile?.name || shortenKey(account.pubkey)}
+ (you)
)} diff --git a/src/app/space/components/create.tsx b/src/app/space/components/create.tsx index 3b727e3e..1a1026d5 100644 --- a/src/app/space/components/create.tsx +++ b/src/app/space/components/create.tsx @@ -1,24 +1,27 @@ +import { BlockImageUploader } from "./imageUploader"; import { Dialog, Transition } from "@headlessui/react"; import CancelIcon from "@icons/cancel"; import PlusIcon from "@icons/plus"; +import { Image } from "@shared/image"; +import { DEFAULT_AVATAR } from "@stores/constants"; import { useActiveAccount } from "@utils/hooks/useActiveAccount"; -import { createBlock } from "@utils/storage"; -import { Fragment, useState } from "react"; +import { createBlock, getPlebs } from "@utils/storage"; +import { Fragment, useEffect, useState } from "react"; import { useForm } from "react-hook-form"; +import useSWR from "swr"; + +const fetcher = () => getPlebs(); export function CreateBlockModal() { - const { - register, - handleSubmit, - reset, - setValue, - formState: { isDirty, isValid }, - } = useForm(); + const { account } = useActiveAccount(); + const { register, handleSubmit, reset, watch, setValue } = useForm(); + const { data: plebs } = useSWR("plebs", fetcher); + const [image, setImage] = useState(DEFAULT_AVATAR); const [isOpen, setIsOpen] = useState(false); const [loading, setLoading] = useState(false); - const { account } = useActiveAccount(); + const kind = watch("kind"); const closeModal = () => { setIsOpen(false); @@ -41,6 +44,10 @@ export function CreateBlockModal() { }); }; + useEffect(() => { + setValue("content", image); + }, [setValue, image]); + return ( <>