mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-30 05:45:31 +02:00
Fixed: Backend Updates from Sonarr
Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com> Co-Authored-By: taloth <taloth@users.noreply.github.com>
This commit is contained in:
78
frontend/src/Store/Actions/providerOptionActions.js
Normal file
78
frontend/src/Store/Actions/providerOptionActions.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import requestAction from 'Utilities/requestAction';
|
||||
import updateSectionState from 'Utilities/State/updateSectionState';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import { set } from './baseActions';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
export const section = 'providerOptions';
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
export const defaultState = {
|
||||
items: [],
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: false
|
||||
};
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_OPTIONS = 'devices/fetchOptions';
|
||||
export const CLEAR_OPTIONS = 'devices/clearOptions';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchOptions = createThunk(FETCH_OPTIONS);
|
||||
export const clearOptions = createAction(CLEAR_OPTIONS);
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
export const actionHandlers = handleThunks({
|
||||
|
||||
[FETCH_OPTIONS]: function(getState, payload, dispatch) {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: true
|
||||
}));
|
||||
|
||||
const promise = requestAction(payload);
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: true,
|
||||
error: null,
|
||||
items: data.options || []
|
||||
}));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: xhr
|
||||
}));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
export const reducers = createHandleActions({
|
||||
|
||||
[CLEAR_OPTIONS]: function(state) {
|
||||
return updateSectionState(state, section, defaultState);
|
||||
}
|
||||
|
||||
}, defaultState, section);
|
Reference in New Issue
Block a user