import ImagePicker from '@components/form/imagePicker'; import { RelayContext } from '@components/relaysProvider'; import { dateToUnix } from '@utils/getDate'; import useLocalStorage from '@rehooks/local-storage'; import { getEventHash, signEvent } from 'nostr-tools'; import { useCallback, useContext, useState } from 'react'; export default function FormChannelMessage({ eventId }: { eventId: string | string[] }) { const [pool, relays]: any = useContext(RelayContext); const [value, setValue] = useState(''); const [activeAccount]: any = useLocalStorage('activeAccount', {}); const submitEvent = useCallback(() => { const event: any = { content: value, created_at: dateToUnix(), kind: 42, pubkey: activeAccount.pubkey, tags: [['e', eventId, '', 'root']], }; event.id = getEventHash(event); event.sig = signEvent(event, activeAccount.privkey); // publish note pool.publish(event, relays); // reset state setValue(''); }, [activeAccount.privkey, activeAccount.pubkey, eventId, value, pool, relays]); const handleEnterPress = (e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); submitEvent(); } }; return (