mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-21 22:04:31 -04:00
UI Action Handler Changes, Misc Fixes
This commit is contained in:
@@ -1,7 +1,104 @@
|
||||
import $ from 'jquery';
|
||||
import { createAction } from 'redux-actions';
|
||||
import * as types from './actionTypes';
|
||||
import pathActionHandlers from './pathActionHandlers';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import { set } from './baseActions';
|
||||
|
||||
export const fetchPaths = pathActionHandlers[types.FETCH_PATHS];
|
||||
export const updatePaths = createAction(types.UPDATE_PATHS);
|
||||
export const clearPaths = createAction(types.CLEAR_PATHS);
|
||||
//
|
||||
// Variables
|
||||
|
||||
export const section = 'paths';
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
export const defaultState = {
|
||||
currentPath: '',
|
||||
isPopulated: false,
|
||||
isFetching: false,
|
||||
error: null,
|
||||
directories: [],
|
||||
files: [],
|
||||
parent: null
|
||||
};
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_PATHS = 'paths/fetchPaths';
|
||||
export const UPDATE_PATHS = 'paths/updatePaths';
|
||||
export const CLEAR_PATHS = 'paths/clearPaths';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchPaths = createThunk(FETCH_PATHS);
|
||||
export const updatePaths = createAction(UPDATE_PATHS);
|
||||
export const clearPaths = createAction(CLEAR_PATHS);
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
export const actionHandlers = handleThunks({
|
||||
|
||||
[FETCH_PATHS]: function(getState, payload, dispatch) {
|
||||
dispatch(set({ section, isFetching: true }));
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/filesystem',
|
||||
data: {
|
||||
path: payload.path
|
||||
}
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(updatePaths({ path: payload.path, ...data }));
|
||||
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: true,
|
||||
error: null
|
||||
}));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: xhr
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
export const reducers = createHandleActions({
|
||||
|
||||
[UPDATE_PATHS]: (state, { payload }) => {
|
||||
const newState = Object.assign({}, state);
|
||||
|
||||
newState.currentPath = payload.path;
|
||||
newState.directories = payload.directories;
|
||||
newState.files = payload.files;
|
||||
newState.parent = payload.parent;
|
||||
|
||||
return newState;
|
||||
},
|
||||
|
||||
[CLEAR_PATHS]: (state, { payload }) => {
|
||||
const newState = Object.assign({}, state);
|
||||
|
||||
newState.path = '';
|
||||
newState.directories = [];
|
||||
newState.files = [];
|
||||
newState.parent = '';
|
||||
|
||||
return newState;
|
||||
}
|
||||
|
||||
}, defaultState, section);
|
||||
|
||||
Reference in New Issue
Block a user