2018-01-13 02:01:27 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
import { fetchInteractiveImportItems, setInteractiveImportSort, clearInteractiveImport, setInteractiveImportMode } from 'Store/Actions/interactiveImportActions';
|
|
|
|
import createClientSideCollectionSelector from 'Store/Selectors/createClientSideCollectionSelector';
|
|
|
|
import { executeCommand } from 'Store/Actions/commandActions';
|
|
|
|
import * as commandNames from 'Commands/commandNames';
|
|
|
|
import InteractiveImportModalContent from './InteractiveImportModalContent';
|
|
|
|
|
|
|
|
function createMapStateToProps() {
|
|
|
|
return createSelector(
|
|
|
|
createClientSideCollectionSelector('interactiveImport'),
|
|
|
|
(interactiveImport) => {
|
|
|
|
return interactiveImport;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
2019-05-04 00:38:06 +00:00
|
|
|
dispatchFetchInteractiveImportItems: fetchInteractiveImportItems,
|
|
|
|
dispatchSetInteractiveImportSort: setInteractiveImportSort,
|
|
|
|
dispatchSetInteractiveImportMode: setInteractiveImportMode,
|
|
|
|
dispatchClearInteractiveImport: clearInteractiveImport,
|
|
|
|
dispatchExecuteCommand: executeCommand
|
2018-01-13 02:01:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class InteractiveImportModalContentConnector extends Component {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Lifecycle
|
|
|
|
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
interactiveImportErrorMessage: null,
|
|
|
|
filterExistingFiles: true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const {
|
|
|
|
downloadId,
|
|
|
|
folder
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const {
|
|
|
|
filterExistingFiles
|
|
|
|
} = this.state;
|
|
|
|
|
2019-05-04 00:38:06 +00:00
|
|
|
this.props.dispatchFetchInteractiveImportItems({
|
2018-01-13 02:01:27 +00:00
|
|
|
downloadId,
|
|
|
|
folder,
|
|
|
|
filterExistingFiles
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
const {
|
|
|
|
filterExistingFiles
|
|
|
|
} = this.state;
|
|
|
|
|
|
|
|
if (prevState.filterExistingFiles !== filterExistingFiles) {
|
|
|
|
const {
|
|
|
|
downloadId,
|
|
|
|
folder
|
|
|
|
} = this.props;
|
|
|
|
|
2019-05-04 00:38:06 +00:00
|
|
|
this.props.dispatchFetchInteractiveImportItems({
|
2018-01-13 02:01:27 +00:00
|
|
|
downloadId,
|
|
|
|
folder,
|
|
|
|
filterExistingFiles
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2019-05-04 00:38:06 +00:00
|
|
|
this.props.dispatchClearInteractiveImport();
|
2018-01-13 02:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Listeners
|
|
|
|
|
|
|
|
onSortPress = (sortKey, sortDirection) => {
|
2019-05-04 00:38:06 +00:00
|
|
|
this.props.dispatchSetInteractiveImportSort({ sortKey, sortDirection });
|
2018-01-13 02:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onFilterExistingFilesChange = (filterExistingFiles) => {
|
|
|
|
this.setState({ filterExistingFiles });
|
|
|
|
}
|
|
|
|
|
|
|
|
onImportModeChange = (importMode) => {
|
2019-05-04 00:38:06 +00:00
|
|
|
this.props.dispatchSetInteractiveImportMode({ importMode });
|
2018-01-13 02:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onImportSelectedPress = (selected, importMode) => {
|
|
|
|
const files = [];
|
|
|
|
|
|
|
|
_.forEach(this.props.items, (item) => {
|
|
|
|
const isSelected = selected.indexOf(item.id) > -1;
|
|
|
|
|
|
|
|
if (isSelected) {
|
|
|
|
const {
|
|
|
|
series,
|
|
|
|
seasonNumber,
|
|
|
|
episodes,
|
|
|
|
quality,
|
|
|
|
language
|
|
|
|
} = item;
|
|
|
|
|
|
|
|
if (!series) {
|
|
|
|
this.setState({ interactiveImportErrorMessage: 'Series must be chosen for each selected file' });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isNaN(seasonNumber)) {
|
|
|
|
this.setState({ interactiveImportErrorMessage: 'Season must be chosen for each selected file' });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!episodes || !episodes.length) {
|
|
|
|
this.setState({ interactiveImportErrorMessage: 'One or more episodes must be chosen for each selected file' });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!quality) {
|
|
|
|
this.setState({ interactiveImportErrorMessage: 'Quality must be chosen for each selected file' });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!language) {
|
|
|
|
this.setState({ interactiveImportErrorMessage: 'Language must be chosen for each selected file' });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
files.push({
|
|
|
|
path: item.path,
|
|
|
|
folderName: item.folderName,
|
|
|
|
seriesId: series.id,
|
2019-05-04 00:38:06 +00:00
|
|
|
episodeIds: episodes.map((e) => e.id),
|
2018-01-13 02:01:27 +00:00
|
|
|
quality,
|
|
|
|
language,
|
|
|
|
downloadId: this.props.downloadId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!files.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-04 00:38:06 +00:00
|
|
|
this.props.dispatchExecuteCommand({
|
2018-01-13 02:01:27 +00:00
|
|
|
name: commandNames.INTERACTIVE_IMPORT,
|
|
|
|
files,
|
|
|
|
importMode
|
|
|
|
});
|
|
|
|
|
|
|
|
this.props.onModalClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Render
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
interactiveImportErrorMessage,
|
|
|
|
filterExistingFiles
|
|
|
|
} = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<InteractiveImportModalContent
|
|
|
|
{...this.props}
|
|
|
|
interactiveImportErrorMessage={interactiveImportErrorMessage}
|
|
|
|
filterExistingFiles={filterExistingFiles}
|
|
|
|
onSortPress={this.onSortPress}
|
|
|
|
onFilterExistingFilesChange={this.onFilterExistingFilesChange}
|
|
|
|
onImportModeChange={this.onImportModeChange}
|
|
|
|
onImportSelectedPress={this.onImportSelectedPress}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InteractiveImportModalContentConnector.propTypes = {
|
|
|
|
downloadId: PropTypes.string,
|
|
|
|
folder: PropTypes.string,
|
|
|
|
filterExistingFiles: PropTypes.bool.isRequired,
|
|
|
|
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
2019-05-04 00:38:06 +00:00
|
|
|
dispatchFetchInteractiveImportItems: PropTypes.func.isRequired,
|
|
|
|
dispatchSetInteractiveImportSort: PropTypes.func.isRequired,
|
|
|
|
dispatchSetInteractiveImportMode: PropTypes.func.isRequired,
|
|
|
|
dispatchClearInteractiveImport: PropTypes.func.isRequired,
|
|
|
|
dispatchExecuteCommand: PropTypes.func.isRequired,
|
2018-01-13 02:01:27 +00:00
|
|
|
onModalClose: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
InteractiveImportModalContentConnector.defaultProps = {
|
|
|
|
filterExistingFiles: true
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(createMapStateToProps, mapDispatchToProps)(InteractiveImportModalContentConnector);
|