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.
Lidarr/frontend/src/AddArtist/ImportArtist/Import/SelectArtist/ImportArtistSelectArtistCon...

72 lines
1.7 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 createImportArtistItemSelector from 'Store/Selectors/createImportArtistItemSelector';
import ImportArtistSelectArtist from './ImportArtistSelectArtist';
function createMapStateToProps() {
return createSelector(
createImportArtistItemSelector(),
(item) => {
return item;
}
);
}
const mapDispatchToProps = {
queueLookupArtist,
setImportArtistValue
};
class ImportArtistSelectArtistConnector extends Component {
//
// Listeners
onSearchInputChange = (term) => {
this.props.queueLookupArtist({
name: this.props.id,
term
});
}
onArtistSelect = (foreignArtistId) => {
const {
id,
items
} = this.props;
this.props.setImportArtistValue({
id,
selectedArtist: _.find(items, { foreignArtistId })
});
}
//
// Render
render() {
return (
<ImportArtistSelectArtist
{...this.props}
onSearchInputChange={this.onSearchInputChange}
onArtistSelect={this.onArtistSelect}
/>
);
}
}
ImportArtistSelectArtistConnector.propTypes = {
id: PropTypes.string.isRequired,
items: PropTypes.arrayOf(PropTypes.object),
selectedArtist: PropTypes.object,
isSelected: PropTypes.bool,
queueLookupArtist: PropTypes.func.isRequired,
setImportArtistValue: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, mapDispatchToProps)(ImportArtistSelectArtistConnector);