import { ImagePicker } from '@components/form/imagePicker'; import { RelayContext } from '@components/relaysProvider'; import { UserMini } from '@components/user/mini'; import { channelContentAtom, channelReplyAtom } from '@stores/channel'; import { FULL_RELAYS } from '@stores/constants'; import { dateToUnix } from '@utils/getDate'; import useLocalStorage from '@rehooks/local-storage'; import { Cancel } from 'iconoir-react'; import { useAtom, useAtomValue } from 'jotai'; import { useResetAtom } from 'jotai/utils'; import { getEventHash, signEvent } from 'nostr-tools'; import { useCallback, useContext } from 'react'; export const FormChannel = ({ eventId }: { eventId: string | string[] }) => { const [pool]: any = useContext(RelayContext); const [activeAccount]: any = useLocalStorage('account', {}); const [value, setValue] = useAtom(channelContentAtom); const resetValue = useResetAtom(channelContentAtom); const channelReply = useAtomValue(channelReplyAtom); const resetChannelReply = useResetAtom(channelReplyAtom); const submitEvent = useCallback(() => { let tags: any[][]; if (channelReply.id !== null) { tags = [ ['e', eventId, '', 'root'], ['e', channelReply.id, '', 'reply'], ['p', channelReply.pubkey, ''], ]; } else { tags = [['e', eventId, '', 'root']]; } const event: any = { content: value, created_at: dateToUnix(), kind: 42, pubkey: activeAccount.pubkey, tags: tags, }; event.id = getEventHash(event); event.sig = signEvent(event, activeAccount.privkey); // publish note pool.publish(event, FULL_RELAYS); // reset state resetValue(); // reset channel reply resetChannelReply(); }, [ value, channelReply.id, channelReply.pubkey, activeAccount.pubkey, activeAccount.privkey, eventId, resetChannelReply, resetValue, pool, ]); const handleEnterPress = (e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); submitEvent(); } }; const stopReply = () => { resetChannelReply(); }; return (