New: Newznab/Torznab categories dropdown with indexer provided category names

Signed-off-by: Robin Dadswell <robin@dadswell.email>
This commit is contained in:
Taloth
2020-10-08 23:33:13 +02:00
committed by Qstick
parent b4289664dc
commit 7f64162a7a
22 changed files with 428 additions and 35 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);