import { RelayContext } from '@components/contexts/relay'; import { dateToUnix } from '@utils/getDate'; import * as Dialog from '@radix-ui/react-dialog'; import { useLocalStorage } from '@rehooks/local-storage'; import * as commands from '@uiw/react-md-editor/lib/commands'; import dynamic from 'next/dynamic'; import { getEventHash, signEvent } from 'nostr-tools'; import { useContext, useState } from 'react'; const MDEditor = dynamic(() => import('@uiw/react-md-editor').then((mod) => mod.default), { ssr: false, }); export default function CreatePost() { const relayPool: any = useContext(RelayContext); const [relays]: any = useLocalStorage('relays'); const [value, setValue] = useState(''); const [currentUser]: any = useLocalStorage('current-user'); const pubkey = currentUser.id; const privkey = currentUser.privkey; const postButton = { name: 'post', keyCommand: 'post', buttonProps: { className: 'cta-btn', 'aria-label': 'Post a message' }, icon: (
Post
), execute: (state: { text: any }) => { const message = state.text; if (message.length > 0) { const event: any = { content: message, created_at: dateToUnix(), kind: 1, pubkey: pubkey, tags: [], }; event.id = getEventHash(event); event.sig = signEvent(event, privkey); relayPool.publish(event, relays); setValue(''); } }, }; return (