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:
parent
24ab0cb050
commit
3345939670
13 changed files with 243 additions and 170 deletions
64
src/components/sortable/SortableImageGrid/index.tsx
Normal file
64
src/components/sortable/SortableImageGrid/index.tsx
Normal file
|
@ -0,0 +1,64 @@
|
|||
import React, { FC, useCallback } from 'react';
|
||||
|
||||
import { ImageUpload } from '~/components/upload/ImageUpload';
|
||||
import { ImagePresets } from '~/constants/urls';
|
||||
import { UploadStatus } from '~/store/uploader/UploaderStore';
|
||||
import { IFile } from '~/types';
|
||||
import { getURL } from '~/utils/dom';
|
||||
|
||||
import { SortableGrid } from '../SortableGrid';
|
||||
|
||||
type OnSortEnd = (newValue: IFile[]) => void;
|
||||
|
||||
interface SortableImageGridProps {
|
||||
onSortEnd: OnSortEnd;
|
||||
items: IFile[];
|
||||
locked: UploadStatus[];
|
||||
onDelete: (file_id: IFile['id']) => void;
|
||||
className?: string;
|
||||
size?: number;
|
||||
}
|
||||
|
||||
const SortableImageGrid: FC<SortableImageGridProps> = ({
|
||||
items,
|
||||
locked,
|
||||
onDelete,
|
||||
className,
|
||||
onSortEnd,
|
||||
size,
|
||||
}) => {
|
||||
const renderItem = useCallback<FC<{ item: IFile }>>(
|
||||
({ item }) => (
|
||||
<ImageUpload id={item.id} thumb={getURL(item, ImagePresets.cover)} onDrop={onDelete} />
|
||||
),
|
||||
[]
|
||||
);
|
||||
|
||||
const renderLocked = useCallback<FC<{ locked: UploadStatus }>>(
|
||||
({ locked }) => (
|
||||
<ImageUpload
|
||||
thumb={locked.thumbnail}
|
||||
onDrop={onDelete}
|
||||
progress={locked.progress}
|
||||
is_uploading
|
||||
/>
|
||||
),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<SortableGrid
|
||||
items={items}
|
||||
locked={locked}
|
||||
getID={it => it.id}
|
||||
getLockedID={it => it.id}
|
||||
renderItem={renderItem}
|
||||
renderLocked={renderLocked}
|
||||
onSortEnd={onSortEnd}
|
||||
className={className}
|
||||
size={size}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export { SortableImageGrid };
|
Loading…
Add table
Add a link
Reference in a new issue