diff --git a/src/Element/NoteCreator.tsx b/src/Element/NoteCreator.tsx index 98f0a2bc..703c2787 100644 --- a/src/Element/NoteCreator.tsx +++ b/src/Element/NoteCreator.tsx @@ -1,9 +1,7 @@ import "./NoteCreator.css"; import { useState } from "react"; - import Attachment from "Icons/Attachment"; -import Plus from "Icons/Plus"; import useEventPublisher from "Feed/EventPublisher"; import { openFile } from "Util"; import Textarea from "Element/Textarea"; @@ -29,110 +27,107 @@ function NotePreview({ note }: NotePreviewProps) { } export interface NoteCreatorProps { - show: boolean - setShow: (s: boolean) => void - replyTo?: NEvent, - onSend?: Function, - autoFocus: boolean + show: boolean + setShow: (s: boolean) => void + replyTo?: NEvent, + onSend?: Function, + autoFocus: boolean } export function NoteCreator(props: NoteCreatorProps) { - const { show, setShow, replyTo, onSend, autoFocus } = props - const publisher = useEventPublisher(); - const [note, setNote] = useState(); - const [error, setError] = useState(); - const [active, setActive] = useState(false); - const uploader = useFileUpload(); - const hasErrors = (error?.length ?? 0) > 0 + const { show, setShow, replyTo, onSend, autoFocus } = props + const publisher = useEventPublisher(); + const [note, setNote] = useState(); + const [error, setError] = useState(); + const [active, setActive] = useState(false); + const uploader = useFileUpload(); + const hasErrors = (error?.length ?? 0) > 0 - async function sendNote() { - if (note) { - let ev = replyTo ? await publisher.reply(replyTo, note) : await publisher.note(note); - console.debug("Sending note: ", ev); - publisher.broadcast(ev); - setNote(""); - setShow(false); - if (typeof onSend === "function") { - onSend(); - } - setActive(false); + async function sendNote() { + if (note) { + let ev = replyTo ? await publisher.reply(replyTo, note) : await publisher.note(note); + console.debug("Sending note: ", ev); + publisher.broadcast(ev); + setNote(""); + setShow(false); + if (typeof onSend === "function") { + onSend(); + } + setActive(false); + } + } + + async function attachFile() { + try { + let file = await openFile(); + if (file) { + let rx = await uploader.upload(file, file.name); + if (rx.url) { + setNote(n => `${n ? `${n}\n` : ""}${rx.url}`); + } else if (rx?.error) { + setError(rx.error); } + } + } catch (error: any) { + setError(error?.message) } + } - async function attachFile() { - try { - let file = await openFile(); - if (file) { - let rx = await uploader.upload(file, file.name); - if (rx.url) { - setNote(n => `${n ? `${n}\n` : ""}${rx.url}`); - } else if (rx?.error) { - setError(rx.error); - } - } - } catch (error: any) { - setError(error?.message) - } + function onChange(ev: any) { + const { value } = ev.target + setNote(value) + if (value) { + setActive(true) + } else { + setActive(false) } + } - function onChange(ev: any) { - const { value } = ev.target - setNote(value) - if (value) { - setActive(true) - } else { - setActive(false) - } - } + function cancel(ev: any) { + setShow(false) + setNote("") + } - function cancel(ev: any) { - setShow(false) - setNote("") - } + function onSubmit(ev: React.MouseEvent) { + ev.stopPropagation(); + sendNote().catch(console.warn); + } - function onSubmit(ev: React.MouseEvent) { - ev.stopPropagation(); - sendNote().catch(console.warn); - } - - return ( - <> - - {show && ( - setShow(false)} - > - {replyTo && ( - - )} -
-
-