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 18 additions and 11 deletions
Showing only changes of commit ddcdf9586e - Show all commits

View file

@ -28,7 +28,7 @@ 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.
};
const HIDE_TIME_OUT = 600;
const CLEAR_TIME_OUT = 300;
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 TARGET_TIME_OUT = 300;
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 NAVIGATE_TIME_OUT = 400;
const PUBLISH_URL = `/$/${PAGES.PUBLISH}`;
@ -37,9 +37,9 @@ function FileDrop(props: 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.
const { drag, dropData } = useDragDrop();
const [files, setFiles] = React.useState([]);
const [error, setError] = React.useState(false);
const [target, updateTarget] = 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 [target, setTarget] = 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 hideTimer = React.useRef(null);
const clearDataTimer = React.useRef(null);
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 targetTimer = React.useRef(null);
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 navigationTimer = React.useRef(null);
const navigateToPublish = React.useCallback(() => {
@ -93,21 +93,24 @@ function FileDrop(props: 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.
if (hideTimer.current) {
clearTimeout(hideTimer.current);
}
// Clear target timer
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 (targetTimer.current) {
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.
clearTimeout(targetTimer.current);
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.
// Clear navigation timer
if (navigationTimer.current) {
clearTimeout(navigationTimer.current);
}
// Clear clearData timer
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 (navigationTimer.current) {
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.
clearTimeout(clearDataTimer.current);
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(() => {
// Clear selected file after modal closed
if ((target && !files) || !files.length) {
clearDataTimer.current = setTimeout(() => updateTarget(null), CLEAR_TIME_OUT);
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.
// Small delay for a better transition
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.
targetTimer.current = setTimeout(() => {
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.
setTarget(null);
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.
}, TARGET_TIME_OUT);
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, target]);
@ -135,7 +138,7 @@ function FileDrop(props: 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.
setFiles([]);
} else if (files.length === 1) {
// Handle single file selection
updateTarget(files[0]);
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.
setTarget(files[0]);
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.
handleFileSelected(files[0]);
}
}

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

@ -22,7 +22,7 @@ const readDirectory = directory => {
// Get file system entries from the dataTransfer items list:
const getFiles = (items, directoryEntries) => {
const getFiles = (items, directoryEntries = false) => {
let entries = [];
for (let item of items) {
@ -58,11 +58,15 @@ export const getTree = async dataTransfer => {
const file = await getFile(root);
return [file];
}
} else {
// Some files have hidden dataTransfer items:
// Use the default file object instead
return files;
}
}
// Handle multiple items drop
if (files.length > 1) {
// Convert items to fileEntry and get each file
// Convert items to fileEntry and filter files
return getFiles(items);
}
}