From bd5122f3655026809d7e90ad348a0ba7430920a5 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Wed, 16 Oct 2019 11:11:35 +0700 Subject: [PATCH] editor refactoring --- src/components/containers/Scroll/index.tsx | 9 ++--- src/components/editors/ImageEditor/index.tsx | 17 +++++----- src/components/editors/ImageGrid/index.tsx | 2 -- src/components/input/InputText/index.tsx | 34 ++++++++----------- src/containers/dialogs/EditorDialog/index.tsx | 6 +--- 5 files changed, 28 insertions(+), 40 deletions(-) diff --git a/src/components/containers/Scroll/index.tsx b/src/components/containers/Scroll/index.tsx index 36be053d..07ea0dfd 100644 --- a/src/components/containers/Scroll/index.tsx +++ b/src/components/containers/Scroll/index.tsx @@ -14,12 +14,7 @@ interface IProps { onScrollStop?: MouseEventHandler; } -export const Scroll = ({ - children, - className = '', - onRef = null, - ...props -}: IProps) => { +const Scroll = ({ children, className = '', onRef = null, ...props }: IProps) => { const [ref, setRef] = useState(null); useEffect(() => { @@ -43,3 +38,5 @@ export const Scroll = ({ ); }; + +export { Scroll }; diff --git a/src/components/editors/ImageEditor/index.tsx b/src/components/editors/ImageEditor/index.tsx index aecf0a90..77762732 100644 --- a/src/components/editors/ImageEditor/index.tsx +++ b/src/components/editors/ImageEditor/index.tsx @@ -1,12 +1,10 @@ -import React, { FC, ChangeEventHandler, DragEventHandler, useCallback } from 'react'; +import React, { FC, ChangeEventHandler, DragEventHandler, useCallback, useMemo } from 'react'; import { connect } from 'react-redux'; import { INode } from '~/redux/types'; import * as UPLOAD_ACTIONS from '~/redux/uploads/actions'; import { selectUploads } from '~/redux/uploads/selectors'; import { ImageGrid } from '~/components/editors/ImageGrid'; import { IUploadStatus } from '~/redux/uploads/reducer'; -import { moveArrItem } from '~/utils/fn'; -import assocPath from 'ramda/es/assocPath'; const mapStateToProps = selectUploads; const mapDispatchToProps = { @@ -16,14 +14,17 @@ const mapDispatchToProps = { type IProps = ReturnType & typeof mapDispatchToProps & { data: INode; - pending_files: IUploadStatus[]; - setData: (val: INode) => void; - onFileMove: (from: number, to: number) => void; - onInputChange: ChangeEventHandler; + temp: string[]; + setTemp: (val: string[]) => void; }; -const ImageEditorUnconnected: FC = ({ data, setData, pending_files }) => { +const ImageEditorUnconnected: FC = ({ data, setData, temp, statuses }) => { + const pending_files = useMemo(() => temp.filter(id => !!statuses[id]).map(id => statuses[id]), [ + temp, + statuses, + ]); + return ; }; diff --git a/src/components/editors/ImageGrid/index.tsx b/src/components/editors/ImageGrid/index.tsx index 7a2ef947..beb7f2b9 100644 --- a/src/components/editors/ImageGrid/index.tsx +++ b/src/components/editors/ImageGrid/index.tsx @@ -12,8 +12,6 @@ interface IProps { data: INode; setData: (val: INode) => void; locked: IUploadStatus[]; - // items: IFile[]; - // onFileMove: (o: number, n: number) => void; } const SortableItem = SortableElement(({ children }) => ( diff --git a/src/components/input/InputText/index.tsx b/src/components/input/InputText/index.tsx index 434df389..524d0182 100644 --- a/src/components/input/InputText/index.tsx +++ b/src/components/input/InputText/index.tsx @@ -1,9 +1,4 @@ -import React, { - FC, - ChangeEvent, - useCallback, - useState, useEffect, -} from 'react'; +import React, { FC, ChangeEvent, useCallback, useState, useEffect } from 'react'; import classNames from 'classnames'; import * as styles from '~/styles/inputs.scss'; import { Icon } from '~/components/input/Icon'; @@ -28,7 +23,7 @@ const InputText: FC = ({ const onInput = useCallback( ({ target }: ChangeEvent) => handler(target.value), - [handler], + [handler] ); const onFocus = useCallback(() => setFocused(true), []); @@ -39,18 +34,15 @@ const InputText: FC = ({ }, [inner_ref, onRef]); return ( -
= ({
- { - title &&
{title}
- } - { - error &&
{error}
- } + {title && ( +
+ {title} +
+ )} + {error && ( +
+ {error} +
+ )} ); }; diff --git a/src/containers/dialogs/EditorDialog/index.tsx b/src/containers/dialogs/EditorDialog/index.tsx index 8b0a8a53..965702c3 100644 --- a/src/containers/dialogs/EditorDialog/index.tsx +++ b/src/containers/dialogs/EditorDialog/index.tsx @@ -67,11 +67,7 @@ const EditorDialogUnconnected: FC = ({ onRequestClose, editor, statuses,
- !!statuses[id]).map(id => statuses[id])} - setData={setData} - /> +