mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
setting nodes on flow\
This commit is contained in:
parent
4a7fe884f9
commit
4c49ed000a
4 changed files with 16 additions and 9 deletions
|
@ -1,15 +1,17 @@
|
||||||
import { createReducer } from '~/utils/reducer';
|
import { createReducer } from '~/utils/reducer';
|
||||||
import { INode, UUID } from '../types';
|
import { INode, IError } from '../types';
|
||||||
import { FLOW_HANDLERS } from './handlers';
|
import { FLOW_HANDLERS } from './handlers';
|
||||||
|
|
||||||
export type IFlowState = Readonly<{
|
export type IFlowState = Readonly<{
|
||||||
is_loading: boolean;
|
is_loading: boolean;
|
||||||
nodes: Record<UUID, INode>;
|
nodes: INode[];
|
||||||
|
error: IError;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
const INITIAL_STATE: IFlowState = {
|
const INITIAL_STATE: IFlowState = {
|
||||||
nodes: {},
|
nodes: [],
|
||||||
is_loading: false,
|
is_loading: false,
|
||||||
|
error: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createReducer(INITIAL_STATE, FLOW_HANDLERS);
|
export default createReducer(INITIAL_STATE, FLOW_HANDLERS);
|
||||||
|
|
|
@ -1,23 +1,25 @@
|
||||||
import { takeLatest, call } from 'redux-saga/effects';
|
import { takeLatest, call, put } from 'redux-saga/effects';
|
||||||
import { REHYDRATE } from 'redux-persist';
|
import { REHYDRATE } from 'redux-persist';
|
||||||
import { FLOW_ACTIONS } from './constants';
|
import { FLOW_ACTIONS } from './constants';
|
||||||
import { getNodes } from '../node/api';
|
import { getNodes } from '../node/api';
|
||||||
import { flowSetNodes } from './actions';
|
import { flowSetNodes } from './actions';
|
||||||
|
import { objFromArray } from '~/utils/fn';
|
||||||
|
import { IResultWithStatus, INode } from '../types';
|
||||||
|
|
||||||
function* onGetFlow() {
|
function* onGetFlow() {
|
||||||
const {
|
const {
|
||||||
data: { nodes = null },
|
data: { nodes = null },
|
||||||
error,
|
error,
|
||||||
} = yield call(getNodes, {});
|
}: IResultWithStatus<{ nodes: INode[] }> = yield call(getNodes, {});
|
||||||
|
|
||||||
if (!nodes) {
|
if (!nodes || !nodes.length) {
|
||||||
// todo: set error empty response
|
// todo: set error empty response
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: write nodes
|
// todo: write nodes
|
||||||
// yield put(flowSetNodes());
|
yield put(flowSetNodes(nodes));
|
||||||
|
|
||||||
console.log('flow', { nodes, error });
|
// console.log('flow', { nodes, error });
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function* nodeSaga() {
|
export default function* nodeSaga() {
|
||||||
|
|
|
@ -114,4 +114,5 @@ export interface INode {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IUploadProgressHandler = (progress: ProgressEvent) => void;
|
export type IUploadProgressHandler = (progress: ProgressEvent) => void;
|
||||||
export type IValidationErrors = Record<string, ValueOf<typeof ERRORS>>;
|
export type IError = ValueOf<typeof ERRORS>;
|
||||||
|
export type IValidationErrors = Record<string, IError>;
|
||||||
|
|
|
@ -4,3 +4,5 @@ import nth from 'ramda/es/nth';
|
||||||
import remove from 'ramda/es/remove';
|
import remove from 'ramda/es/remove';
|
||||||
|
|
||||||
export const moveArrItem = curry((at, to, list) => insert(to, nth(at, list), remove(at, 1, list)));
|
export const moveArrItem = curry((at, to, list) => insert(to, nth(at, list), remove(at, 1, list)));
|
||||||
|
export const objFromArray = (array: any[], key: string) =>
|
||||||
|
array.reduce((obj, el) => (key && el[key] ? { ...obj, [el[key]]: el } : obj), {});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue