import UserReply from '@lume/app/channel/components/messages/userReply'; import { ImagePicker } from '@lume/shared/form/imagePicker'; import CancelIcon from '@lume/shared/icons/cancel'; import { RelayContext } from '@lume/shared/relayProvider'; import { channelContentAtom, channelReplyAtom } from '@lume/stores/channel'; import { WRITEONLY_RELAYS } from '@lume/stores/constants'; import { dateToUnix } from '@lume/utils/getDate'; import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount'; import { useAtom, useAtomValue } from 'jotai'; import { useResetAtom } from 'jotai/utils'; import { getEventHash, signEvent } from 'nostr-tools'; import { useContext } from 'react'; export default function ChannelMessageForm({ channelID }: { channelID: string | string[] }) { const pool: any = useContext(RelayContext); const { account, isLoading, isError } = useActiveAccount(); const [value, setValue] = useAtom(channelContentAtom); const resetValue = useResetAtom(channelContentAtom); const channelReply = useAtomValue(channelReplyAtom); const resetChannelReply = useResetAtom(channelReplyAtom); const submitEvent = () => { let tags: any[][]; if (channelReply.id !== null) { tags = [ ['e', channelID, '', 'root'], ['e', channelReply.id, '', 'reply'], ['p', channelReply.pubkey, ''], ]; } else { tags = [['e', channelID, '', 'root']]; } if (!isError && !isLoading && account) { const event: any = { content: value, created_at: dateToUnix(), kind: 42, pubkey: account.pubkey, tags: tags, }; event.id = getEventHash(event); event.sig = signEvent(event, account.privkey); // publish note pool.publish(event, WRITEONLY_RELAYS); // reset state resetValue(); // reset channel reply resetChannelReply(); } else { console.log('error'); } }; const handleEnterPress = (e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); submitEvent(); } }; const stopReply = () => { resetChannelReply(); }; return (