Note creator fix

This commit is contained in:
Kieran 2023-01-16 18:30:08 +00:00
parent d74b05be98
commit 22e84d63ba
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941

View File

@ -20,19 +20,21 @@ export interface NoteCreatorProps {
export function NoteCreator(props: NoteCreatorProps) { export function NoteCreator(props: NoteCreatorProps) {
const publisher = useEventPublisher(); const publisher = useEventPublisher();
const [note, setNote] = useState(""); const [note, setNote] = useState<string>();
const [error, setError] = useState(""); const [error, setError] = useState<string>();
const [active, setActive] = useState(false); const [active, setActive] = useState<boolean>(false);
async function sendNote() { async function sendNote() {
let ev = props.replyTo ? await publisher.reply(props.replyTo, note) : await publisher.note(note); if (note) {
console.debug("Sending note: ", ev); let ev = props.replyTo ? await publisher.reply(props.replyTo, note) : await publisher.note(note);
publisher.broadcast(ev); console.debug("Sending note: ", ev);
setNote(""); publisher.broadcast(ev);
if (typeof props.onSend === "function") { setNote("");
props.onSend(); if (typeof props.onSend === "function") {
props.onSend();
}
setActive(false);
} }
setActive(false);
} }
async function attachFile() { async function attachFile() {
@ -86,7 +88,7 @@ export function NoteCreator(props: NoteCreatorProps) {
{active && note && ( {active && note && (
<div className="actions flex f-row"> <div className="actions flex f-row">
<div className="attachment flex f-row"> <div className="attachment flex f-row">
{error.length > 0 ? <b className="error">{error}</b> : null} {(error?.length ?? 0) > 0 ? <b className="error">{error}</b> : null}
<FontAwesomeIcon icon={faPaperclip} size="xl" onClick={(e) => attachFile()} /> <FontAwesomeIcon icon={faPaperclip} size="xl" onClick={(e) => attachFile()} />
</div> </div>
<button type="button" className="btn" onClick={onSubmit}> <button type="button" className="btn" onClick={onSubmit}>