You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.2 KiB
92 lines
2.2 KiB
import _ from 'lodash';
|
|
import PropTypes from 'prop-types';
|
|
import React, { Component } from 'react';
|
|
import { connect } from 'react-redux';
|
|
import { createSelector } from 'reselect';
|
|
import { queueLookupArtist, setImportArtistValue } from 'Store/Actions/importArtistActions';
|
|
import createAllArtistSelector from 'Store/Selectors/createAllArtistSelector';
|
|
import ImportArtistRow from './ImportArtistRow';
|
|
|
|
function createImportArtistItemSelector() {
|
|
return createSelector(
|
|
(state, { id }) => id,
|
|
(state) => state.importArtist.items,
|
|
(id, items) => {
|
|
return _.find(items, { id }) || {};
|
|
}
|
|
);
|
|
}
|
|
|
|
function createMapStateToProps() {
|
|
return createSelector(
|
|
createImportArtistItemSelector(),
|
|
createAllArtistSelector(),
|
|
(item, series) => {
|
|
const selectedArtist = item && item.selectedArtist;
|
|
const isExistingArtist = !!selectedArtist && _.some(series, { foreignArtistId: selectedArtist.foreignArtistId });
|
|
|
|
return {
|
|
...item,
|
|
isExistingArtist
|
|
};
|
|
}
|
|
);
|
|
}
|
|
|
|
const mapDispatchToProps = {
|
|
queueLookupArtist,
|
|
setImportArtistValue
|
|
};
|
|
|
|
class ImportArtistRowConnector extends Component {
|
|
|
|
//
|
|
// Listeners
|
|
|
|
onInputChange = ({ name, value }) => {
|
|
this.props.setImportArtistValue({
|
|
id: this.props.id,
|
|
[name]: value
|
|
});
|
|
}
|
|
|
|
//
|
|
// Render
|
|
|
|
render() {
|
|
// Don't show the row until we have the information we require for it.
|
|
|
|
const {
|
|
items,
|
|
monitor,
|
|
// seriesType,
|
|
albumFolder
|
|
} = this.props;
|
|
|
|
if (!items || !monitor || !albumFolder == null) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<ImportArtistRow
|
|
{...this.props}
|
|
onInputChange={this.onInputChange}
|
|
onArtistSelect={this.onArtistSelect}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
ImportArtistRowConnector.propTypes = {
|
|
rootFolderId: PropTypes.number.isRequired,
|
|
id: PropTypes.string.isRequired,
|
|
monitor: PropTypes.string,
|
|
// seriesType: PropTypes.string,
|
|
albumFolder: PropTypes.bool,
|
|
items: PropTypes.arrayOf(PropTypes.object),
|
|
queueLookupArtist: PropTypes.func.isRequired,
|
|
setImportArtistValue: PropTypes.func.isRequired
|
|
};
|
|
|
|
export default connect(createMapStateToProps, mapDispatchToProps)(ImportArtistRowConnector);
|