1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00
This commit is contained in:
muerwre 2019-08-09 14:37:44 +07:00
parent 9a8e5efd1a
commit 988a069d57
4 changed files with 23 additions and 24 deletions

View file

@ -1,5 +1,5 @@
import React, {
FC, ReactChildren, useCallback, ChangeEventHandler, DragEventHandler
FC, useCallback, ChangeEventHandler, DragEventHandler
} from 'react';
import { SortableContainer, SortableElement } from 'react-sortable-hoc';
import * as styles from './styles.scss';
@ -15,7 +15,7 @@ interface IProps {
onDrop: DragEventHandler<HTMLFormElement>;
}
const SortableItem = SortableElement(({ children }) => (
const SortableItem = SortableElement(({ children, }) => (
<div className={styles.item}>{children}</div>
));
@ -23,7 +23,7 @@ const SortableList = SortableContainer(
({
items,
locked,
onDrop
onDrop,
}: {
items: IFile[];
locked: IUploadStatus[];
@ -46,9 +46,9 @@ const SortableList = SortableContainer(
);
const ImageGrid: FC<IProps> = ({
items, locked, onFileMove, onUpload, onDrop
items, locked, onFileMove, onUpload, onDrop,
}) => {
const onMove = useCallback(({ oldIndex, newIndex }) => onFileMove(oldIndex, newIndex), [
const onMove = useCallback(({ oldIndex, newIndex, }) => onFileMove(oldIndex, newIndex), [
onFileMove
]);
@ -60,7 +60,7 @@ const ImageGrid: FC<IProps> = ({
locked={locked}
onUpload={onUpload}
onDrop={onDrop}
pressDelay={100}
pressDelay={window.innerWidth < 768 ? 200 : 0}
helperClass={styles.helper}
/>
);

View file

@ -1,6 +1,4 @@
import {
createStore, applyMiddleware, combineReducers, compose, Store
} from 'redux';
import { createStore, applyMiddleware, combineReducers, compose, Store } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
@ -25,7 +23,7 @@ import modalReducer, { IModalState } from '~/redux/modal/reducer';
const authPersistConfig: PersistConfig = {
key: 'auth',
whitelist: ['token', 'user'],
storage
storage,
};
export interface IState {
@ -39,9 +37,10 @@ export interface IState {
export const sagaMiddleware = createSagaMiddleware();
export const history = createBrowserHistory();
const composeEnhancers = typeof window === 'object' && (<any>window).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? (<any>window).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
: compose;
const composeEnhancers =
typeof window === 'object' && (<any>window).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? (<any>window).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
: compose;
export const store = createStore(
combineReducers<IState>({

View file

@ -9,35 +9,35 @@ import { IUploadState } from './reducer';
const addStatus = (
state: IUploadState,
{ temp_id, status }: ReturnType<typeof uploadAddStatus>
{ temp_id, status, }: ReturnType<typeof uploadAddStatus>
): IUploadState => assocPath(
['statuses'],
{ ...state.statuses, [temp_id]: { ...EMPTY_UPLOAD_STATUS, ...status } },
{ ...state.statuses, [temp_id]: { ...EMPTY_UPLOAD_STATUS, ...status, }, },
state
);
const dropStatus = (
state: IUploadState,
{ temp_id }: ReturnType<typeof uploadDropStatus>
{ temp_id, }: ReturnType<typeof uploadDropStatus>
): IUploadState => assocPath(['statuses'], omit([temp_id], state.statuses), state);
const setStatus = (
state: IUploadState,
{ temp_id, status }: ReturnType<typeof uploadSetStatus>
{ temp_id, status, }: ReturnType<typeof uploadSetStatus>
): IUploadState => assocPath(
['statuses'],
{
...state.statuses,
[temp_id]: { ...(state.statuses[temp_id] || EMPTY_UPLOAD_STATUS), ...status }
[temp_id]: { ...(state.statuses[temp_id] || EMPTY_UPLOAD_STATUS), ...status, },
},
state
);
const addFile = (state: IUploadState, { file }: ReturnType<typeof uploadAddFile>): IUploadState => assocPath(['files'], { ...state.files, [file.id]: file }, state);
const addFile = (state: IUploadState, { file, }: ReturnType<typeof uploadAddFile>): IUploadState => assocPath(['files'], { ...state.files, [file.id]: file, }, state);
export const UPLOAD_HANDLERS = {
[UPLOAD_ACTIONS.ADD_STATUS]: addStatus,
[UPLOAD_ACTIONS.DROP_STATUS]: dropStatus,
[UPLOAD_ACTIONS.SET_STATUS]: setStatus,
[UPLOAD_ACTIONS.ADD_FILE]: addFile
[UPLOAD_ACTIONS.ADD_FILE]: addFile,
};