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/Album/Edit/EditAlbumModalContentConnec...

99 lines
2.4 KiB

import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
4 years ago
import { saveAlbum, setAlbumValue } from 'Store/Actions/albumActions';
import createAlbumSelector from 'Store/Selectors/createAlbumSelector';
import createArtistSelector from 'Store/Selectors/createArtistSelector';
4 years ago
import selectSettings from 'Store/Selectors/selectSettings';
import EditAlbumModalContent from './EditAlbumModalContent';
function createMapStateToProps() {
return createSelector(
(state) => state.albums,
createAlbumSelector(),
createArtistSelector(),
(albumState, album, artist) => {
const {
isSaving,
saveError,
pendingChanges
} = albumState;
const albumSettings = _.pick(album, [
'monitored',
'anyReleaseOk',
'releases'
]);
const settings = selectSettings(albumSettings, pendingChanges, saveError);
return {
title: album.title,
artistName: artist.artistName,
albumType: album.albumType,
statistics: album.statistics,
isSaving,
saveError,
item: settings.settings,
...settings
};
}
);
}
const mapDispatchToProps = {
dispatchSetAlbumValue: setAlbumValue,
dispatchSaveAlbum: saveAlbum
};
class EditAlbumModalContentConnector extends Component {
//
// Lifecycle
componentDidUpdate(prevProps, prevState) {
if (prevProps.isSaving && !this.props.isSaving && !this.props.saveError) {
this.props.onModalClose();
}
}
//
// Listeners
onInputChange = ({ name, value }) => {
this.props.dispatchSetAlbumValue({ name, value });
};
onSavePress = () => {
this.props.dispatchSaveAlbum({
id: this.props.albumId
});
};
//
// Render
render() {
return (
<EditAlbumModalContent
{...this.props}
onInputChange={this.onInputChange}
onSavePress={this.onSavePress}
/>
);
}
}
EditAlbumModalContentConnector.propTypes = {
albumId: PropTypes.number,
isSaving: PropTypes.bool.isRequired,
saveError: PropTypes.object,
dispatchSetAlbumValue: PropTypes.func.isRequired,
dispatchSaveAlbum: PropTypes.func.isRequired,
onModalClose: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, mapDispatchToProps)(EditAlbumModalContentConnector);