import * as Dialog from '@radix-ui/react-dialog'; import { useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; import { useHotkeys } from 'react-hotkeys-hook'; import { CancelIcon, CommandIcon, LoaderIcon } from '@shared/icons'; import { Image } from '@shared/image'; import { BLOCK_KINDS, DEFAULT_AVATAR } from '@stores/constants'; import { ADD_IMAGEBLOCK_SHORTCUT } from '@stores/shortcuts'; import { useWidgets } from '@stores/widgets'; import { useImageUploader } from '@utils/hooks/useUploader'; export function ImageModal() { const upload = useImageUploader(); const setWidget = useWidgets((state) => state.setWidget); const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); const [image, setImage] = useState(''); useHotkeys(ADD_IMAGEBLOCK_SHORTCUT, () => setOpen(false)); const { register, handleSubmit, reset, setValue, formState: { isDirty, isValid }, } = useForm(); const uploadImage = async () => { const image = await upload(null, true); if (image.url) { setImage(image.url); } }; const onSubmit = async (data: { kind: number; title: string; content: string }) => { setLoading(true); // mutate setWidget({ kind: BLOCK_KINDS.image, title: data.title, content: data.content }); setLoading(false); // reset form reset(); // close modal setOpen(false); }; useEffect(() => { setValue('content', image); }, [setValue, image]); return (
Create image block
Pin your favorite image to Space then you can view every time that you use Lume, your image will be broadcast to Nostr Relay as well
content
); }