New: Added book monitoring to author details

(cherry picked from commit 0ff889c3be1e8ee48759b233aeabf1bf1c4b4ff4)
(cherry picked from commit 0bd74098f9)
This commit is contained in:
Robin Dadswell
2021-09-02 21:12:13 +01:00
committed by ta264
parent 73950ca431
commit 2317665f33
8 changed files with 405 additions and 8 deletions
+50 -2
View File
@@ -5,7 +5,8 @@ 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 { set, updateItem } from './baseActions';
import { fetchBooks } from './bookActions';
import createFetchHandler from './Creators/createFetchHandler';
import createHandleActions from './Creators/createHandleActions';
import createRemoveItemHandler from './Creators/createRemoveItemHandler';
@@ -169,6 +170,7 @@ export const DELETE_AUTHOR = 'authors/deleteAuthor';
export const TOGGLE_AUTHOR_MONITORED = 'authors/toggleAuthorMonitored';
export const TOGGLE_BOOK_MONITORED = 'authors/toggleBookMonitored';
export const UPDATE_BOOK_MONITORED = 'authors/updateBookMonitored';
//
// Action Creators
@@ -202,6 +204,7 @@ export const deleteAuthor = createThunk(DELETE_AUTHOR, (payload) => {
export const toggleAuthorMonitored = createThunk(TOGGLE_AUTHOR_MONITORED);
export const toggleBookMonitored = createThunk(TOGGLE_BOOK_MONITORED);
export const updateBookMonitor = createThunk(UPDATE_BOOK_MONITORED);
export const setAuthorValue = createAction(SET_AUTHOR_VALUE, (payload) => {
return {
@@ -330,8 +333,53 @@ export const actionHandlers = handleThunks({
seasons: author.seasons
}));
});
}
},
[UPDATE_BOOK_MONITORED]: function(getState, payload, dispatch) {
const {
id,
monitor
} = payload;
const authorToUpdate = { id };
if (monitor !== 'None') {
authorToUpdate.monitored = true;
}
dispatch(set({
section,
isSaving: true
}));
const promise = createAjaxRequest({
url: '/bookshelf',
method: 'POST',
data: JSON.stringify({
authors: [{ id }],
monitoringOptions: { monitor }
}),
dataType: 'json'
}).request;
promise.done((data) => {
dispatch(fetchBooks({ authorId: id }));
dispatch(set({
section,
isSaving: false,
saveError: null
}));
});
promise.fail((xhr) => {
dispatch(set({
section,
isSaving: false,
saveError: xhr
}));
});
}
});
//
+42 -3
View File
@@ -6,8 +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 { removeItem, updateItem } from './baseActions';
import createFetchHandler from './Creators/createFetchHandler';
import { removeItem, set, update, updateItem } from './baseActions';
import createHandleActions from './Creators/createHandleActions';
import createRemoveItemHandler from './Creators/createRemoveItemHandler';
import createSaveProviderHandler from './Creators/createSaveProviderHandler';
@@ -259,7 +258,47 @@ export const setBookValue = createAction(SET_BOOK_VALUE, (payload) => {
// Action Handlers
export const actionHandlers = handleThunks({
[FETCH_BOOKS]: createFetchHandler(section, '/book'),
[FETCH_BOOKS]: function(getState, payload, dispatch) {
dispatch(set({ section, isFetching: true }));
const { request, abortRequest } = createAjaxRequest({
url: '/book',
data: payload,
traditional: true
});
request.done((data) => {
// Preserve books for other authors we didn't fetch
if (payload.hasOwnProperty('authorId')) {
const oldBooks = getState().books.items;
const newBooks = oldBooks.filter((x) => x.authorId !== payload.authorId);
data = newBooks.concat(data);
}
dispatch(batchActions([
update({ section, data }),
set({
section,
isFetching: false,
isPopulated: true,
error: null
})
]));
});
request.fail((xhr) => {
dispatch(set({
section,
isFetching: false,
isPopulated: false,
error: xhr.aborted ? null : xhr
}));
});
return abortRequest;
},
[SAVE_BOOK]: createSaveProviderHandler(section, '/book'),
[DELETE_BOOK]: createRemoveItemHandler(section, '/book'),