1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

made sortable grid component

This commit is contained in:
Fedor Katurov 2022-06-24 16:47:38 +07:00
parent 24ab0cb050
commit 3345939670
13 changed files with 243 additions and 170 deletions

View file

@ -3,7 +3,7 @@ import React, { FC, useCallback } from 'react';
import { SortEnd } from 'react-sortable-hoc';
import { SortableAudioGrid } from '~/components/editors/SortableAudioGrid';
import { OnSortEnd, SortableImageGrid } from '~/components/editors/SortableImageGrid';
import { SortableImageGrid } from '~/components/sortable';
import { COMMENT_FILE_TYPES } from '~/constants/uploads';
import { useFileDropZone } from '~/hooks';
import { IFile } from '~/types';
@ -29,16 +29,9 @@ const CommentFormAttaches: FC = () => {
const hasAudioAttaches = filesAudios.length > 0 || pendingAudios.length > 0;
const hasAttaches = hasImageAttaches || hasAudioAttaches;
const onImageMove = useCallback<OnSortEnd>(
({ oldIndex, newIndex }) => {
setFiles([
...filesAudios,
...(moveArrItem(
oldIndex,
newIndex,
filesImages.filter(file => !!file)
) as IFile[]),
]);
const onImageMove = useCallback(
(newFiles: IFile[]) => {
setFiles([...filesAudios, ...newFiles.filter(it => it)]);
},
[setFiles, filesImages, filesAudios]
);
@ -85,6 +78,7 @@ const CommentFormAttaches: FC = () => {
onSortEnd={onImageMove}
items={filesImages}
locked={pendingImages}
size={160}
/>
)}