mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
drag-and-drop on form
This commit is contained in:
parent
1ccc87178e
commit
b4bba2ea3b
7 changed files with 51 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
||||||
import React, { FC } from 'react';
|
import React, {FC, useCallback, useEffect} from 'react';
|
||||||
import { INode } from '~/redux/types';
|
import { INode } from '~/redux/types';
|
||||||
import * as styles from './styles.scss';
|
import * as styles from './styles.scss';
|
||||||
|
|
||||||
|
@ -8,10 +8,26 @@ interface IProps {
|
||||||
};
|
};
|
||||||
|
|
||||||
const ImageEditor: FC<IProps> = ({
|
const ImageEditor: FC<IProps> = ({
|
||||||
}) => (
|
data,
|
||||||
<div className={styles.uploads}>
|
setData,
|
||||||
<div />
|
}) => {
|
||||||
</div>
|
const eventPreventer = useCallback(event => event.preventDefault(), []);
|
||||||
)
|
|
||||||
|
|
||||||
export { ImageEditor };
|
useEffect(() => {
|
||||||
|
window.addEventListener("dragover", eventPreventer,false);
|
||||||
|
window.addEventListener("drop",eventPreventer,false);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("dragover", eventPreventer,false);
|
||||||
|
window.removeEventListener("drop",eventPreventer,false);
|
||||||
|
}
|
||||||
|
}, [eventPreventer]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form className={styles.uploads} onDrop={e => { console.log(e.dataTransfer.files);}}>
|
||||||
|
<div>{data.type}</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { ImageEditor };
|
||||||
|
|
|
@ -11,4 +11,4 @@
|
||||||
@media (max-width: 600px) {
|
@media (max-width: 600px) {
|
||||||
grid-template-columns: repeat(auto-fill, minmax(30vw, 1fr));
|
grid-template-columns: repeat(auto-fill, minmax(30vw, 1fr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { IDialogProps } from '~/redux/modal/constants';
|
||||||
import { useCloseOnEscape } from '~/utils/hooks';
|
import { useCloseOnEscape } from '~/utils/hooks';
|
||||||
import { Group } from '~/components/containers/Group';
|
import { Group } from '~/components/containers/Group';
|
||||||
import { InputText } from '~/components/input/InputText';
|
import { InputText } from '~/components/input/InputText';
|
||||||
import { Button } from '../../../components/input/Button/index';
|
import { Button } from '~/components/input/Button';
|
||||||
import { Padder } from '~/components/containers/Padder';
|
import { Padder } from '~/components/containers/Padder';
|
||||||
import * as styles from './styles.scss';
|
import * as styles from './styles.scss';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
|
@ -10,7 +10,7 @@ export interface IModalState {
|
||||||
|
|
||||||
const INITIAL_STATE: IModalState = {
|
const INITIAL_STATE: IModalState = {
|
||||||
is_shown: true,
|
is_shown: true,
|
||||||
dialog: DIALOGS.LOGIN,
|
dialog: DIALOGS.EDITOR,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createReducer(INITIAL_STATE, MODAL_HANDLERS);
|
export default createReducer(INITIAL_STATE, MODAL_HANDLERS);
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
import { INode } from "../types";
|
import {IBlock, INode} from "../types";
|
||||||
|
|
||||||
|
export const EMPTY_BLOCK: IBlock = {
|
||||||
|
type: null,
|
||||||
|
temp_ids: [],
|
||||||
|
attaches: [],
|
||||||
|
};
|
||||||
|
|
||||||
export const EMPTY_NODE: INode = {
|
export const EMPTY_NODE: INode = {
|
||||||
id: null,
|
id: null,
|
||||||
|
@ -11,10 +17,12 @@ export const EMPTY_NODE: INode = {
|
||||||
cover: null,
|
cover: null,
|
||||||
type: null,
|
type: null,
|
||||||
|
|
||||||
|
blocks: [],
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
flow: {
|
flow: {
|
||||||
display: 'single',
|
display: 'single',
|
||||||
show_description: false,
|
show_description: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { createReducer } from "~/utils/reducer";
|
import { createReducer } from "~/utils/reducer";
|
||||||
import { INode } from "../types";
|
import { INode } from "../types";
|
||||||
import { EMPTY_NODE } from "./constants";
|
import {EMPTY_BLOCK, EMPTY_NODE} from "./constants";
|
||||||
import { NODE_HANDLERS } from "./handlers";
|
import { NODE_HANDLERS } from "./handlers";
|
||||||
|
|
||||||
export type INodeState = Readonly<{
|
export type INodeState = Readonly<{
|
||||||
|
@ -13,10 +13,14 @@ export type INodeState = Readonly<{
|
||||||
const INITIAL_STATE: INodeState = {
|
const INITIAL_STATE: INodeState = {
|
||||||
editor: {
|
editor: {
|
||||||
...EMPTY_NODE,
|
...EMPTY_NODE,
|
||||||
|
type: 'image',
|
||||||
|
blocks: [
|
||||||
|
{ ...EMPTY_BLOCK, type: 'image' },
|
||||||
|
]
|
||||||
},
|
},
|
||||||
is_loading: false,
|
is_loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
errors: {},
|
errors: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createReducer(INITIAL_STATE, NODE_HANDLERS);
|
export default createReducer(INITIAL_STATE, NODE_HANDLERS);
|
||||||
|
|
|
@ -64,6 +64,12 @@ export interface IFile {
|
||||||
updatedAt?: string;
|
updatedAt?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IBlock {
|
||||||
|
type: 'image' | 'text' | 'media' | 'youtube' | 'video',
|
||||||
|
temp_ids: UUID[];
|
||||||
|
attaches: UUID[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface INode {
|
export interface INode {
|
||||||
id?: UUID;
|
id?: UUID;
|
||||||
user_id: UUID;
|
user_id: UUID;
|
||||||
|
@ -74,6 +80,8 @@ export interface INode {
|
||||||
cover: IFile['id'];
|
cover: IFile['id'];
|
||||||
type: 'image';
|
type: 'image';
|
||||||
|
|
||||||
|
blocks: IBlock[];
|
||||||
|
|
||||||
brief?: {
|
brief?: {
|
||||||
thumbnail?: string;
|
thumbnail?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
@ -90,4 +98,4 @@ export interface INode {
|
||||||
|
|
||||||
createdAt?: string;
|
createdAt?: string;
|
||||||
updatedAt?: string;
|
updatedAt?: string;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue