Lidarr/frontend/src/Components/FileBrowser/FileBrowserModalContentConn...

120 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-09-04 02:20:56 +00:00
import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
2020-09-07 01:33:10 +00:00
import { clearPaths, fetchPaths } from 'Store/Actions/pathActions';
import createSystemStatusSelector from 'Store/Selectors/createSystemStatusSelector';
2017-09-04 02:20:56 +00:00
import FileBrowserModalContent from './FileBrowserModalContent';
function createMapStateToProps() {
return createSelector(
(state) => state.paths,
createSystemStatusSelector(),
(paths, systemStatus) => {
2017-09-04 02:20:56 +00:00
const {
isFetching,
isPopulated,
error,
2017-09-04 02:20:56 +00:00
parent,
currentPath,
directories,
files
} = paths;
const filteredPaths = _.filter([...directories, ...files], ({ path }) => {
return path.toLowerCase().startsWith(currentPath.toLowerCase());
});
return {
isFetching,
isPopulated,
error,
2017-09-04 02:20:56 +00:00
parent,
currentPath,
directories,
files,
paths: filteredPaths,
isWindowsService: systemStatus.isWindows && systemStatus.mode === 'service'
2017-09-04 02:20:56 +00:00
};
}
);
}
const mapDispatchToProps = {
dispatchFetchPaths: fetchPaths,
dispatchClearPaths: clearPaths
2017-09-04 02:20:56 +00:00
};
class FileBrowserModalContentConnector extends Component {
// Lifecycle
componentDidMount() {
const {
value,
includeFiles,
dispatchFetchPaths
} = this.props;
dispatchFetchPaths({
path: value,
allowFoldersWithoutTrailingSlashes: true,
includeFiles
});
2017-09-04 02:20:56 +00:00
}
//
// Listeners
onFetchPaths = (path) => {
const {
includeFiles,
dispatchFetchPaths
} = this.props;
dispatchFetchPaths({
path,
allowFoldersWithoutTrailingSlashes: true,
includeFiles
});
2021-12-24 18:18:14 +00:00
};
2017-09-04 02:20:56 +00:00
onClearPaths = () => {
// this.props.dispatchClearPaths();
2021-12-24 18:18:14 +00:00
};
2017-09-04 02:20:56 +00:00
onModalClose = () => {
this.props.dispatchClearPaths();
2017-09-04 02:20:56 +00:00
this.props.onModalClose();
2021-12-24 18:18:14 +00:00
};
2017-09-04 02:20:56 +00:00
//
// Render
render() {
return (
<FileBrowserModalContent
onFetchPaths={this.onFetchPaths}
onClearPaths={this.onClearPaths}
{...this.props}
onModalClose={this.onModalClose}
/>
);
}
}
FileBrowserModalContentConnector.propTypes = {
value: PropTypes.string,
includeFiles: PropTypes.bool.isRequired,
dispatchFetchPaths: PropTypes.func.isRequired,
dispatchClearPaths: PropTypes.func.isRequired,
2017-09-04 02:20:56 +00:00
onModalClose: PropTypes.func.isRequired
};
FileBrowserModalContentConnector.defaultProps = {
includeFiles: false
};
2017-09-04 02:20:56 +00:00
export default connect(createMapStateToProps, mapDispatchToProps)(FileBrowserModalContentConnector);