mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
Add support for Applications
This commit is contained in:
115
frontend/src/Store/Actions/Settings/applications.js
Normal file
115
frontend/src/Store/Actions/Settings/applications.js
Normal file
@@ -0,0 +1,115 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import createFetchHandler from 'Store/Actions/Creators/createFetchHandler';
|
||||
import createFetchSchemaHandler from 'Store/Actions/Creators/createFetchSchemaHandler';
|
||||
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
|
||||
import createSaveProviderHandler, { createCancelSaveProviderHandler } from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
import createTestProviderHandler, { createCancelTestProviderHandler } from 'Store/Actions/Creators/createTestProviderHandler';
|
||||
import createSetProviderFieldValueReducer from 'Store/Actions/Creators/Reducers/createSetProviderFieldValueReducer';
|
||||
import createSetSettingValueReducer from 'Store/Actions/Creators/Reducers/createSetSettingValueReducer';
|
||||
import { createThunk } from 'Store/thunks';
|
||||
import selectProviderSchema from 'Utilities/State/selectProviderSchema';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.applications';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_APPLICATIONS = 'settings/applications/fetchApplications';
|
||||
export const FETCH_APPLICATION_SCHEMA = 'settings/applications/fetchApplicationSchema';
|
||||
export const SELECT_APPLICATION_SCHEMA = 'settings/applications/selectApplicationSchema';
|
||||
export const SET_APPLICATION_VALUE = 'settings/applications/setApplicationValue';
|
||||
export const SET_APPLICATION_FIELD_VALUE = 'settings/applications/setApplicationFieldValue';
|
||||
export const SAVE_APPLICATION = 'settings/applications/saveApplication';
|
||||
export const CANCEL_SAVE_APPLICATION = 'settings/applications/cancelSaveApplication';
|
||||
export const DELETE_APPLICATION = 'settings/applications/deleteApplication';
|
||||
export const TEST_APPLICATION = 'settings/applications/testApplication';
|
||||
export const CANCEL_TEST_APPLICATION = 'settings/applications/cancelTestApplication';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchApplications = createThunk(FETCH_APPLICATIONS);
|
||||
export const fetchApplicationSchema = createThunk(FETCH_APPLICATION_SCHEMA);
|
||||
export const selectApplicationSchema = createAction(SELECT_APPLICATION_SCHEMA);
|
||||
|
||||
export const saveApplication = createThunk(SAVE_APPLICATION);
|
||||
export const cancelSaveApplication = createThunk(CANCEL_SAVE_APPLICATION);
|
||||
export const deleteApplication = createThunk(DELETE_APPLICATION);
|
||||
export const testApplication = createThunk(TEST_APPLICATION);
|
||||
export const cancelTestApplication = createThunk(CANCEL_TEST_APPLICATION);
|
||||
|
||||
export const setApplicationValue = createAction(SET_APPLICATION_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
export const setApplicationFieldValue = createAction(SET_APPLICATION_FIELD_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isSchemaFetching: false,
|
||||
isSchemaPopulated: false,
|
||||
schemaError: null,
|
||||
schema: [],
|
||||
selectedSchema: {},
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
isTesting: false,
|
||||
items: [],
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_APPLICATIONS]: createFetchHandler(section, '/applications'),
|
||||
[FETCH_APPLICATION_SCHEMA]: createFetchSchemaHandler(section, '/applications/schema'),
|
||||
|
||||
[SAVE_APPLICATION]: createSaveProviderHandler(section, '/applications'),
|
||||
[CANCEL_SAVE_APPLICATION]: createCancelSaveProviderHandler(section),
|
||||
[DELETE_APPLICATION]: createRemoveItemHandler(section, '/applications'),
|
||||
[TEST_APPLICATION]: createTestProviderHandler(section, '/applications'),
|
||||
[CANCEL_TEST_APPLICATION]: createCancelTestProviderHandler(section)
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_APPLICATION_VALUE]: createSetSettingValueReducer(section),
|
||||
[SET_APPLICATION_FIELD_VALUE]: createSetProviderFieldValueReducer(section),
|
||||
|
||||
[SELECT_APPLICATION_SCHEMA]: (state, { payload }) => {
|
||||
return selectProviderSchema(state, section, payload, (selectedSchema) => {
|
||||
selectedSchema.onGrab = selectedSchema.supportsOnGrab;
|
||||
selectedSchema.onDownload = selectedSchema.supportsOnDownload;
|
||||
selectedSchema.onUpgrade = selectedSchema.supportsOnUpgrade;
|
||||
selectedSchema.onRename = selectedSchema.supportsOnRename;
|
||||
|
||||
return selectedSchema;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
@@ -1,6 +1,7 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import { handleThunks } from 'Store/thunks';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import applications from './Settings/applications';
|
||||
import general from './Settings/general';
|
||||
import indexerFlags from './Settings/indexerFlags';
|
||||
import indexerOptions from './Settings/indexerOptions';
|
||||
@@ -13,6 +14,7 @@ export * from './Settings/indexerFlags';
|
||||
export * from './Settings/indexerOptions';
|
||||
export * from './Settings/languages';
|
||||
export * from './Settings/notifications';
|
||||
export * from './Settings/applications';
|
||||
export * from './Settings/ui';
|
||||
|
||||
//
|
||||
@@ -31,6 +33,7 @@ export const defaultState = {
|
||||
indexerOptions: indexerOptions.defaultState,
|
||||
languages: languages.defaultState,
|
||||
notifications: notifications.defaultState,
|
||||
applications: applications.defaultState,
|
||||
ui: ui.defaultState
|
||||
};
|
||||
|
||||
@@ -57,6 +60,7 @@ export const actionHandlers = handleThunks({
|
||||
...indexerOptions.actionHandlers,
|
||||
...languages.actionHandlers,
|
||||
...notifications.actionHandlers,
|
||||
...applications.actionHandlers,
|
||||
...ui.actionHandlers
|
||||
});
|
||||
|
||||
@@ -74,6 +78,7 @@ export const reducers = createHandleActions({
|
||||
...indexerOptions.reducers,
|
||||
...languages.reducers,
|
||||
...notifications.reducers,
|
||||
...applications.reducers,
|
||||
...ui.reducers
|
||||
|
||||
}, defaultState, section);
|
||||
|
Reference in New Issue
Block a user