From 6d922a756327ed40704429629ec6ee53be74cc6c Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Wed, 9 Sep 2020 21:07:57 -0700 Subject: [PATCH] Show normal upload box when using upload button; closes #2294 --- .../components/server/files/UploadButton.tsx | 53 ++++++++++++++----- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/resources/scripts/components/server/files/UploadButton.tsx b/resources/scripts/components/server/files/UploadButton.tsx index 5b399ef1d..df2416a6b 100644 --- a/resources/scripts/components/server/files/UploadButton.tsx +++ b/resources/scripts/components/server/files/UploadButton.tsx @@ -2,7 +2,7 @@ import axios from 'axios'; import getFileUploadUrl from '@/api/server/files/getFileUploadUrl'; import tw from 'twin.macro'; import Button from '@/components/elements/Button'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import styled from 'styled-components/macro'; import { ModalMask } from '@/components/elements/Modal'; import Fade from '@/components/elements/Fade'; @@ -18,6 +18,7 @@ const InnerContainer = styled.div` `; export default () => { + const fileUploadInput = useRef(null); const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const [ visible, setVisible ] = useState(false); const [ loading, setLoading ] = useState(false); @@ -46,17 +47,9 @@ export default () => { }; }, [ visible ]); - const onFileDrop = (e: React.DragEvent) => { - e.preventDefault(); - e.stopPropagation(); - - setVisible(false); - if (e.dataTransfer === undefined || e.dataTransfer === null) { - return; - } - + const onFileSubmission = (files: FileList) => { const form = new FormData(); - Array.from(e.dataTransfer.files).forEach(file => form.append('files', file)); + Array.from(files).forEach(file => form.append('files', file)); setLoading(true); clearFlashes('files'); @@ -84,7 +77,21 @@ export default () => { key={'upload_modal_mask'} unmountOnExit > - setVisible(false)} onDrop={onFileDrop} onDragOver={e => e.preventDefault()}> + setVisible(false)} + onDragOver={e => e.preventDefault()} + onDrop={e => { + e.preventDefault(); + e.stopPropagation(); + + setVisible(false); + if (e.dataTransfer === undefined || e.dataTransfer === null) { + return; + } + + onFileSubmission(e.dataTransfer.files); + }} + >

@@ -95,7 +102,27 @@ export default () => { -