Push drop zone down to dialog

pull/180/head
Philipp Heckel 2022-04-03 22:42:56 -04:00
parent 8914809775
commit 7716b1e81e
2 changed files with 15 additions and 24 deletions

View File

@ -126,25 +126,15 @@ const Messaging = (props) => {
const [message, setMessage] = useState(""); const [message, setMessage] = useState("");
const [dialogKey, setDialogKey] = useState(0); const [dialogKey, setDialogKey] = useState(0);
const [dialogOpenMode, setDialogOpenMode] = useState(""); const [dialogOpenMode, setDialogOpenMode] = useState("");
const [showDropZone, setShowDropZone] = useState(false);
const subscription = props.selected; const subscription = props.selected;
const selectedTopicUrl = (subscription) ? topicUrl(subscription.baseUrl, subscription.topic) : ""; const selectedTopicUrl = (subscription) ? topicUrl(subscription.baseUrl, subscription.topic) : "";
useEffect(() => {
window.addEventListener('dragenter', () => {
setDialogOpenMode(prev => (prev) ? prev : SendDialog.OPEN_MODE_DRAG); // Only update if not already open
setShowDropZone(true);
});
}, []);
const handleOpenDialogClick = () => { const handleOpenDialogClick = () => {
setDialogOpenMode(SendDialog.OPEN_MODE_DEFAULT); setDialogOpenMode(SendDialog.OPEN_MODE_DEFAULT);
setShowDropZone(false);
}; };
const handleSendDialogClose = () => { const handleSendDialogClose = () => {
setShowDropZone(false);
setDialogOpenMode(""); setDialogOpenMode("");
setDialogKey(prev => prev+1); setDialogKey(prev => prev+1);
}; };
@ -159,13 +149,11 @@ const Messaging = (props) => {
/>} />}
<SendDialog <SendDialog
key={`sendDialog${dialogKey}`} // Resets dialog when canceled/closed key={`sendDialog${dialogKey}`} // Resets dialog when canceled/closed
openMode={dialogOpenMode}
topicUrl={selectedTopicUrl} topicUrl={selectedTopicUrl}
message={message} message={message}
open={!!dialogOpenMode}
openMode={dialogOpenMode}
dropZone={showDropZone}
onClose={handleSendDialogClose} onClose={handleSendDialogClose}
onHideDropZone={() => setShowDropZone(false)} onDragEnter={() => setDialogOpenMode(prev => (prev) ? prev : SendDialog.OPEN_MODE_DRAG)} // Only update if not already open
onResetOpenMode={() => setDialogOpenMode(SendDialog.OPEN_MODE_DEFAULT)} onResetOpenMode={() => setDialogOpenMode(SendDialog.OPEN_MODE_DEFAULT)}
/> />
</> </>

View File

@ -54,11 +54,19 @@ const SendDialog = (props) => {
const [status, setStatus] = useState(""); const [status, setStatus] = useState("");
const disabled = !!activeRequest; const disabled = !!activeRequest;
const [dropZone, setDropZone] = useState(false);
const [sendButtonEnabled, setSendButtonEnabled] = useState(true); const [sendButtonEnabled, setSendButtonEnabled] = useState(true);
const dropZone = props.dropZone; const open = !!props.openMode;
const fullScreen = useMediaQuery(theme.breakpoints.down('sm')); const fullScreen = useMediaQuery(theme.breakpoints.down('sm'));
useEffect(() => {
window.addEventListener('dragenter', () => {
props.onDragEnter();
setDropZone(true);
});
}, []);
useEffect(() => { useEffect(() => {
setTopicUrl(props.topicUrl); setTopicUrl(props.topicUrl);
setShowTopicUrl(props.topicUrl === "") setShowTopicUrl(props.topicUrl === "")
@ -165,7 +173,7 @@ const SendDialog = (props) => {
const handleAttachFileDrop = async (ev) => { const handleAttachFileDrop = async (ev) => {
ev.preventDefault(); ev.preventDefault();
props.onHideDropZone(); setDropZone(false);
await updateAttachFile(ev.dataTransfer.files[0]); await updateAttachFile(ev.dataTransfer.files[0]);
}; };
@ -177,14 +185,9 @@ const SendDialog = (props) => {
}; };
const handleAttachFileDragLeave = () => { const handleAttachFileDragLeave = () => {
// When the dialog was opened by dragging a file in, close it. If it was open setDropZone(false);
// before, keep it open.
console.log(`open mode ${props.openMode}`);
if (props.openMode === SendDialog.OPEN_MODE_DRAG) { if (props.openMode === SendDialog.OPEN_MODE_DRAG) {
props.onClose(); props.onClose(); // Only close dialog if it was not open before dragging file in
} else {
props.onHideDropZone();
} }
}; };
@ -194,7 +197,7 @@ const SendDialog = (props) => {
onDrop={handleAttachFileDrop} onDrop={handleAttachFileDrop}
onDragLeave={handleAttachFileDragLeave}/> onDragLeave={handleAttachFileDragLeave}/>
} }
<Dialog maxWidth="md" open={props.open} onClose={props.onCancel} fullScreen={fullScreen}> <Dialog maxWidth="md" open={open} onClose={props.onCancel} fullScreen={fullScreen}>
<DialogTitle>Publish to {shortUrl(topicUrl)}</DialogTitle> <DialogTitle>Publish to {shortUrl(topicUrl)}</DialogTitle>
<DialogContent> <DialogContent>
{dropZone && <DropBox/>} {dropZone && <DropBox/>}