Files
Readarr/frontend/src/Search/Author/AddNewAuthorModalContentConnector.js
Mark McDowall f819e582cf New: Author folder hint when selecting a root folder while adding a new author
(cherry picked from commit dd09f31abb4dd3f699bcff0a47577075300c70ee)

Fix AuthorFolderAsRootFolderValidator

(cherry picked from commit 0ce81e1ab69d43fde382cc4ae22cd46fe626dea7)
2025-04-08 21:41:48 +03:00

109 lines
2.9 KiB
JavaScript

import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { addAuthor, setAuthorAddDefault } from 'Store/Actions/searchActions';
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
import createSystemStatusSelector from 'Store/Selectors/createSystemStatusSelector';
import selectSettings from 'Store/Selectors/selectSettings';
import AddNewAuthorModalContent from './AddNewAuthorModalContent';
function createMapStateToProps() {
return createSelector(
(state) => state.search,
(state) => state.settings.metadataProfiles,
createDimensionsSelector(),
createSystemStatusSelector(),
(searchState, metadataProfiles, dimensions, systemStatus) => {
const {
isAdding,
addError,
authorDefaults
} = searchState;
const {
settings,
validationErrors,
validationWarnings
} = selectSettings(authorDefaults, {}, addError);
return {
isAdding,
addError,
showMetadataProfile: metadataProfiles.items.length > 2, // NONE (not allowed for authors) and one other
isSmallScreen: dimensions.isSmallScreen,
validationErrors,
validationWarnings,
isWindows: systemStatus.isWindows,
...settings
};
}
);
}
const mapDispatchToProps = {
setAuthorAddDefault,
addAuthor
};
class AddNewAuthorModalContentConnector extends Component {
//
// Listeners
onInputChange = ({ name, value }) => {
this.props.setAuthorAddDefault({ [name]: value });
};
onAddAuthorPress = (searchForMissingBooks) => {
const {
foreignAuthorId,
rootFolderPath,
monitor,
monitorNewItems,
qualityProfileId,
metadataProfileId,
tags
} = this.props;
this.props.addAuthor({
foreignAuthorId,
rootFolderPath: rootFolderPath.value,
monitor: monitor.value,
monitorNewItems: monitorNewItems.value,
qualityProfileId: qualityProfileId.value,
metadataProfileId: metadataProfileId.value,
tags: tags.value,
searchForMissingBooks
});
};
//
// Render
render() {
return (
<AddNewAuthorModalContent
{...this.props}
onInputChange={this.onInputChange}
onAddAuthorPress={this.onAddAuthorPress}
/>
);
}
}
AddNewAuthorModalContentConnector.propTypes = {
foreignAuthorId: PropTypes.string.isRequired,
rootFolderPath: PropTypes.object,
monitor: PropTypes.object.isRequired,
monitorNewItems: PropTypes.object.isRequired,
qualityProfileId: PropTypes.object,
metadataProfileId: PropTypes.object,
tags: PropTypes.object.isRequired,
onModalClose: PropTypes.func.isRequired,
setAuthorAddDefault: PropTypes.func.isRequired,
addAuthor: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, mapDispatchToProps)(AddNewAuthorModalContentConnector);