mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
editor refactoring
This commit is contained in:
parent
1f9c6ac8f7
commit
bd5122f365
5 changed files with 28 additions and 40 deletions
|
@ -14,12 +14,7 @@ interface IProps {
|
||||||
onScrollStop?: MouseEventHandler;
|
onScrollStop?: MouseEventHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Scroll = ({
|
const Scroll = ({ children, className = '', onRef = null, ...props }: IProps) => {
|
||||||
children,
|
|
||||||
className = '',
|
|
||||||
onRef = null,
|
|
||||||
...props
|
|
||||||
}: IProps) => {
|
|
||||||
const [ref, setRef] = useState(null);
|
const [ref, setRef] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -43,3 +38,5 @@ export const Scroll = ({
|
||||||
</Scrollbars>
|
</Scrollbars>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export { Scroll };
|
||||||
|
|
|
@ -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 { connect } from 'react-redux';
|
||||||
import { INode } from '~/redux/types';
|
import { INode } from '~/redux/types';
|
||||||
import * as UPLOAD_ACTIONS from '~/redux/uploads/actions';
|
import * as UPLOAD_ACTIONS from '~/redux/uploads/actions';
|
||||||
import { selectUploads } from '~/redux/uploads/selectors';
|
import { selectUploads } from '~/redux/uploads/selectors';
|
||||||
import { ImageGrid } from '~/components/editors/ImageGrid';
|
import { ImageGrid } from '~/components/editors/ImageGrid';
|
||||||
import { IUploadStatus } from '~/redux/uploads/reducer';
|
import { IUploadStatus } from '~/redux/uploads/reducer';
|
||||||
import { moveArrItem } from '~/utils/fn';
|
|
||||||
import assocPath from 'ramda/es/assocPath';
|
|
||||||
|
|
||||||
const mapStateToProps = selectUploads;
|
const mapStateToProps = selectUploads;
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
|
@ -16,14 +14,17 @@ const mapDispatchToProps = {
|
||||||
type IProps = ReturnType<typeof mapStateToProps> &
|
type IProps = ReturnType<typeof mapStateToProps> &
|
||||||
typeof mapDispatchToProps & {
|
typeof mapDispatchToProps & {
|
||||||
data: INode;
|
data: INode;
|
||||||
pending_files: IUploadStatus[];
|
|
||||||
|
|
||||||
setData: (val: INode) => void;
|
setData: (val: INode) => void;
|
||||||
onFileMove: (from: number, to: number) => void;
|
temp: string[];
|
||||||
onInputChange: ChangeEventHandler<HTMLInputElement>;
|
setTemp: (val: string[]) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ImageEditorUnconnected: FC<IProps> = ({ data, setData, pending_files }) => {
|
const ImageEditorUnconnected: FC<IProps> = ({ data, setData, temp, statuses }) => {
|
||||||
|
const pending_files = useMemo(() => temp.filter(id => !!statuses[id]).map(id => statuses[id]), [
|
||||||
|
temp,
|
||||||
|
statuses,
|
||||||
|
]);
|
||||||
|
|
||||||
return <ImageGrid data={data} setData={setData} locked={pending_files} />;
|
return <ImageGrid data={data} setData={setData} locked={pending_files} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@ interface IProps {
|
||||||
data: INode;
|
data: INode;
|
||||||
setData: (val: INode) => void;
|
setData: (val: INode) => void;
|
||||||
locked: IUploadStatus[];
|
locked: IUploadStatus[];
|
||||||
// items: IFile[];
|
|
||||||
// onFileMove: (o: number, n: number) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const SortableItem = SortableElement(({ children }) => (
|
const SortableItem = SortableElement(({ children }) => (
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
import React, {
|
import React, { FC, ChangeEvent, useCallback, useState, useEffect } from 'react';
|
||||||
FC,
|
|
||||||
ChangeEvent,
|
|
||||||
useCallback,
|
|
||||||
useState, useEffect,
|
|
||||||
} from 'react';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import * as styles from '~/styles/inputs.scss';
|
import * as styles from '~/styles/inputs.scss';
|
||||||
import { Icon } from '~/components/input/Icon';
|
import { Icon } from '~/components/input/Icon';
|
||||||
|
@ -28,7 +23,7 @@ const InputText: FC<IInputTextProps> = ({
|
||||||
|
|
||||||
const onInput = useCallback(
|
const onInput = useCallback(
|
||||||
({ target }: ChangeEvent<HTMLInputElement>) => handler(target.value),
|
({ target }: ChangeEvent<HTMLInputElement>) => handler(target.value),
|
||||||
[handler],
|
[handler]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onFocus = useCallback(() => setFocused(true), []);
|
const onFocus = useCallback(() => setFocused(true), []);
|
||||||
|
@ -39,18 +34,15 @@ const InputText: FC<IInputTextProps> = ({
|
||||||
}, [inner_ref, onRef]);
|
}, [inner_ref, onRef]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(
|
<div
|
||||||
styles.input_text_wrapper,
|
className={classNames(styles.input_text_wrapper, wrapperClassName, {
|
||||||
wrapperClassName,
|
|
||||||
{
|
|
||||||
[styles.required]: required,
|
[styles.required]: required,
|
||||||
[styles.focused]: focused,
|
[styles.focused]: focused,
|
||||||
[styles.has_status]: !!status || !!error,
|
[styles.has_status]: !!status || !!error,
|
||||||
[styles.has_value]: !!value,
|
[styles.has_value]: !!value,
|
||||||
[styles.has_error]: !!error,
|
[styles.has_error]: !!error,
|
||||||
[styles.has_loader]: is_loading,
|
[styles.has_loader]: is_loading,
|
||||||
},
|
})}
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
<div className={styles.input}>
|
<div className={styles.input}>
|
||||||
<input
|
<input
|
||||||
|
@ -79,12 +71,16 @@ const InputText: FC<IInputTextProps> = ({
|
||||||
<LoaderCircle size={20} />
|
<LoaderCircle size={20} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{
|
{title && (
|
||||||
title && <div className={styles.title}><span>{title}</span></div>
|
<div className={styles.title}>
|
||||||
}
|
<span>{title}</span>
|
||||||
{
|
</div>
|
||||||
error && <div className={styles.error}><span>{error}</span></div>
|
)}
|
||||||
}
|
{error && (
|
||||||
|
<div className={styles.error}>
|
||||||
|
<span>{error}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,11 +67,7 @@ const EditorDialogUnconnected: FC<IProps> = ({ onRequestClose, editor, statuses,
|
||||||
<form onSubmit={onSubmit} className={styles.form}>
|
<form onSubmit={onSubmit} className={styles.form}>
|
||||||
<ScrollDialog buttons={buttons} width={860} onClose={onRequestClose}>
|
<ScrollDialog buttons={buttons} width={860} onClose={onRequestClose}>
|
||||||
<div className={styles.editor}>
|
<div className={styles.editor}>
|
||||||
<ImageEditor
|
<ImageEditor data={data} setData={setData} temp={temp} setTemp={setTemp} />
|
||||||
data={data}
|
|
||||||
pending_files={temp.filter(id => !!statuses[id]).map(id => statuses[id])}
|
|
||||||
setData={setData}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</ScrollDialog>
|
</ScrollDialog>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue