mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-25 22:36:59 -04:00
New: Load all books on page load and store in the browser
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import { sortDirections } from 'Helpers/Props';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import { set } from './baseActions';
|
||||
import { filterPredicates, sortPredicates } from './bookActions';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import createSetClientSideCollectionSortReducer from './Creators/Reducers/createSetClientSideCollectionSortReducer';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
export const section = 'authorDetails';
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
export const defaultState = {
|
||||
sortKey: 'releaseDate',
|
||||
sortDirection: sortDirections.DESCENDING,
|
||||
secondarySortKey: 'releaseDate',
|
||||
secondarySortDirection: sortDirections.DESCENDING,
|
||||
|
||||
selectedFilterKey: 'authorId',
|
||||
|
||||
sortPredicates: {
|
||||
...sortPredicates
|
||||
},
|
||||
|
||||
filters: [
|
||||
{
|
||||
key: 'authorId',
|
||||
label: 'Author',
|
||||
filters: [
|
||||
{
|
||||
key: 'authorId',
|
||||
value: 0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
filterPredicates
|
||||
|
||||
};
|
||||
|
||||
export const persistState = [
|
||||
'authorDetails.sortKey',
|
||||
'authorDetails.sortDirection'
|
||||
];
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const SET_AUTHOR_DETAILS_SORT = 'authorIndex/setAuthorDetailsSort';
|
||||
export const SET_AUTHOR_DETAILS_ID = 'authorIndex/setAuthorDetailsId';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const setAuthorDetailsSort = createAction(SET_AUTHOR_DETAILS_SORT);
|
||||
export const setAuthorDetailsId = createThunk(SET_AUTHOR_DETAILS_ID);
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
export const actionHandlers = handleThunks({
|
||||
[SET_AUTHOR_DETAILS_ID]: function(getState, payload, dispatch) {
|
||||
const {
|
||||
authorId
|
||||
} = payload;
|
||||
|
||||
dispatch(set({
|
||||
section,
|
||||
filters: [
|
||||
{
|
||||
key: 'authorId',
|
||||
label: 'Author',
|
||||
filters: [
|
||||
{
|
||||
key: 'authorId',
|
||||
value: authorId
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
export const reducers = createHandleActions({
|
||||
|
||||
[SET_AUTHOR_DETAILS_SORT]: createSetClientSideCollectionSortReducer(section)
|
||||
|
||||
}, defaultState, section);
|
||||
@@ -6,7 +6,7 @@ import { filterTypePredicates, filterTypes, sortDirections } from 'Helpers/Props
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
||||
import dateFilterPredicate from 'Utilities/Date/dateFilterPredicate';
|
||||
import { updateItem } from './baseActions';
|
||||
import { removeItem, updateItem } from './baseActions';
|
||||
import createFetchHandler from './Creators/createFetchHandler';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import createRemoveItemHandler from './Creators/createRemoveItemHandler';
|
||||
@@ -213,6 +213,7 @@ export const CLEAR_BOOKS = 'books/clearBooks';
|
||||
export const SET_BOOK_VALUE = 'books/setBookValue';
|
||||
export const SAVE_BOOK = 'books/saveBook';
|
||||
export const DELETE_BOOK = 'books/deleteBook';
|
||||
export const DELETE_AUTHOR_BOOKS = 'books/deleteAuthorBooks';
|
||||
export const TOGGLE_BOOK_MONITORED = 'books/toggleBookMonitored';
|
||||
export const TOGGLE_BOOKS_MONITORED = 'books/toggleBooksMonitored';
|
||||
|
||||
@@ -238,6 +239,15 @@ export const deleteBook = createThunk(DELETE_BOOK, (payload) => {
|
||||
};
|
||||
});
|
||||
|
||||
export const deleteAuthorBooks = createThunk(DELETE_AUTHOR_BOOKS, (payload) => {
|
||||
return {
|
||||
...payload,
|
||||
queryParams: {
|
||||
authorId: payload.authorId
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
export const setBookValue = createAction(SET_BOOK_VALUE, (payload) => {
|
||||
return {
|
||||
section: 'books',
|
||||
@@ -253,6 +263,15 @@ export const actionHandlers = handleThunks({
|
||||
[SAVE_BOOK]: createSaveProviderHandler(section, '/book'),
|
||||
[DELETE_BOOK]: createRemoveItemHandler(section, '/book'),
|
||||
|
||||
[DELETE_AUTHOR_BOOKS]: function(getState, payload, dispatch) {
|
||||
const { authorId } = payload;
|
||||
const books = getState().books.items;
|
||||
|
||||
const toDelete = books.filter((x) => x.authorId === authorId);
|
||||
|
||||
dispatch(batchActions(toDelete.map((b) => removeItem({ section, id: b.id }))));
|
||||
},
|
||||
|
||||
[TOGGLE_BOOK_MONITORED]: function(getState, payload, dispatch) {
|
||||
const {
|
||||
bookId,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as app from './appActions';
|
||||
import * as author from './authorActions';
|
||||
import * as authorDetails from './authorDetailsActions';
|
||||
import * as authorEditor from './authorEditorActions';
|
||||
import * as authorHistory from './authorHistoryActions';
|
||||
import * as authorIndex from './authorIndexActions';
|
||||
@@ -31,31 +32,32 @@ import * as wanted from './wantedActions';
|
||||
|
||||
export default [
|
||||
app,
|
||||
author,
|
||||
authorDetails,
|
||||
authorEditor,
|
||||
authorHistory,
|
||||
authorIndex,
|
||||
blacklist,
|
||||
captcha,
|
||||
calendar,
|
||||
commands,
|
||||
customFilters,
|
||||
books,
|
||||
bookFiles,
|
||||
bookHistory,
|
||||
bookIndex,
|
||||
books,
|
||||
bookStudio,
|
||||
calendar,
|
||||
captcha,
|
||||
commands,
|
||||
customFilters,
|
||||
history,
|
||||
interactiveImportActions,
|
||||
oAuth,
|
||||
organizePreview,
|
||||
retagPreview,
|
||||
paths,
|
||||
providerOptions,
|
||||
queue,
|
||||
releases,
|
||||
bookStudio,
|
||||
author,
|
||||
authorEditor,
|
||||
authorHistory,
|
||||
authorIndex,
|
||||
series,
|
||||
retagPreview,
|
||||
search,
|
||||
series,
|
||||
settings,
|
||||
system,
|
||||
tags,
|
||||
|
||||
@@ -163,6 +163,7 @@ export const actionHandlers = handleThunks({
|
||||
itemToAdd.book = data;
|
||||
dispatch(batchActions([
|
||||
updateItem({ section: 'authors', ...data.author }),
|
||||
updateItem({ section: 'books', ...data }),
|
||||
updateItem({ section, ...itemToAdd }),
|
||||
|
||||
set({
|
||||
|
||||
Reference in New Issue
Block a user