1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

refactored component errors

This commit is contained in:
Fedor Katurov 2021-03-03 17:54:58 +07:00
parent 7031084b09
commit d4c2e7ee09
79 changed files with 573 additions and 462 deletions

View file

@ -17,7 +17,7 @@ export const nodeSetSaveErrors = (errors: IValidationErrors) => ({
type: NODE_ACTIONS.SET_SAVE_ERRORS,
});
export const nodeGotoNode = (id: number, node_type: INode['type']) => ({
export const nodeGotoNode = (id: INode['id'], node_type: INode['type']) => ({
id,
node_type,
type: NODE_ACTIONS.GOTO_NODE,

View file

@ -1,4 +1,4 @@
import { FC } from 'react';
import { FC, ReactElement } from 'react';
import { IComment, INode, ValueOf } from '../types';
import { NodeImageSlideBlock } from '~/components/node/NodeImageSlideBlock';
import { NodeTextBlock } from '~/components/node/NodeTextBlock';
@ -13,7 +13,7 @@ import { EditorImageUploadButton } from '~/components/editors/EditorImageUploadB
import { EditorAudioUploadButton } from '~/components/editors/EditorAudioUploadButton';
import { EditorUploadCoverButton } from '~/components/editors/EditorUploadCoverButton';
import { modalShowPhotoswipe } from '../modal/actions';
import { IEditorComponentProps } from '~/redux/node/types';
import { IEditorComponentProps, NodeEditorProps } from '~/redux/node/types';
import { EditorFiller } from '~/components/editors/EditorFiller';
const prefix = 'NODE.';
@ -50,15 +50,13 @@ export const NODE_ACTIONS = {
};
export const EMPTY_NODE: INode = {
id: null,
user: null,
id: 0,
user: undefined,
title: '',
files: [],
cover: null,
type: null,
cover: undefined,
type: undefined,
blocks: [],
tags: [],
@ -102,13 +100,16 @@ export const NODE_INLINES: INodeComponents = {
};
export const EMPTY_COMMENT: IComment = {
id: null,
id: 0,
text: '',
files: [],
user: null,
user: undefined,
};
export const NODE_EDITORS = {
export const NODE_EDITORS: Record<
typeof NODE_TYPES[keyof typeof NODE_TYPES],
FC<NodeEditorProps>
> = {
[NODE_TYPES.IMAGE]: ImageEditor,
[NODE_TYPES.TEXT]: TextEditor,
[NODE_TYPES.VIDEO]: VideoEditor,

View file

@ -8,12 +8,12 @@ export type INodeState = Readonly<{
current: INode;
comments: IComment[];
related: {
albums: Record<string, Partial<INode[]>>;
similar: Partial<INode[]>;
albums: Record<string, INode[]>;
similar: INode[];
};
comment_data: Record<number, IComment>;
comment_count: number;
current_cover_image: IFile;
current_cover_image?: IFile;
error: string;
errors: Record<string, string>;
@ -38,14 +38,17 @@ const INITIAL_STATE: INodeState = {
},
comment_count: 0,
comments: [],
related: null,
current_cover_image: null,
related: {
albums: {},
similar: [],
},
current_cover_image: undefined,
is_loading: false,
is_loading_comments: false,
is_sending_comment: false,
error: null,
error: '',
errors: {},
};

View file

@ -51,6 +51,7 @@ import { selectNode } from './selectors';
import { Unwrap } from '../types';
import { NODE_EDITOR_DIALOGS } from '~/constants/dialogs';
import { DIALOGS } from '~/redux/modal/constants';
import { has } from 'ramda';
export function* updateNodeEverywhere(node) {
const {
@ -103,6 +104,9 @@ function* onNodeSave({ node }: ReturnType<typeof nodeSave>) {
}
function* onNodeGoto({ id, node_type }: ReturnType<typeof nodeGotoNode>) {
if (!id) {
return;
}
if (node_type) yield put(nodeSetCurrent({ ...EMPTY_NODE, type: node_type }));
yield put(nodeLoadNode(id));
@ -224,7 +228,7 @@ function* onUpdateTags({ id, tags }: ReturnType<typeof nodeUpdateTags>) {
}
function* onCreateSaga({ node_type: type }: ReturnType<typeof nodeCreate>) {
if (!NODE_EDITOR_DIALOGS[type]) return;
if (!type || !has(type, NODE_EDITOR_DIALOGS)) return;
yield put(nodeSetEditor({ ...EMPTY_NODE, ...(NODE_EDITOR_DATA[type] || {}), type }));
yield put(modalShowDialog(NODE_EDITOR_DIALOGS[type]));
@ -240,6 +244,8 @@ function* onEditSaga({ id }: ReturnType<typeof nodeEdit>) {
const { node }: Unwrap<typeof apiGetNode> = yield call(apiGetNode, { id });
if (!node.type || !has(node.type, NODE_EDITOR_DIALOGS)) return;
if (!NODE_EDITOR_DIALOGS[node?.type]) {
throw new Error('Unknown node type');
}

View file

@ -83,3 +83,9 @@ export type ApiLockCommentRequest = {
export type ApiLockcommentResult = {
deleted_at: string;
};
export type NodeEditorProps = {
data: INode;
setData: (val: INode) => void;
temp: string[];
setTemp: (val: string[]) => void;
};