diff --git a/src/element/NoteCreator.tsx b/src/element/NoteCreator.tsx index 399819e3..f3a3f1de 100644 --- a/src/element/NoteCreator.tsx +++ b/src/element/NoteCreator.tsx @@ -20,19 +20,21 @@ export interface NoteCreatorProps { export function NoteCreator(props: NoteCreatorProps) { const publisher = useEventPublisher(); - const [note, setNote] = useState(""); - const [error, setError] = useState(""); - const [active, setActive] = useState(false); + const [note, setNote] = useState(); + const [error, setError] = useState(); + const [active, setActive] = useState(false); async function sendNote() { - let ev = props.replyTo ? await publisher.reply(props.replyTo, note) : await publisher.note(note); - console.debug("Sending note: ", ev); - publisher.broadcast(ev); - setNote(""); - if (typeof props.onSend === "function") { - props.onSend(); + if (note) { + let ev = props.replyTo ? await publisher.reply(props.replyTo, note) : await publisher.note(note); + console.debug("Sending note: ", ev); + publisher.broadcast(ev); + setNote(""); + if (typeof props.onSend === "function") { + props.onSend(); + } + setActive(false); } - setActive(false); } async function attachFile() { @@ -86,7 +88,7 @@ export function NoteCreator(props: NoteCreatorProps) { {active && note && (
- {error.length > 0 ? {error} : null} + {(error?.length ?? 0) > 0 ? {error} : null} attachFile()} />