From 36f9bc68b20e94de21c0552cd4dae7b5776f73a7 Mon Sep 17 00:00:00 2001 From: Peter Hoppe Date: Tue, 14 Feb 2023 02:02:48 +0100 Subject: [PATCH] reorder --- src/components/DndList.tsx | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/components/DndList.tsx b/src/components/DndList.tsx index 6048b9e..fcc8041 100644 --- a/src/components/DndList.tsx +++ b/src/components/DndList.tsx @@ -29,7 +29,17 @@ const useStyles = createStyles((theme) => ({ })); export interface DndListProps { - data: { + data: TData + } + + export interface IProps + { + dragEndHandler: (p: any) => void; + dataprops: DndListProps; + } + + export type TData = + { id: string; name: string; @@ -39,16 +49,9 @@ export interface DndListProps { // mass: number; // symbol: 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 item = current[from]; @@ -92,7 +95,13 @@ export interface DndListProps { { handlers.reorder({ from: source.index, to: destination?.index || 0 }); console.log(state); - dragEndHandler(state); + dragEndHandler( + reorder( + { + current:state, + from: source.index, + to: destination!.index + } )); } } >