From 7ff34364a36fd36f95131e32ad874d84e8d5dd30 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Wed, 30 Mar 2022 14:11:18 -0400 Subject: [PATCH] Editable attachment filename --- web/src/components/SendDialog.js | 62 ++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/web/src/components/SendDialog.js b/web/src/components/SendDialog.js index 90824b3..ef80181 100644 --- a/web/src/components/SendDialog.js +++ b/web/src/components/SendDialog.js @@ -1,5 +1,5 @@ import * as React from 'react'; -import {useRef, useState} from 'react'; +import {useEffect, useRef, useState} from 'react'; import {NotificationItem} from "./Notifications"; import theme from "./theme"; import {Chip, FormControl, InputLabel, Link, Select, useMediaQuery} from "@mui/material"; @@ -24,6 +24,8 @@ import Icon from "./Icon"; import DialogFooter from "./DialogFooter"; import api from "../app/Api"; import Divider from "@mui/material/Divider"; +import EditIcon from '@mui/icons-material/Edit'; +import CheckIcon from '@mui/icons-material/Check'; const SendDialog = (props) => { const [topicUrl, setTopicUrl] = useState(props.topicUrl); @@ -326,43 +328,59 @@ const DialogIconButton = (props) => { const AttachmentBox = (props) => { const file = props.file; - const maybeInfoText = formatBytes(file.size); - const [editFilename, setEditFilename] = useState(false); + 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: - props.onChangeFilename(ev.target.value)} - fullWidth - /> - {editFilename - ? - : {props.filename} - } - setEditFilename(true)}> +
- {maybeInfoText} + {formatBytes(file.size)}
- ); };