mirror of
https://github.com/Readarr/Readarr
synced 2025-12-10 10:22:31 +01:00
New: Add option to only monitor selected book when adding single book
This commit is contained in:
parent
a1c2986af8
commit
33e5351add
8 changed files with 63 additions and 75 deletions
|
|
@ -7,6 +7,7 @@ function MonitorBooksSelectInput(props) {
|
|||
const {
|
||||
includeNoChange,
|
||||
includeMixed,
|
||||
includeSpecificBook,
|
||||
...otherProps
|
||||
} = props;
|
||||
|
||||
|
|
@ -28,6 +29,13 @@ function MonitorBooksSelectInput(props) {
|
|||
});
|
||||
}
|
||||
|
||||
if (includeSpecificBook) {
|
||||
values.push({
|
||||
key: 'specificBook',
|
||||
value: 'Only This Book'
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<SelectInput
|
||||
values={values}
|
||||
|
|
@ -39,12 +47,14 @@ function MonitorBooksSelectInput(props) {
|
|||
MonitorBooksSelectInput.propTypes = {
|
||||
includeNoChange: PropTypes.bool.isRequired,
|
||||
includeMixed: PropTypes.bool.isRequired,
|
||||
includeSpecificBook: PropTypes.bool.isRequired,
|
||||
onChange: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
MonitorBooksSelectInput.defaultProps = {
|
||||
includeNoChange: false,
|
||||
includeMixed: false
|
||||
includeMixed: false,
|
||||
includeSpecificBook: false
|
||||
};
|
||||
|
||||
export default MonitorBooksSelectInput;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
|
|||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import { addAuthor, setAddDefault } from 'Store/Actions/searchActions';
|
||||
import { addAuthor, setAuthorAddDefault } from 'Store/Actions/searchActions';
|
||||
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
|
||||
import selectSettings from 'Store/Selectors/selectSettings';
|
||||
import AddNewAuthorModalContent from './AddNewAuthorModalContent';
|
||||
|
|
@ -16,14 +16,14 @@ function createMapStateToProps() {
|
|||
const {
|
||||
isAdding,
|
||||
addError,
|
||||
defaults
|
||||
authorDefaults
|
||||
} = searchState;
|
||||
|
||||
const {
|
||||
settings,
|
||||
validationErrors,
|
||||
validationWarnings
|
||||
} = selectSettings(defaults, {}, addError);
|
||||
} = selectSettings(authorDefaults, {}, addError);
|
||||
|
||||
return {
|
||||
isAdding,
|
||||
|
|
@ -39,7 +39,7 @@ function createMapStateToProps() {
|
|||
}
|
||||
|
||||
const mapDispatchToProps = {
|
||||
setAddDefault,
|
||||
setAuthorAddDefault,
|
||||
addAuthor
|
||||
};
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ class AddNewAuthorModalContentConnector extends Component {
|
|||
// Listeners
|
||||
|
||||
onInputChange = ({ name, value }) => {
|
||||
this.props.setAddDefault({ [name]: value });
|
||||
this.props.setAuthorAddDefault({ [name]: value });
|
||||
}
|
||||
|
||||
onAddAuthorPress = (searchForMissingBooks) => {
|
||||
|
|
@ -95,7 +95,7 @@ AddNewAuthorModalContentConnector.propTypes = {
|
|||
metadataProfileId: PropTypes.object,
|
||||
tags: PropTypes.object.isRequired,
|
||||
onModalClose: PropTypes.func.isRequired,
|
||||
setAddDefault: PropTypes.func.isRequired,
|
||||
setAuthorAddDefault: PropTypes.func.isRequired,
|
||||
addAuthor: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ class AddNewBookModalContent extends Component {
|
|||
<AddAuthorOptionsForm
|
||||
authorName={authorName}
|
||||
includeNoneMetadataProfile={true}
|
||||
includeSpecificBookMonitor={true}
|
||||
{...otherProps}
|
||||
/>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import PropTypes from 'prop-types';
|
|||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import { metadataProfileNames } from 'Helpers/Props';
|
||||
import { addBook, setAddDefault } from 'Store/Actions/searchActions';
|
||||
import { addBook, setBookAddDefault } from 'Store/Actions/searchActions';
|
||||
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
|
||||
import selectSettings from 'Store/Selectors/selectSettings';
|
||||
import AddNewBookModalContent from './AddNewBookModalContent';
|
||||
|
|
@ -18,17 +17,14 @@ function createMapStateToProps() {
|
|||
const {
|
||||
isAdding,
|
||||
addError,
|
||||
defaults
|
||||
bookDefaults
|
||||
} = searchState;
|
||||
|
||||
const {
|
||||
settings,
|
||||
validationErrors,
|
||||
validationWarnings
|
||||
} = selectSettings(defaults, {}, addError);
|
||||
|
||||
// For adding single books, default to None profile
|
||||
const noneProfile = metadataProfiles.items.find((item) => item.name === metadataProfileNames.NONE);
|
||||
} = selectSettings(bookDefaults, {}, addError);
|
||||
|
||||
return {
|
||||
isAdding,
|
||||
|
|
@ -37,7 +33,6 @@ function createMapStateToProps() {
|
|||
isSmallScreen: dimensions.isSmallScreen,
|
||||
validationErrors,
|
||||
validationWarnings,
|
||||
noneMetadataProfileId: noneProfile.id,
|
||||
...settings
|
||||
};
|
||||
}
|
||||
|
|
@ -45,39 +40,17 @@ function createMapStateToProps() {
|
|||
}
|
||||
|
||||
const mapDispatchToProps = {
|
||||
setAddDefault,
|
||||
setBookAddDefault,
|
||||
addBook
|
||||
};
|
||||
|
||||
class AddNewBookModalContentConnector extends Component {
|
||||
|
||||
//
|
||||
// Lifecycle
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
this.state = {
|
||||
metadataProfileIdDefault: props.metadataProfileId.value
|
||||
};
|
||||
|
||||
// select none as default
|
||||
this.onInputChange({
|
||||
name: 'metadataProfileId',
|
||||
value: props.noneMetadataProfileId
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
// reinstate standard default
|
||||
this.props.setAddDefault({ metadataProfileId: this.state.metadataProfileIdDefault });
|
||||
}
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onInputChange = ({ name, value }) => {
|
||||
this.props.setAddDefault({ [name]: value });
|
||||
this.props.setBookAddDefault({ [name]: value });
|
||||
}
|
||||
|
||||
onAddBookPress = (searchForNewBook) => {
|
||||
|
|
@ -122,10 +95,9 @@ AddNewBookModalContentConnector.propTypes = {
|
|||
monitor: PropTypes.object.isRequired,
|
||||
qualityProfileId: PropTypes.object,
|
||||
metadataProfileId: PropTypes.object,
|
||||
noneMetadataProfileId: PropTypes.number.isRequired,
|
||||
tags: PropTypes.object.isRequired,
|
||||
onModalClose: PropTypes.func.isRequired,
|
||||
setAddDefault: PropTypes.func.isRequired,
|
||||
setBookAddDefault: PropTypes.func.isRequired,
|
||||
addBook: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class AddAuthorOptionsForm extends Component {
|
|||
qualityProfileId,
|
||||
metadataProfileId,
|
||||
includeNoneMetadataProfile,
|
||||
includeSpecificBookMonitor,
|
||||
showMetadataProfile,
|
||||
tags,
|
||||
onInputChange,
|
||||
|
|
@ -77,6 +78,7 @@ class AddAuthorOptionsForm extends Component {
|
|||
type={inputTypes.MONITOR_BOOKS_SELECT}
|
||||
name="monitor"
|
||||
onChange={onInputChange}
|
||||
includeSpecificBook={includeSpecificBookMonitor}
|
||||
{...monitor}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
|
@ -147,6 +149,7 @@ AddAuthorOptionsForm.propTypes = {
|
|||
metadataProfileId: PropTypes.object,
|
||||
showMetadataProfile: PropTypes.bool.isRequired,
|
||||
includeNoneMetadataProfile: PropTypes.bool.isRequired,
|
||||
includeSpecificBookMonitor: PropTypes.bool.isRequired,
|
||||
tags: PropTypes.object.isRequired,
|
||||
onInputChange: PropTypes.func.isRequired
|
||||
};
|
||||
|
|
|
|||
|
|
@ -29,7 +29,15 @@ export const defaultState = {
|
|||
addError: null,
|
||||
items: [],
|
||||
|
||||
defaults: {
|
||||
authorDefaults: {
|
||||
rootFolderPath: '',
|
||||
monitor: monitorOptions[0].key,
|
||||
qualityProfileId: 0,
|
||||
metadataProfileId: 0,
|
||||
tags: []
|
||||
},
|
||||
|
||||
bookDefaults: {
|
||||
rootFolderPath: '',
|
||||
monitor: monitorOptions[0].key,
|
||||
qualityProfileId: 0,
|
||||
|
|
@ -39,7 +47,8 @@ export const defaultState = {
|
|||
};
|
||||
|
||||
export const persistState = [
|
||||
'search.defaults'
|
||||
'search.bookDefaults',
|
||||
'search.authorDefaults'
|
||||
];
|
||||
|
||||
//
|
||||
|
|
@ -49,7 +58,8 @@ export const GET_SEARCH_RESULTS = 'search/getSearchResults';
|
|||
export const ADD_AUTHOR = 'search/addAuthor';
|
||||
export const ADD_BOOK = 'search/addBook';
|
||||
export const CLEAR_SEARCH_RESULTS = 'search/clearSearchResults';
|
||||
export const SET_ADD_DEFAULT = 'search/setAddDefault';
|
||||
export const SET_AUTHOR_ADD_DEFAULT = 'search/setAuthorAddDefault';
|
||||
export const SET_BOOK_ADD_DEFAULT = 'search/setBookAddDefault';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
|
@ -58,7 +68,8 @@ export const getSearchResults = createThunk(GET_SEARCH_RESULTS);
|
|||
export const addAuthor = createThunk(ADD_AUTHOR);
|
||||
export const addBook = createThunk(ADD_BOOK);
|
||||
export const clearSearchResults = createAction(CLEAR_SEARCH_RESULTS);
|
||||
export const setAddDefault = createAction(SET_ADD_DEFAULT);
|
||||
export const setAuthorAddDefault = createAction(SET_AUTHOR_ADD_DEFAULT);
|
||||
export const setBookAddDefault = createAction(SET_BOOK_ADD_DEFAULT);
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
|
@ -191,11 +202,22 @@ export const actionHandlers = handleThunks({
|
|||
|
||||
export const reducers = createHandleActions({
|
||||
|
||||
[SET_ADD_DEFAULT]: function(state, { payload }) {
|
||||
[SET_AUTHOR_ADD_DEFAULT]: function(state, { payload }) {
|
||||
const newState = getSectionState(state, section);
|
||||
|
||||
newState.defaults = {
|
||||
...newState.defaults,
|
||||
newState.authorDefaults = {
|
||||
...newState.authorDefaults,
|
||||
...payload
|
||||
};
|
||||
|
||||
return updateSectionState(state, section, newState);
|
||||
},
|
||||
|
||||
[SET_BOOK_ADD_DEFAULT]: function(state, { payload }) {
|
||||
const newState = getSectionState(state, section);
|
||||
|
||||
newState.bookDefaults = {
|
||||
...newState.bookDefaults,
|
||||
...payload
|
||||
};
|
||||
|
||||
|
|
@ -204,7 +226,8 @@ export const reducers = createHandleActions({
|
|||
|
||||
[CLEAR_SEARCH_RESULTS]: function(state) {
|
||||
const {
|
||||
defaults,
|
||||
authorDefaults,
|
||||
bookDefaults,
|
||||
...otherDefaultState
|
||||
} = defaultState;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
import _ from 'lodash';
|
||||
import { createSelector } from 'reselect';
|
||||
import createAllAuthorsSelector from './createAllAuthorsSelector';
|
||||
|
||||
function createImportAuthorItemSelector() {
|
||||
return createSelector(
|
||||
(state, { id }) => id,
|
||||
(state) => state.addAuthor,
|
||||
(state) => state.importAuthor,
|
||||
createAllAuthorsSelector(),
|
||||
(id, addAuthor, importAuthor, author) => {
|
||||
const item = _.find(importAuthor.items, { id }) || {};
|
||||
const selectedAuthor = item && item.selectedAuthor;
|
||||
const isExistingAuthor = !!selectedAuthor && _.some(author, { titleSlug: selectedAuthor.titleSlug });
|
||||
|
||||
return {
|
||||
defaultMonitor: addAuthor.defaults.monitor,
|
||||
defaultQualityProfileId: addAuthor.defaults.qualityProfileId,
|
||||
...item,
|
||||
isExistingAuthor
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default createImportAuthorItemSelector;
|
||||
|
|
@ -7,6 +7,11 @@ function getNewBook(book, payload) {
|
|||
|
||||
if (!('id' in book.author) || book.author.id === 0) {
|
||||
getNewAuthor(book.author, payload);
|
||||
|
||||
if (payload.monitor === 'specificBook') {
|
||||
delete book.author.addOptions.monitor;
|
||||
book.author.addOptions.booksToMonitor = [book.foreignBookId];
|
||||
}
|
||||
}
|
||||
|
||||
book.addOptions = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue