1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-26 05:16:41 +07:00

file sorting

This commit is contained in:
muerwre 2019-08-08 18:04:48 +07:00
parent 125a120c85
commit cfe7603379
3 changed files with 17 additions and 5 deletions

View file

@ -1,4 +1,4 @@
import React, { FC, ReactChildren } from 'react';
import React, { FC, ReactChildren, useCallback } from 'react';
import { SortableContainer, SortableElement } from 'react-sortable-hoc';
import * as styles from './styles.scss';
import { ImageUpload } from '~/components/upload/ImageUpload';
@ -8,6 +8,7 @@ import { IUploadStatus } from '~/redux/uploads/reducer';
interface IProps {
items: IFile[];
locked: IUploadStatus[];
onFileMove: (o: number, n: number) => void;
};
const SortableItem = SortableElement(({ children }) => <div className={styles.item}>{children}</div>);
@ -44,11 +45,12 @@ const SortableList = SortableContainer(({ items, locked }: { items: IFile[], loc
const ImageGrid: FC<IProps> = ({
items,
locked,
onFileMove,
}) => {
const onMove = useCallback(({ oldIndex, newIndex }) => onFileMove(oldIndex, newIndex), [onFileMove]);
return (
<SortableList onSortEnd={console.log} axis="xy" items={items} locked={locked} />
<SortableList onSortEnd={onMove} axis="xy" items={items} locked={locked} />
)
}