Support drag-and-drop file publishing #4170
|
@ -28,7 +28,7 @@ type Props = {
|
|||
ok, done. ok, done.
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
};
|
||||
|
||||
const HIDE_TIME_OUT = 600;
|
||||
const CLEAR_TIME_OUT = 300;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const TARGET_TIME_OUT = 300;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const NAVIGATE_TIME_OUT = 400;
|
||||
const PUBLISH_URL = `/$/${PAGES.PUBLISH}`;
|
||||
|
||||
|
@ -37,9 +37,9 @@ function FileDrop(props: Props) {
|
|||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
Please wrap this in Please wrap this in `__()`
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);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const [target, setTarget] = React.useState(false);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const hideTimer = React.useRef(null);
|
||||
const clearDataTimer = React.useRef(null);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const targetTimer = React.useRef(null);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const navigationTimer = React.useRef(null);
|
||||
|
||||
const navigateToPublish = React.useCallback(() => {
|
||||
|
@ -93,21 +93,24 @@ function FileDrop(props: Props) {
|
|||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
if (hideTimer.current) {
|
||||
clearTimeout(hideTimer.current);
|
||||
}
|
||||
// Clear target timer
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
if (targetTimer.current) {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
clearTimeout(targetTimer.current);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
}
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
// Clear navigation timer
|
||||
if (navigationTimer.current) {
|
||||
clearTimeout(navigationTimer.current);
|
||||
}
|
||||
// Clear clearData timer
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
if (navigationTimer.current) {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
clearTimeout(clearDataTimer.current);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
}
|
||||
Please wrap this in Please wrap this in `__()`
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);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
// Small delay for a better transition
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
targetTimer.current = setTimeout(() => {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
setTarget(null);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
}, TARGET_TIME_OUT);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
}
|
||||
}, [files, target]);
|
||||
|
||||
|
@ -135,7 +138,7 @@ function FileDrop(props: Props) {
|
|||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
setFiles([]);
|
||||
} else if (files.length === 1) {
|
||||
// Handle single file selection
|
||||
updateTarget(files[0]);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
setTarget(files[0]);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
handleFileSelected(files[0]);
|
||||
}
|
||||
}
|
||||
|
|
|||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Please wrap this in
__()