mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
New: Newznab/Torznab categories dropdown with indexer provided category names
This commit is contained in:
parent
2d8657a77f
commit
9b1bbaef02
22 changed files with 429 additions and 36 deletions
|
@ -1,3 +1,4 @@
|
|||
import _ from 'lodash';
|
||||
import { createAction } from 'redux-actions';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import requestAction from 'Utilities/requestAction';
|
||||
|
@ -10,6 +11,9 @@ import createHandleActions from './Creators/createHandleActions';
|
|||
|
||||
export const section = 'providerOptions';
|
||||
|
||||
const lastActions = {};
|
||||
let lastActionId = 0;
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
|
@ -23,8 +27,8 @@ export const defaultState = {
|
|||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_OPTIONS = 'devices/fetchOptions';
|
||||
export const CLEAR_OPTIONS = 'devices/clearOptions';
|
||||
export const FETCH_OPTIONS = 'providers/fetchOptions';
|
||||
export const CLEAR_OPTIONS = 'providers/clearOptions';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
@ -38,30 +42,55 @@ export const clearOptions = createAction(CLEAR_OPTIONS);
|
|||
export const actionHandlers = handleThunks({
|
||||
|
||||
[FETCH_OPTIONS]: function(getState, payload, dispatch) {
|
||||
const subsection = `${section}.${payload.section}`;
|
||||
|
||||
if (lastActions[payload.section] && _.isEqual(payload, lastActions[payload.section].payload)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const actionId = ++lastActionId;
|
||||
|
||||
lastActions[payload.section] = {
|
||||
actionId,
|
||||
payload
|
||||
};
|
||||
|
||||
dispatch(set({
|
||||
section,
|
||||
section: subsection,
|
||||
isFetching: true
|
||||
}));
|
||||
|
||||
const promise = requestAction(payload);
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: true,
|
||||
error: null,
|
||||
items: data.options || []
|
||||
}));
|
||||
if (lastActions[payload.section]) {
|
||||
if (lastActions[payload.section].actionId === actionId) {
|
||||
lastActions[payload.section] = null;
|
||||
}
|
||||
|
||||
dispatch(set({
|
||||
section: subsection,
|
||||
isFetching: false,
|
||||
isPopulated: true,
|
||||
error: null,
|
||||
items: data.options || []
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: xhr
|
||||
}));
|
||||
if (lastActions[payload.section]) {
|
||||
if (lastActions[payload.section].actionId === actionId) {
|
||||
lastActions[payload.section] = null;
|
||||
}
|
||||
|
||||
dispatch(set({
|
||||
section: subsection,
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: xhr
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -71,8 +100,12 @@ export const actionHandlers = handleThunks({
|
|||
|
||||
export const reducers = createHandleActions({
|
||||
|
||||
[CLEAR_OPTIONS]: function(state) {
|
||||
return updateSectionState(state, section, defaultState);
|
||||
[CLEAR_OPTIONS]: function(state, { payload }) {
|
||||
const subsection = `${section}.${payload.section}`;
|
||||
|
||||
lastActions[payload.section] = null;
|
||||
|
||||
return updateSectionState(state, subsection, defaultState);
|
||||
}
|
||||
|
||||
}, defaultState, section);
|
||||
}, {}, section);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue