diff --git a/web/src/components/SendDialog.js b/web/src/components/SendDialog.js index ef801812..1b43150e 100644 --- a/web/src/components/SendDialog.js +++ b/web/src/components/SendDialog.js @@ -37,6 +37,7 @@ const SendDialog = (props) => { const [attachUrl, setAttachUrl] = useState(""); const [attachFile, setAttachFile] = useState(null); const [filename, setFilename] = useState(""); + const [filenameEdited, setFilenameEdited] = useState(false); const [email, setEmail] = useState(""); const [delay, setDelay] = useState(""); @@ -205,30 +206,60 @@ const SendDialog = (props) => { setShowEmail(false); }}> setEmail(ev.target.value)} - type="email" - variant="standard" - fullWidth - /> + margin="dense" + label="Email" + placeholder="Address to forward the message to, e.g. phil@example.com" + value={email} + onChange={ev => setEmail(ev.target.value)} + type="email" + variant="standard" + fullWidth + /> } {showAttachUrl && { setAttachUrl(""); + setFilename(""); + setFilenameEdited(false); setShowAttachUrl(false); }}> setAttachUrl(ev.target.value)} + onChange={ev => { + const url = ev.target.value; + setAttachUrl(url); + if (!filenameEdited) { + try { + const u = new URL(url); + const parts = u.pathname.split("/"); + if (parts.length > 0) { + setFilename(parts[parts.length-1]); + } + } catch (e) { + // Do nothing + } + } + }} type="url" variant="standard" - fullWidth + sx={{flexGrow: 5, marginRight: 1}} + /> + { + setFilename(ev.target.value); + setFilenameEdited(true); + }} + type="text" + variant="standard" + sx={{flexGrow: 1}} /> } @@ -242,16 +273,10 @@ const SendDialog = (props) => { file={attachFile} filename={filename} onChangeFilename={(f) => setFilename(f)} - onClose={() => setAttachFile(null)} - />} - {showAttachUrl && setFilename(ev.target.value)} - type="text" - variant="standard" - fullWidth + onClose={() => { + setAttachFile(null); + setFilename(""); + }} />} {showDelay && { @@ -328,32 +353,8 @@ const DialogIconButton = (props) => { const AttachmentBox = (props) => { const file = props.file; - const invisibleFilenameRef = useRef(); - const minFilenameWidth = 140; - const [filenameWidth, setFilenameWidth] = useState(minFilenameWidth); - const handleFilenameChange = (ev) => { - props.onChangeFilename(ev.target.value); - }; - const determineFilenameWidth = () => { - const boundingRect = invisibleFilenameRef?.current?.getBoundingClientRect(); - if (!boundingRect) { - return minFilenameWidth; - } - return (boundingRect.width >= minFilenameWidth) ? Math.round(boundingRect.width) : minFilenameWidth; - }; - useEffect(() => { - setFilenameWidth(determineFilenameWidth() + 5); - }, [props.filename]); return ( <> - - {props.filename} - Attached file: @@ -365,16 +366,11 @@ const AttachmentBox = (props) => { }}> - props.onChangeFilename(ev.target.value)} />
{formatBytes(file.size)} @@ -385,6 +381,44 @@ const AttachmentBox = (props) => { ); }; +const ExpandingTextField = (props) => { + const invisibleFieldRef = useRef(); + const [textWidth, setTextWidth] = useState(props.minWidth); + const determineTextWidth = () => { + const boundingRect = invisibleFieldRef?.current?.getBoundingClientRect(); + if (!boundingRect) { + return props.minWidth; + } + return (boundingRect.width >= props.minWidth) ? Math.round(boundingRect.width) : props.minWidth; + }; + useEffect(() => { + setTextWidth(determineTextWidth() + 5); + }, [props.value]); + return ( + <> + + {props.value} + + + + ) +}; + const priorities = { 1: { label: "Minimum priority", file: priority1 }, 2: { label: "Low priority", file: priority2 },