import { Dropdown, TextInput, Textarea } from 'flowbite-react' import { Dispatch, HTMLAttributes, SetStateAction, useEffect, useState } from 'react' import { FormattedMessage, useIntl } from 'react-intl' import { FaEnvelope, FaGlobe, FaListCheck, FaLock, FaLockOpen, FaPaperPlane, FaPaperclip } from 'react-icons/fa6' import { MegalodonInterface } from 'megalodon' type Props = { client: MegalodonInterface setComposeHeight: Dispatch> } & HTMLAttributes export default function Compose(props: Props) { const [body, setBody] = useState('') const [visibility, setVisibility] = useState<'public' | 'unlisted' | 'private' | 'direct'>('public') const [cw, setCW] = useState(false) const [spoiler, setSpoiler] = useState('') const { formatMessage } = useIntl() useEffect(() => { if (cw) { props.setComposeHeight(162) } else { props.setComposeHeight(120) setSpoiler('') } }, [cw]) const post = async () => { if (body.length === 0) return let options = { visibility: visibility } if (cw) { options = Object.assign({}, options, { spoiler_text: spoiler }) } await props.client.postStatus(body, options) reset() } const reset = () => { setBody('') setSpoiler('') setCW(false) } return (
{cw && ( setSpoiler(ev.target.value)} placeholder={formatMessage({ id: 'compose.spoiler.placeholder' })} /> )}