mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
node no comments
This commit is contained in:
parent
b4d7bd2c8a
commit
96bdbb0e04
11 changed files with 103 additions and 61 deletions
|
@ -23,6 +23,11 @@ export const nodeSetLoading = (is_loading: INodeState['is_loading']) => ({
|
|||
type: NODE_ACTIONS.SET_LOADING,
|
||||
});
|
||||
|
||||
export const nodeSetLoadingComments = (is_loading_comments: INodeState['is_loading_comments']) => ({
|
||||
is_loading_comments,
|
||||
type: NODE_ACTIONS.SET_LOADING_COMMENTS,
|
||||
});
|
||||
|
||||
export const nodeSetCurrent = (current: INodeState['current']) => ({
|
||||
current,
|
||||
type: NODE_ACTIONS.SET_CURRENT,
|
||||
|
|
|
@ -10,6 +10,7 @@ export const NODE_ACTIONS = {
|
|||
|
||||
SET_SAVE_ERRORS: `${prefix}SET_SAVE_ERRORS`,
|
||||
SET_LOADING: `${prefix}SET_LOADING`,
|
||||
SET_LOADING_COMMENTS: `${prefix}SET_LOADING_COMMENTS`,
|
||||
SET_CURRENT: `${prefix}SET_CURRENT`,
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import assocPath from 'ramda/es/assocPath';
|
||||
import { NODE_ACTIONS } from './constants';
|
||||
import { nodeSetSaveErrors, nodeSetLoading, nodeSetCurrent } from './actions';
|
||||
import {
|
||||
nodeSetSaveErrors,
|
||||
nodeSetLoading,
|
||||
nodeSetCurrent,
|
||||
nodeSetLoadingComments,
|
||||
} from './actions';
|
||||
import { INodeState } from './reducer';
|
||||
|
||||
const setSaveErrors = (state: INodeState, { errors }: ReturnType<typeof nodeSetSaveErrors>) =>
|
||||
|
@ -9,11 +14,17 @@ const setSaveErrors = (state: INodeState, { errors }: ReturnType<typeof nodeSetS
|
|||
const setLoading = (state: INodeState, { is_loading }: ReturnType<typeof nodeSetLoading>) =>
|
||||
assocPath(['is_loading'], is_loading, state);
|
||||
|
||||
const setLoadingComments = (
|
||||
state: INodeState,
|
||||
{ is_loading_comments }: ReturnType<typeof nodeSetLoadingComments>
|
||||
) => assocPath(['is_loading_comments'], is_loading_comments, state);
|
||||
|
||||
const setCurrent = (state: INodeState, { current }: ReturnType<typeof nodeSetCurrent>) =>
|
||||
assocPath(['current'], current, state);
|
||||
|
||||
export const NODE_HANDLERS = {
|
||||
[NODE_ACTIONS.SAVE]: setSaveErrors,
|
||||
[NODE_ACTIONS.SET_LOADING]: setLoading,
|
||||
[NODE_ACTIONS.SET_LOADING_COMMENTS]: setLoadingComments,
|
||||
[NODE_ACTIONS.SET_CURRENT]: setCurrent,
|
||||
};
|
||||
|
|
|
@ -4,12 +4,15 @@ import { EMPTY_NODE } from './constants';
|
|||
import { NODE_HANDLERS } from './handlers';
|
||||
|
||||
export type INodeState = Readonly<{
|
||||
is_loading: boolean;
|
||||
editor: INode;
|
||||
current: Partial<INode>;
|
||||
current: INode;
|
||||
comments: IComment[];
|
||||
|
||||
error: string;
|
||||
errors: Record<string, string>;
|
||||
|
||||
is_loading: boolean;
|
||||
is_loading_comments: boolean;
|
||||
}>;
|
||||
|
||||
const INITIAL_STATE: INodeState = {
|
||||
|
@ -19,9 +22,10 @@ const INITIAL_STATE: INodeState = {
|
|||
blocks: [],
|
||||
files: [],
|
||||
},
|
||||
current: {},
|
||||
current: { ...EMPTY_NODE },
|
||||
comments: [],
|
||||
is_loading: false,
|
||||
is_loading_comments: false,
|
||||
error: null,
|
||||
errors: {},
|
||||
};
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
nodeLoadNode,
|
||||
nodeSetLoading,
|
||||
nodeSetCurrent,
|
||||
nodeSetLoadingComments,
|
||||
} from './actions';
|
||||
import { postNode, getNode } from './api';
|
||||
import { reqWrapper } from '../auth/sagas';
|
||||
|
@ -39,6 +40,7 @@ function* onNodeSave({ node }: ReturnType<typeof nodeSave>) {
|
|||
|
||||
function* onNodeLoad({ id, node_type }: ReturnType<typeof nodeLoadNode>) {
|
||||
yield put(nodeSetLoading(true));
|
||||
yield put(nodeSetLoadingComments(true));
|
||||
yield put(nodeSetSaveErrors({}));
|
||||
|
||||
if (node_type) yield put(nodeSetCurrent({ ...EMPTY_NODE, type: node_type }));
|
||||
|
@ -58,6 +60,10 @@ function* onNodeLoad({ id, node_type }: ReturnType<typeof nodeLoadNode>) {
|
|||
yield put(nodeSetSaveErrors({}));
|
||||
yield put(nodeSetCurrent(node));
|
||||
|
||||
// todo: load comments
|
||||
yield delay(500);
|
||||
yield put(nodeSetLoadingComments(false));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue