UI Action Handler Changes, Misc Fixes

This commit is contained in:
Qstick
2017-11-26 15:09:45 -05:00
parent 7825319d89
commit cd5b658196
193 changed files with 6992 additions and 6341 deletions
+102 -5
View File
@@ -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);