mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-10 07:13:47 -07:00
UI Action Handler Changes, Misc Fixes
This commit is contained in:
parent
7825319d89
commit
cd5b658196
193 changed files with 6992 additions and 6341 deletions
103
frontend/src/Store/Actions/Settings/delayProfiles.js
Normal file
103
frontend/src/Store/Actions/Settings/delayProfiles.js
Normal file
|
@ -0,0 +1,103 @@
|
|||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import { createAction } from 'redux-actions';
|
||||
import { createThunk } from 'Store/thunks';
|
||||
import createSetSettingValueReducer from 'Store/Actions/Creators/Reducers/createSetSettingValueReducer';
|
||||
import createFetchHandler from 'Store/Actions/Creators/createFetchHandler';
|
||||
import createFetchSchemaHandler from 'Store/Actions/Creators/createFetchSchemaHandler';
|
||||
import createSaveProviderHandler from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
|
||||
import { update } from 'Store/Actions/baseActions';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.delayProfiles';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_DELAY_PROFILES = 'settings/delayProfiles/fetchDelayProfiles';
|
||||
export const FETCH_DELAY_PROFILE_SCHEMA = 'settings/delayProfiles/fetchDelayProfileSchema';
|
||||
export const SAVE_DELAY_PROFILE = 'settings/delayProfiles/saveDelayProfile';
|
||||
export const DELETE_DELAY_PROFILE = 'settings/delayProfiles/deleteDelayProfile';
|
||||
export const REORDER_DELAY_PROFILE = 'settings/delayProfiles/reorderDelayProfile';
|
||||
export const SET_DELAY_PROFILE_VALUE = 'settings/delayProfiles/setDelayProfileValue';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchDelayProfiles = createThunk(FETCH_DELAY_PROFILES);
|
||||
export const fetchDelayProfileSchema = createThunk(FETCH_DELAY_PROFILE_SCHEMA);
|
||||
export const saveDelayProfile = createThunk(SAVE_DELAY_PROFILE);
|
||||
export const deleteDelayProfile = createThunk(DELETE_DELAY_PROFILE);
|
||||
export const reorderDelayProfile = createThunk(REORDER_DELAY_PROFILE);
|
||||
|
||||
export const setDelayProfileValue = createAction(SET_DELAY_PROFILE_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
items: [],
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_DELAY_PROFILES]: createFetchHandler(section, '/delayprofile'),
|
||||
[FETCH_DELAY_PROFILE_SCHEMA]: createFetchSchemaHandler(section, '/delayprofile/schema'),
|
||||
|
||||
[SAVE_DELAY_PROFILE]: createSaveProviderHandler(section, '/delayprofile'),
|
||||
[DELETE_DELAY_PROFILE]: createRemoveItemHandler(section, '/delayprofile'),
|
||||
|
||||
[REORDER_DELAY_PROFILE]: (getState, payload, dispatch) => {
|
||||
const { id, moveIndex } = payload;
|
||||
const moveOrder = moveIndex + 1;
|
||||
const delayProfiles = getState().settings.delayProfiles.items;
|
||||
const moving = _.find(delayProfiles, { id });
|
||||
|
||||
// Don't move if the order hasn't changed
|
||||
if (moving.order === moveOrder) {
|
||||
return;
|
||||
}
|
||||
|
||||
const after = moveIndex > 0 ? _.find(delayProfiles, { order: moveIndex }) : null;
|
||||
const afterQueryParam = after ? `after=${after.id}` : '';
|
||||
|
||||
const promise = $.ajax({
|
||||
method: 'PUT',
|
||||
url: `/delayprofile/reorder/${id}?${afterQueryParam}`
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(update({ section, data }));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_DELAY_PROFILE_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue