Support drag-and-drop file publishing #4170

Merged
btzr-io merged 14 commits from drag-drop into master 2020-05-25 16:27:37 +02:00
2 changed files with 25 additions and 17 deletions
Showing only changes of commit b1ca99be91 - Show all commits

View file

@ -12,32 +12,41 @@ type Props = {
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
function FileDrop(props: Props) {
const { drag, dropData } = useDragDrop();
const [show, setShow] = React.useState(false);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
const [files, setFiles] = React.useState([]);
const [error, setError] = React.useState(false);
const [loading, setLoading] = React.useState(false);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
const showDropArea = drag || (files && files.length > 0 && loading && !error);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
React.useEffect(() => {
// Handle drop...
if (dropData && !loading) {
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
setLoading(true);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
if (dropData) {
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
getTree(dropData)
.then(entries => {
setLoading(false);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
setFiles(entries);
})
.catch(error => {
// Invalid entry / entries
setError(true);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
setLoading(false);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
setError(error || true);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
});
}
}, [dropData, loading]);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
}, [dropData]);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
React.useEffect(() => {
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
// Files are drag over or already dropped
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
if (drag || files.length) {
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
setShow(true);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
// No drag over or files dropped
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
} else if (!drag && !files.length) {
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
setShow(false);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
}
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
// Handle files
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
}, [drag, files, error]);
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
return (
<div className={classnames('file-drop', showDropArea && 'file-drop--show')}>
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
<p>Drop your files</p>
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
<div className={classnames('file-drop', show && 'file-drop--show')}>
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
<p>Drop your files here!</p>
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
{files.map(file => (
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
<div key={file.path}>{file.path}</div>
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
))}
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
</div>
);
}

neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.
neb-b commented 2020-05-15 17:37:44 +02:00 (Migrated from github.com)
Review

Please wrap this in __()

Please wrap this in `__()`
btzr-io commented 2020-05-18 01:19:54 +02:00 (Migrated from github.com)
Review

ok, done.

ok, done.

View file

@ -1,5 +1,5 @@
// Some functions to work with the new html5 file system API:
// - Used for the fileDrop component
import path from 'path';
// Wrapper for webkitGetAsEntry
// Note: webkitGetAsEntry might be renamed to GetAsEntry
@ -66,18 +66,17 @@ export const getTree = async dataTransfer => {
if (dataTransfer) {
const { items, files } = dataTransfer;
// Handle single item drop
if (items.length === 1) {
const { path } = files[0];
if (files.length === 1) {
const entry = getAsEntry(items[0]);
// Handle entry
if (entry) {
const root = { entry, path };
const root = { entry, path: files[0].path };
// Handle directory
if (root.entry.isDirectory) {
const directoryEntries = await readDirectory(root.entry);
directoryEntries.forEach(item => {
if (item.isFile) {
tree.push({ entry: item, path: `root.path/${item.name}` });
tree.push({ entry: item, path: path.join(root.path, item.name) });
}
});
}
@ -88,7 +87,7 @@ export const getTree = async dataTransfer => {
}
}
// Handle multiple items drop
if (items.length > 1) {
if (files.length > 1) {
tree = tree.concat(getFiles(dataTransfer));
}
}