import { NDKSubscriptionCacheUsage } from '@nostr-dev-kit/ndk' import { FALLBACK_PROFILE_IMAGE } from '../../constants' import { useAppSelector } from 'hooks' import { useProfile } from 'hooks/useProfile' import { Navigate, useSubmit } from 'react-router-dom' import { appRoutes } from 'routes' import { useState } from 'react' import { adjustTextareaHeight } from 'utils' import { NotePreview } from './NotePreview' interface NoteSubmitProps { initialContent?: string | undefined } export const NoteSubmit = ({ initialContent }: NoteSubmitProps) => { const userState = useAppSelector((state) => state.user) const profile = useProfile(userState.user?.pubkey as string | undefined, { cacheUsage: NDKSubscriptionCacheUsage.PARALLEL }) const [content, setContent] = useState(initialContent ?? '') const [nsfw, setNsfw] = useState(false) const [showPreview, setShowPreview] = useState(false) const image = profile?.image || FALLBACK_PROFILE_IMAGE const submit = useSubmit() const handleContentChange = ( event: React.ChangeEvent ) => { setContent(event.currentTarget.value) adjustTextareaHeight(event.currentTarget) } const handleFormSubmit = async (event: React.FormEvent) => { event.preventDefault() const formSubmit = { content, nsfw } submit(JSON.stringify(formSubmit), { method: 'post', encType: 'application/json' }) } const handlePreviewToggle = () => { setShowPreview((prev) => !prev) } if (!userState.user?.pubkey) return return ( <>