Lidarr/frontend/src/Artist/Editor/ArtistEditorConnector.js

93 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-09-04 02:20:56 +00:00
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
2017-09-04 02:20:56 +00:00
import { createSelector } from 'reselect';
2020-09-07 01:33:10 +00:00
import * as commandNames from 'Commands/commandNames';
import { saveArtistEditor, setArtistEditorFilter, setArtistEditorSort } from 'Store/Actions/artistEditorActions';
import { executeCommand } from 'Store/Actions/commandActions';
import { fetchRootFolders } from 'Store/Actions/settingsActions';
2017-09-04 02:20:56 +00:00
import createClientSideCollectionSelector from 'Store/Selectors/createClientSideCollectionSelector';
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
import ArtistEditor from './ArtistEditor';
2017-09-04 02:20:56 +00:00
function createMapStateToProps() {
return createSelector(
(state) => state.settings.metadataProfiles,
createClientSideCollectionSelector('artist', 'artistEditor'),
createCommandExecutingSelector(commandNames.RENAME_ARTIST),
createCommandExecutingSelector(commandNames.RETAG_ARTIST),
(metadataProfiles, artist, isOrganizingArtist, isRetaggingArtist) => {
2017-09-04 02:20:56 +00:00
return {
isOrganizingArtist,
isRetaggingArtist,
showMetadataProfile: metadataProfiles.items.length > 1,
2017-10-07 22:38:31 +00:00
...artist
2017-09-04 02:20:56 +00:00
};
}
);
}
const mapDispatchToProps = {
dispatchSetArtistEditorSort: setArtistEditorSort,
dispatchSetArtistEditorFilter: setArtistEditorFilter,
dispatchSaveArtistEditor: saveArtistEditor,
dispatchFetchRootFolders: fetchRootFolders,
dispatchExecuteCommand: executeCommand
2017-09-04 02:20:56 +00:00
};
class ArtistEditorConnector extends Component {
2017-09-04 02:20:56 +00:00
//
// Lifecycle
componentDidMount() {
this.props.dispatchFetchRootFolders();
2017-09-04 02:20:56 +00:00
}
//
// Listeners
onSortPress = (sortKey) => {
this.props.dispatchSetArtistEditorSort({ sortKey });
2017-09-04 02:20:56 +00:00
}
2018-03-15 01:28:46 +00:00
onFilterSelect = (selectedFilterKey) => {
this.props.dispatchSetArtistEditorFilter({ selectedFilterKey });
2017-09-04 02:20:56 +00:00
}
onSaveSelected = (payload) => {
this.props.dispatchSaveArtistEditor(payload);
}
onMoveSelected = (payload) => {
this.props.dispatchExecuteCommand({
name: commandNames.MOVE_ARTIST,
...payload
});
2017-09-04 02:20:56 +00:00
}
//
// Render
render() {
return (
<ArtistEditor
2017-09-04 02:20:56 +00:00
{...this.props}
onSortPress={this.onSortPress}
onFilterSelect={this.onFilterSelect}
onSaveSelected={this.onSaveSelected}
/>
);
}
}
ArtistEditorConnector.propTypes = {
dispatchSetArtistEditorSort: PropTypes.func.isRequired,
dispatchSetArtistEditorFilter: PropTypes.func.isRequired,
dispatchSaveArtistEditor: PropTypes.func.isRequired,
dispatchFetchRootFolders: PropTypes.func.isRequired,
dispatchExecuteCommand: PropTypes.func.isRequired
2017-09-04 02:20:56 +00:00
};
export default connect(createMapStateToProps, mapDispatchToProps)(ArtistEditorConnector);