diff --git a/src/Util.js b/src/Util.js new file mode 100644 index 00000000..7fc8f003 --- /dev/null +++ b/src/Util.js @@ -0,0 +1,11 @@ + +export async function openFile() { + return new Promise((resolve, reject) => { + let elm = document.createElement("input"); + elm.type = "file"; + elm.onchange = (e) => { + resolve(e.target.files[0]); + }; + elm.click(); + }); +} diff --git a/src/element/NoteCreator.css b/src/element/NoteCreator.css new file mode 100644 index 00000000..eb3e6297 --- /dev/null +++ b/src/element/NoteCreator.css @@ -0,0 +1,18 @@ +.note-creator { + margin-bottom: 10px; +} + +.note-creator textarea { + min-height: 40px; + max-height: 300px; + border-radius: 10px 10px 0 0; + max-width: -webkit-fill-available; + min-width: -webkit-fill-available; +} + +.note-creator .actions { + cursor: pointer; + padding: 5px 10px; + border-radius: 0 0 10px 10px; + background-color: #222; +} \ No newline at end of file diff --git a/src/element/NoteCreator.js b/src/element/NoteCreator.js index e33595dc..30b122c1 100644 --- a/src/element/NoteCreator.js +++ b/src/element/NoteCreator.js @@ -1,11 +1,18 @@ +import "./NoteCreator.css"; import { useState } from "react"; import useEventPublisher from "../feed/EventPublisher"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { faPaperclip } from "@fortawesome/free-solid-svg-icons"; +import { openFile } from "../Util"; +import VoidUpload from "../feed/VoidUpload"; +import { FileExtensionRegex } from "../Const"; export function NoteCreator(props) { const replyTo = props.replyTo; const onSend = props.onSend; const publisher = useEventPublisher(); const [note, setNote] = useState(""); + const [error, setError] = useState(""); async function sendNote() { let ev = replyTo ? @@ -15,16 +22,33 @@ export function NoteCreator(props) { console.debug("Sending note: ", ev); publisher.broadcast(ev); setNote(""); - if(typeof onSend === "function") { + if (typeof onSend === "function") { onSend(); } } + async function attachFile() { + let file = await openFile(); + let rsp = await VoidUpload(file); + let ext = file.name.match(FileExtensionRegex)[1]; + + // extension tricks note parser to embed the content + let url = rsp.metadata.url ?? `https://void.cat/d/${rsp.id}.${ext}`; + + setNote(n => `${n}\n{url}`); + } + return ( <> {replyTo ? {`Reply to: ${replyTo.Id.substring(0, 8)}`} : null} -
- setNote(e.target.value)} className="f-grow mr10"> +
+
+