Fixed: Correctly set default profiles on import

Fixes: #333
pull/6/head
Qstick 7 years ago
parent 0d7cd8009f
commit 8624ff5c6a

@ -209,7 +209,7 @@
"lines-around-comment": ["error", { "beforeBlockComment": true, "afterBlockComment": false }], "lines-around-comment": ["error", { "beforeBlockComment": true, "afterBlockComment": false }],
"max-depth": ["error", {"maximum": 5}], "max-depth": ["error", {"maximum": 5}],
"max-nested-callbacks": ["error", 4], "max-nested-callbacks": ["error", 4],
"max-params": ["warn", 4], "max-params": ["error", 7],
"max-statements": "off", "max-statements": "off",
"max-statements-per-line": ["error", { "max": 1 }], "max-statements-per-line": ["error", { "max": 1 }],
"new-cap": ["error", {"capIsNewExceptions": ["$.Deferred"]}], "new-cap": ["error", {"capIsNewExceptions": ["$.Deferred"]}],

@ -16,9 +16,18 @@ function createMapStateToProps() {
(state) => state.rootFolders, (state) => state.rootFolders,
(state) => state.addArtist, (state) => state.addArtist,
(state) => state.importArtist, (state) => state.importArtist,
(state) => state.settings.qualityProfiles,
(state) => state.settings.languageProfiles, (state) => state.settings.languageProfiles,
(state) => state.settings.metadataProfiles, (state) => state.settings.metadataProfiles,
(match, rootFolders, addArtist, importArtistState, languageProfiles, metadataProfiles) => { (
match,
rootFolders,
addArtist,
importArtistState,
qualityProfiles,
languageProfiles,
metadataProfiles
) => {
const { const {
isFetching: rootFoldersFetching, isFetching: rootFoldersFetching,
isPopulated: rootFoldersPopulated, isPopulated: rootFoldersPopulated,
@ -33,8 +42,14 @@ function createMapStateToProps() {
rootFoldersFetching, rootFoldersFetching,
rootFoldersPopulated, rootFoldersPopulated,
rootFoldersError, rootFoldersError,
qualityProfiles: qualityProfiles.items,
languageProfiles: languageProfiles.items,
metadataProfiles: metadataProfiles.items,
showLanguageProfile: languageProfiles.items.length > 1, showLanguageProfile: languageProfiles.items.length > 1,
showMetadataProfile: metadataProfiles.items.length > 1 showMetadataProfile: metadataProfiles.items.length > 1,
defaultQualityProfileId: addArtist.defaults.qualityProfileId,
defaultLanguageProfileId: addArtist.defaults.languageProfileId,
defaultMetadataProfileId: addArtist.defaults.metadataProfileId
}; };
if (items.length) { if (items.length) {
@ -53,11 +68,11 @@ function createMapStateToProps() {
} }
const mapDispatchToProps = { const mapDispatchToProps = {
setImportArtistValue, dispatchSetImportArtistValue: setImportArtistValue,
importArtist, dispatchImportArtist: importArtist,
clearImportArtist, dispatchClearImportArtist: clearImportArtist,
fetchRootFolders, dispatchFetchRootFolders: fetchRootFolders,
setAddArtistDefault dispatchSetAddArtistDefault: setAddArtistDefault
}; };
class ImportArtistConnector extends Component { class ImportArtistConnector extends Component {
@ -66,23 +81,65 @@ class ImportArtistConnector extends Component {
// Lifecycle // Lifecycle
componentDidMount() { componentDidMount() {
const {
qualityProfiles,
languageProfiles,
metadataProfiles,
defaultQualityProfileId,
defaultLanguageProfileId,
defaultMetadataProfileId,
dispatchFetchRootFolders,
dispatchSetAddArtistDefault
} = this.props;
if (!this.props.rootFoldersPopulated) { if (!this.props.rootFoldersPopulated) {
this.props.fetchRootFolders(); dispatchFetchRootFolders();
}
let setDefaults = false;
const setDefaultPayload = {};
if (
!defaultQualityProfileId ||
!qualityProfiles.some((p) => p.id === defaultQualityProfileId)
) {
setDefaults = true;
setDefaultPayload.qualityProfileId = qualityProfiles[0].id;
}
if (
!defaultLanguageProfileId ||
!languageProfiles.some((p) => p.id === defaultLanguageProfileId)
) {
setDefaults = true;
setDefaultPayload.languageProfileId = languageProfiles[0].id;
}
if (
!defaultMetadataProfileId ||
!metadataProfiles.some((p) => p.id === defaultMetadataProfileId)
) {
setDefaults = true;
setDefaultPayload.metadataProfileId = metadataProfiles[0].id;
}
if (setDefaults) {
dispatchSetAddArtistDefault(setDefaultPayload);
} }
} }
componentWillUnmount() { componentWillUnmount() {
this.props.clearImportArtist(); this.props.dispatchClearImportArtist();
} }
// //
// Listeners // Listeners
onInputChange = (ids, name, value) => { onInputChange = (ids, name, value) => {
this.props.setAddArtistDefault({ [name]: value }); this.props.dispatchSetAddArtistDefault({ [name]: value });
ids.forEach((id) => { ids.forEach((id) => {
this.props.setImportArtistValue({ this.props.dispatchSetImportArtistValue({
id, id,
[name]: value [name]: value
}); });
@ -90,7 +147,7 @@ class ImportArtistConnector extends Component {
} }
onImportPress = (ids) => { onImportPress = (ids) => {
this.props.importArtist({ ids }); this.props.dispatchImportArtist({ ids });
} }
// //
@ -114,11 +171,17 @@ const routeMatchShape = createRouteMatchShape({
ImportArtistConnector.propTypes = { ImportArtistConnector.propTypes = {
match: routeMatchShape.isRequired, match: routeMatchShape.isRequired,
rootFoldersPopulated: PropTypes.bool.isRequired, rootFoldersPopulated: PropTypes.bool.isRequired,
setImportArtistValue: PropTypes.func.isRequired, qualityProfiles: PropTypes.arrayOf(PropTypes.object).isRequired,
importArtist: PropTypes.func.isRequired, languageProfiles: PropTypes.arrayOf(PropTypes.object).isRequired,
clearImportArtist: PropTypes.func.isRequired, metadataProfiles: PropTypes.arrayOf(PropTypes.object).isRequired,
fetchRootFolders: PropTypes.func.isRequired, defaultQualityProfileId: PropTypes.number.isRequired,
setAddArtistDefault: PropTypes.func.isRequired defaultLanguageProfileId: PropTypes.number.isRequired,
defaultMetadataProfileId: PropTypes.number.isRequired,
dispatchSetImportArtistValue: PropTypes.func.isRequired,
dispatchImportArtist: PropTypes.func.isRequired,
dispatchClearImportArtist: PropTypes.func.isRequired,
dispatchFetchRootFolders: PropTypes.func.isRequired,
dispatchSetAddArtistDefault: PropTypes.func.isRequired
}; };
export default connect(createMapStateToProps, mapDispatchToProps)(ImportArtistConnector); export default connect(createMapStateToProps, mapDispatchToProps)(ImportArtistConnector);

@ -35,21 +35,25 @@ function createMapStateToProps() {
(state) => state.app, (state) => state.app,
createDimensionsSelector(), createDimensionsSelector(),
(artist, tags, settings, app, dimensions) => { (artist, tags, settings, app, dimensions) => {
const isPopulated = artist.isPopulated && const isPopulated = (
artist.isPopulated &&
tags.isPopulated && tags.isPopulated &&
settings.qualityProfiles.isPopulated && settings.qualityProfiles.isPopulated &&
settings.languageProfiles.isPopulated && settings.languageProfiles.isPopulated &&
settings.metadataProfiles.isPopulated && settings.metadataProfiles.isPopulated &&
settings.importLists.isPopulated && settings.importLists.isPopulated &&
settings.ui.isPopulated; settings.ui.isPopulated
);
const hasError = !!artist.error ||
!!tags.error || const hasError = !!(
!!settings.qualityProfiles.error || artist.error ||
!!settings.languageProfiles.error || tags.error ||
!!settings.metadataProfiles.error || settings.qualityProfiles.error ||
!!settings.importLists.error || settings.languageProfiles.error ||
!!settings.ui.error; settings.metadataProfiles.error ||
settings.importLists.error ||
settings.ui.error
);
return { return {
isPopulated, isPopulated,

Loading…
Cancel
Save