mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-17 21:25:39 -04:00
New: Load all books on page load and store in the browser
This commit is contained in:
@@ -48,10 +48,11 @@ function createMapStateToProps() {
|
||||
createUISettingsSelector(),
|
||||
createDimensionsSelector(),
|
||||
(titleSlug, bookFiles, books, authors, commands, uiSettings, dimensions) => {
|
||||
const sortedBooks = _.orderBy(books.items, 'releaseDate');
|
||||
const bookIndex = _.findIndex(sortedBooks, { titleSlug });
|
||||
const book = sortedBooks[bookIndex];
|
||||
const author = _.find(authors, { id: book.authorId });
|
||||
const book = books.items.find((b) => b.titleSlug === titleSlug);
|
||||
const author = authors.find((a) => a.id === book.authorId);
|
||||
const sortedBooks = books.items.filter((b) => b.authorId === book.authorId);
|
||||
sortedBooks.sort((a, b) => ((a.releaseDate > b.releaseDate) ? 1 : -1));
|
||||
const bookIndex = sortedBooks.findIndex((b) => b.id === book.id);
|
||||
|
||||
if (!book) {
|
||||
return {};
|
||||
|
||||
@@ -8,7 +8,6 @@ import LoadingIndicator from 'Components/Loading/LoadingIndicator';
|
||||
import NotFound from 'Components/NotFound';
|
||||
import PageContent from 'Components/Page/PageContent';
|
||||
import PageContentBody from 'Components/Page/PageContentBody';
|
||||
import { clearBooks, fetchBooks } from 'Store/Actions/bookActions';
|
||||
import translate from 'Utilities/String/translate';
|
||||
import BookDetailsConnector from './BookDetailsConnector';
|
||||
|
||||
@@ -44,9 +43,7 @@ function createMapStateToProps() {
|
||||
}
|
||||
|
||||
const mapDispatchToProps = {
|
||||
push,
|
||||
fetchBooks,
|
||||
clearBooks
|
||||
push
|
||||
};
|
||||
|
||||
class BookDetailsPageConnector extends Component {
|
||||
@@ -62,24 +59,11 @@ class BookDetailsPageConnector extends Component {
|
||||
this.populate();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.unpopulate();
|
||||
}
|
||||
|
||||
//
|
||||
// Control
|
||||
|
||||
populate = () => {
|
||||
const titleSlug = this.props.titleSlug;
|
||||
this.setState({ hasMounted: true });
|
||||
this.props.fetchBooks({
|
||||
titleSlug,
|
||||
includeAllAuthorBooks: true
|
||||
});
|
||||
}
|
||||
|
||||
unpopulate = () => {
|
||||
this.props.clearBooks();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -125,8 +109,6 @@ BookDetailsPageConnector.propTypes = {
|
||||
titleSlug: PropTypes.string,
|
||||
match: PropTypes.shape({ params: PropTypes.shape({ titleSlug: PropTypes.string.isRequired }).isRequired }).isRequired,
|
||||
push: PropTypes.func.isRequired,
|
||||
fetchBooks: PropTypes.func.isRequired,
|
||||
clearBooks: PropTypes.func.isRequired,
|
||||
isFetching: PropTypes.bool.isRequired,
|
||||
isPopulated: PropTypes.bool.isRequired
|
||||
};
|
||||
|
||||
@@ -5,7 +5,6 @@ import { connect } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import * as commandNames from 'Commands/commandNames';
|
||||
import withScrollPosition from 'Components/withScrollPosition';
|
||||
import { clearBooks, fetchBooks } from 'Store/Actions/bookActions';
|
||||
import { setBookFilter, setBookSort, setBookTableOption, setBookView } from 'Store/Actions/bookIndexActions';
|
||||
import { executeCommand } from 'Store/Actions/commandActions';
|
||||
import scrollPositions from 'Store/scrollPositions';
|
||||
@@ -67,42 +66,12 @@ function createMapDispatchToProps(dispatch, props) {
|
||||
dispatch(executeCommand({
|
||||
name: commandNames.RSS_SYNC
|
||||
}));
|
||||
},
|
||||
|
||||
dispatchFetchBooks() {
|
||||
dispatch(fetchBooks());
|
||||
},
|
||||
|
||||
dispatchClearBooks() {
|
||||
dispatch(clearBooks());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class BookIndexConnector extends Component {
|
||||
|
||||
//
|
||||
// Lifecycle
|
||||
|
||||
componentDidMount() {
|
||||
this.populate();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.unpopulate();
|
||||
}
|
||||
|
||||
//
|
||||
// Control
|
||||
|
||||
populate = () => {
|
||||
this.props.dispatchFetchBooks();
|
||||
}
|
||||
|
||||
unpopulate = () => {
|
||||
this.props.dispatchClearBooks();
|
||||
}
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
@@ -131,8 +100,6 @@ class BookIndexConnector extends Component {
|
||||
BookIndexConnector.propTypes = {
|
||||
isSmallScreen: PropTypes.bool.isRequired,
|
||||
view: PropTypes.string.isRequired,
|
||||
dispatchFetchBooks: PropTypes.func.isRequired,
|
||||
dispatchClearBooks: PropTypes.func.isRequired,
|
||||
dispatchSetBookView: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user