New: Load all books on page load and store in the browser

This commit is contained in:
ta264
2021-09-01 21:04:39 +01:00
parent 2558660b7b
commit 468ebc3307
18 changed files with 172 additions and 191 deletions

View File

@@ -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 {};

View File

@@ -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
};

View File

@@ -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
};