reorder
This commit is contained in:
@ -29,7 +29,17 @@ const useStyles = createStyles((theme) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export interface DndListProps {
|
export interface DndListProps {
|
||||||
data: {
|
data: TData
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IProps
|
||||||
|
{
|
||||||
|
dragEndHandler: (p: any) => void;
|
||||||
|
dataprops: DndListProps;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TData =
|
||||||
|
{
|
||||||
|
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
@ -39,16 +49,9 @@ export interface DndListProps {
|
|||||||
// mass: number;
|
// mass: number;
|
||||||
// symbol: string;
|
// symbol: string;
|
||||||
// name: string;
|
// name: string;
|
||||||
}[];
|
}[]
|
||||||
}
|
|
||||||
|
|
||||||
export interface IProps
|
|
||||||
{
|
|
||||||
dragEndHandler: (p: any) => void;
|
|
||||||
dataprops: DndListProps;
|
|
||||||
}
|
|
||||||
|
|
||||||
const reorder = ({ from, to }: { from: number; to: number })
|
const reorder = ({current, from, to }: {current: TData; from: number; to: number }) =>
|
||||||
{
|
{
|
||||||
const cloned = [...current];
|
const cloned = [...current];
|
||||||
const item = current[from];
|
const item = current[from];
|
||||||
@ -92,7 +95,13 @@ export interface DndListProps {
|
|||||||
{
|
{
|
||||||
handlers.reorder({ from: source.index, to: destination?.index || 0 });
|
handlers.reorder({ from: source.index, to: destination?.index || 0 });
|
||||||
console.log(state);
|
console.log(state);
|
||||||
dragEndHandler(state);
|
dragEndHandler(
|
||||||
|
reorder(
|
||||||
|
{
|
||||||
|
current:state,
|
||||||
|
from: source.index,
|
||||||
|
to: destination!.index
|
||||||
|
} ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user