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 43 additions and 13 deletions
Showing only changes of commit 7fe90fc7c5 - Show all commits

View file

@ -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)),
});

View file

@ -8,7 +8,6 @@ import useDragDrop from 'effects/use-drag-drop';
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.
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';
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.
type Props = {
modal: { id: string, modalProps: {} },
@ -29,7 +28,8 @@ 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 NAVIGATE_TIME_OUT = 200;
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 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 NAVIGATE_TIME_OUT = 400;
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 PUBLISH_URL = `/$/${PAGES.PUBLISH}`;
function FileDrop(props: Props) {
@ -37,7 +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 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 navigationTimer = React.useRef(null);
const navigateToPublish = React.useCallback(() => {
@ -64,11 +66,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.
hideDropArea();
};
// Firt file will be selected by default:
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 handleFileChange = (file?: WebFile) => {
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 (files && files.length && 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.
handleFileSelected(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.
const getFileIcon = type => {
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.
// Not all files have a type
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 (!type) {
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 ICONS.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.
}
// Detect common types
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 contentType = type.split('/')[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.
if (contentType === 'text') {
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 ICONS.TEXT;
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 (contentType === 'image') {
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 ICONS.IMAGE;
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 (contentType === 'video') {
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 ICONS.VIDEO;
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 (contentType === 'audio') {
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 ICONS.AUDIO;
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.
// Binary 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.
return ICONS.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.
};
// Clear timers
@ -82,9 +97,20 @@ 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 (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(() => {
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 selected file after modal closed
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 ((target && !files) || !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.
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.
}
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]);
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(() => {
// Handle drop...
if (dropData && !files.length && (!modal || modal.id !== MODALS.FILE_SELECTION)) {
@ -107,18 +133,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 (files.length > 1) {
openModal(MODALS.FILE_SELECTION, { files: files });
setFiles([]);
} else if (files.length === 1) {
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 single file selection
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.
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.
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.
}
}
}, [drag, files, error, openModal]);
const show = files.length === 1 || (drag && (!modal || modal.id !== MODALS.FILE_SELECTION));
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.
// Show icon based on file type
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 icon = target ? getFileIcon(target.type) : ICONS.PUBLISH;
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.
// Show drop area when files are dragged over or processing dropped 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.
const show = files.length === 1 || (!target && drag && (!modal || modal.id !== MODALS.FILE_SELECTION));
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', show && 'file-drop--show')}>
<div className={classnames('card', 'file-drop__area')}>
<Icon size={64} icon={ICONS.PUBLISH} className={'main-icon'} />
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 here to publish!`)} </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 && files.length === 1 && <FileList files={files} onChange={handleFileChange} />}
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.
<Icon size={64} icon={icon} className={'main-icon'} />
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>{target ? target.name : __(`Drop here to publish!`)} </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>
</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.