mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-08 14:01:54 -07:00
parent
6855a7848e
commit
002234f71b
2 changed files with 54 additions and 31 deletions
|
@ -23,10 +23,10 @@ function createMapStateToProps() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
setMetadataProviderValue,
|
dispatchFetchMetadataProvider: fetchMetadataProvider,
|
||||||
saveMetadataProvider,
|
dispatchSetMetadataProviderValue: setMetadataProviderValue,
|
||||||
fetchMetadataProvider,
|
dispatchSaveMetadataProvider: saveMetadataProvider,
|
||||||
clearPendingChanges
|
dispatchClearPendingChanges: clearPendingChanges
|
||||||
};
|
};
|
||||||
|
|
||||||
class MetadataProviderConnector extends Component {
|
class MetadataProviderConnector extends Component {
|
||||||
|
@ -35,31 +35,43 @@ class MetadataProviderConnector extends Component {
|
||||||
// Lifecycle
|
// Lifecycle
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.fetchMetadataProvider();
|
const {
|
||||||
|
dispatchFetchMetadataProvider,
|
||||||
|
dispatchSaveMetadataProvider,
|
||||||
|
onChildMounted
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
dispatchFetchMetadataProvider();
|
||||||
|
onChildMounted(dispatchSaveMetadataProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
if (this.props.hasPendingChanges !== prevProps.hasPendingChanges) {
|
const {
|
||||||
this.props.onHasPendingChange(this.props.hasPendingChanges);
|
hasPendingChanges,
|
||||||
|
isSaving,
|
||||||
|
onChildStateChange
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
if (
|
||||||
|
prevProps.isSaving !== isSaving ||
|
||||||
|
prevProps.hasPendingChanges !== hasPendingChanges
|
||||||
|
) {
|
||||||
|
onChildStateChange({
|
||||||
|
isSaving,
|
||||||
|
hasPendingChanges
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.props.clearPendingChanges({ section: SECTION });
|
this.props.dispatchClearPendingChanges({ section: SECTION });
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Control
|
|
||||||
|
|
||||||
save = () => {
|
|
||||||
this.props.saveMetadataProvider();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Listeners
|
// Listeners
|
||||||
|
|
||||||
onInputChange = ({ name, value }) => {
|
onInputChange = ({ name, value }) => {
|
||||||
this.props.setMetadataProviderValue({ name, value });
|
this.props.dispatchSetMetadataProviderValue({ name, value });
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -76,12 +88,14 @@ class MetadataProviderConnector extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
MetadataProviderConnector.propTypes = {
|
MetadataProviderConnector.propTypes = {
|
||||||
|
isSaving: PropTypes.bool.isRequired,
|
||||||
hasPendingChanges: PropTypes.bool.isRequired,
|
hasPendingChanges: PropTypes.bool.isRequired,
|
||||||
setMetadataProviderValue: PropTypes.func.isRequired,
|
dispatchFetchMetadataProvider: PropTypes.func.isRequired,
|
||||||
saveMetadataProvider: PropTypes.func.isRequired,
|
dispatchSetMetadataProviderValue: PropTypes.func.isRequired,
|
||||||
fetchMetadataProvider: PropTypes.func.isRequired,
|
dispatchSaveMetadataProvider: PropTypes.func.isRequired,
|
||||||
clearPendingChanges: PropTypes.func.isRequired,
|
dispatchClearPendingChanges: PropTypes.func.isRequired,
|
||||||
onHasPendingChange: PropTypes.func.isRequired
|
onChildMounted: PropTypes.func.isRequired,
|
||||||
|
onChildStateChange: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(createMapStateToProps, mapDispatchToProps)(MetadataProviderConnector);
|
export default connect(createMapStateToProps, mapDispatchToProps)(MetadataProviderConnector);
|
||||||
|
|
|
@ -13,7 +13,10 @@ class MetadataSettings extends Component {
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
|
|
||||||
|
this._saveCallback = null;
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
isSaving: false,
|
||||||
hasPendingChanges: false
|
hasPendingChanges: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -21,35 +24,41 @@ class MetadataSettings extends Component {
|
||||||
//
|
//
|
||||||
// Listeners
|
// Listeners
|
||||||
|
|
||||||
setMetadataProviderRef = (ref) => {
|
onChildMounted = (saveCallback) => {
|
||||||
this._metadataProvider = ref;
|
this._saveCallback = saveCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
onHasPendingChange = (hasPendingChanges) => {
|
onChildStateChange = (payload) => {
|
||||||
this.setState({
|
this.setState(payload);
|
||||||
hasPendingChanges
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onSavePress = () => {
|
onSavePress = () => {
|
||||||
this._metadataProvider.getWrappedInstance().save();
|
if (this._saveCallback) {
|
||||||
|
this._saveCallback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Render
|
// Render
|
||||||
render() {
|
render() {
|
||||||
|
const {
|
||||||
|
isSaving,
|
||||||
|
hasPendingChanges
|
||||||
|
} = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContent title="Metadata Settings">
|
<PageContent title="Metadata Settings">
|
||||||
<SettingsToolbarConnector
|
<SettingsToolbarConnector
|
||||||
hasPendingChanges={this.state.hasPendingChanges}
|
isSaving={isSaving}
|
||||||
|
hasPendingChanges={hasPendingChanges}
|
||||||
onSavePress={this.onSavePress}
|
onSavePress={this.onSavePress}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<PageContentBodyConnector>
|
<PageContentBodyConnector>
|
||||||
<MetadatasConnector />
|
<MetadatasConnector />
|
||||||
<MetadataProviderConnector
|
<MetadataProviderConnector
|
||||||
ref={this.setMetadataProviderRef}
|
onChildMounted={this.onChildMounted}
|
||||||
onHasPendingChange={this.onHasPendingChange}
|
onChildStateChange={this.onChildStateChange}
|
||||||
/>
|
/>
|
||||||
</PageContentBodyConnector>
|
</PageContentBodyConnector>
|
||||||
</PageContent>
|
</PageContent>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue