Support drag-and-drop file publishing #4170
|
@ -1,6 +1,6 @@
|
|||
import { connect } from 'react-redux';
|
||||
|
||||
import { doToast, doClearPublish, doUpdatePublishForm, makeSelectPublishFormValue } from 'lbry-redux';
|
||||
import { doUpdatePublishForm, makeSelectPublishFormValue } from 'lbry-redux';
|
||||
|
||||
import { selectModal } from 'redux/selectors/app';
|
||||
import { doOpenModal } from 'redux/actions/app';
|
||||
|
@ -14,8 +14,6 @@ const select = state => ({
|
|||
|
||||
const perform = dispatch => ({
|
||||
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),
|
||||
showToast: message => dispatch(doToast({ message, isError: true })),
|
||||
clearPublish: () => dispatch(doClearPublish()),
|
||||
updatePublishForm: value => dispatch(doUpdatePublishForm(value)),
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import useDragDrop from 'effects/use-drag-drop';
|
|||
ok, done. ok, done.
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
import { getTree } from 'util/web-file-system';
|
||||
import { withRouter } from 'react-router';
|
||||
import Icon from 'component/common/icon';
|
||||
import FileList from 'component/common/file-list';
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
|
||||
type Props = {
|
||||
modal: { id: string, modalProps: {} },
|
||||
|
@ -29,7 +28,8 @@ type 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 HIDE_TIME_OUT = 600;
|
||||
const NAVIGATE_TIME_OUT = 200;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const CLEAR_TIME_OUT = 300;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const NAVIGATE_TIME_OUT = 400;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const PUBLISH_URL = `/$/${PAGES.PUBLISH}`;
|
||||
|
||||
function FileDrop(props: Props) {
|
||||
|
@ -37,7 +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 hideTimer = React.useRef(null);
|
||||
const clearDataTimer = React.useRef(null);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const navigationTimer = React.useRef(null);
|
||||
|
||||
const navigateToPublish = React.useCallback(() => {
|
||||
|
@ -64,11 +66,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.
|
||||
hideDropArea();
|
||||
};
|
||||
|
||||
// Firt file will be selected by default:
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const handleFileChange = (file?: WebFile) => {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
if (files && files.length && file) {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
handleFileSelected(file);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const getFileIcon = type => {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
// Not all files have a type
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
if (!type) {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
return ICONS.FILE;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
}
|
||||
// Detect common types
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const contentType = type.split('/')[0];
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
if (contentType === 'text') {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
return ICONS.TEXT;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
} else if (contentType === 'image') {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
return ICONS.IMAGE;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
} else if (contentType === 'video') {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
return ICONS.VIDEO;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
} else if (contentType === 'audio') {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
return ICONS.AUDIO;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
}
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
// Binary file
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
return ICONS.FILE;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
};
|
||||
|
||||
// Clear timers
|
||||
|
@ -82,9 +97,20 @@ 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 (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(() => {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
// Clear selected file after modal closed
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
if ((target && !files) || !files.length) {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
clearDataTimer.current = setTimeout(() => updateTarget(null), CLEAR_TIME_OUT);
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
}
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
}, [files, target]);
|
||||
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(() => {
|
||||
// Handle drop...
|
||||
if (dropData && !files.length && (!modal || modal.id !== MODALS.FILE_SELECTION)) {
|
||||
|
@ -107,18 +133,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 (files.length > 1) {
|
||||
openModal(MODALS.FILE_SELECTION, { files: files });
|
||||
setFiles([]);
|
||||
} else if (files.length === 1) {
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
// Handle single file selection
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
updateTarget(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.
|
||||
}
|
||||
}
|
||||
}, [drag, files, error, openModal]);
|
||||
|
||||
const show = files.length === 1 || (drag && (!modal || modal.id !== MODALS.FILE_SELECTION));
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
// Show icon based on file type
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const icon = target ? getFileIcon(target.type) : ICONS.PUBLISH;
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
// Show drop area when files are dragged over or processing dropped file
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
const show = files.length === 1 || (!target && drag && (!modal || modal.id !== MODALS.FILE_SELECTION));
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
|
||||
return (
|
||||
<div className={classnames('file-drop', show && 'file-drop--show')}>
|
||||
<div className={classnames('card', 'file-drop__area')}>
|
||||
<Icon size={64} icon={ICONS.PUBLISH} className={'main-icon'} />
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
<p>{__(`Drop here to publish!`)} </p>
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
{files && files.length === 1 && <FileList files={files} onChange={handleFileChange} />}
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
<Icon size={64} icon={icon} className={'main-icon'} />
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
<p>{target ? target.name : __(`Drop here to publish!`)} </p>
|
||||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|||
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
Please wrap this in Please wrap this in `__()`
ok, done. ok, done.
|
Please wrap this in
__()