import { Combobox } from '@headlessui/react'; import * as Dialog from '@radix-ui/react-dialog'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { nip19 } from 'nostr-tools'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { useHotkeys } from 'react-hotkeys-hook'; import { User } from '@app/auth/components/user'; import { createBlock } from '@libs/storage'; import { CancelIcon, CheckCircleIcon, CommandIcon, LoaderIcon } from '@shared/icons'; import { BLOCK_KINDS, DEFAULT_AVATAR } from '@stores/constants'; import { ADD_FEEDBLOCK_SHORTCUT } from '@stores/shortcuts'; import { useAccount } from '@utils/hooks/useAccount'; export function FeedModal() { const queryClient = useQueryClient(); const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); const [selected, setSelected] = useState([]); const [query, setQuery] = useState(''); const { status, account } = useAccount(); useHotkeys(ADD_FEEDBLOCK_SHORTCUT, () => setOpen(true)); const block = useMutation({ mutationFn: (data: { kind: number; title: string; content: string }) => { return createBlock(data.kind, data.title, data.content); }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['blocks'] }); }, }); const { register, handleSubmit, reset, formState: { isDirty, isValid }, } = useForm(); const onSubmit = (data: { kind: number; title: string; content: string }) => { setLoading(true); selected.forEach((item, index) => { if (item.substring(0, 4) === 'npub') { selected[index] = nip19.decode(item).data; } }); // insert to database block.mutate({ kind: BLOCK_KINDS.feed, title: data.title, content: JSON.stringify(selected), }); setLoading(false); // reset form reset(); // close modal setOpen(false); }; return (
Create feed block
Specific newsfeed space for people you want to keep up to date
Choose at least 1 user *
setQuery(event.target.value)} spellCheck={false} placeholder="Enter pubkey or npub..." className="relative mb-2 h-10 w-full rounded-md bg-white/10 px-3 py-2 text-white !outline-none placeholder:text-white/50" /> {query.length > 0 && ( {({ selected }) => ( <>
{query}
{query}
{selected && ( )} )}
)} {status === 'loading' ? (

Loading...

) : ( account?.follows?.map((follow) => ( {({ selected }) => ( <> {selected && ( )} )} )) )}
); }