diff --git a/components/admin/guide-section-editor.tsx b/components/admin/guide-section-editor.tsx index 8f02752..84209a3 100644 --- a/components/admin/guide-section-editor.tsx +++ b/components/admin/guide-section-editor.tsx @@ -4,8 +4,6 @@ import dynamic from "next/dynamic"; import Image from "next/image"; import { ChartNoAxesCombinedIcon, - ChevronDownIcon, - ChevronUpIcon, ClipboardCopyIcon, ClipboardPasteIcon, CopyIcon, @@ -3370,48 +3368,76 @@ function ExtraCatalogItemsEditor({ artifacts: CatalogItem[]; onChange: (value: ExtraCatalogItem[]) => void; }) { + const sensors = useSensors( + useSensor(PointerSensor), + useSensor(KeyboardSensor, { + coordinateGetter: sortableKeyboardCoordinates, + }), + ); const [kind, setKind] = useState("character"); const [key, setKey] = useState(""); const catalogs = { character: characters, weapon: weapons, artifact: artifacts }; const labels = { character: "ตัวละคร", weapon: "อาวุธ", artifact: "อาร์ติแฟกต์" }; const items = catalogs[kind]; + const itemId = (item: ExtraCatalogItem) => `${item.kind}:${item.key}`; + const handleDragEnd = ({ active, over }: DragEndEvent) => { + if (!over || active.id === over.id) return; + const from = value.findIndex((item) => itemId(item) === active.id); + const to = value.findIndex((item) => itemId(item) === over.id); + if (from !== -1 && to !== -1) onChange(arrayMove(value, from, to)); + }; return ( ตัวละคร อาวุธ และอาร์ติแฟกต์
{value.length ? ( -
- {value.map((reference, index) => { - const item = catalogs[reference.kind].find( - (candidate) => candidate.key === reference.key, - ); - return ( - - - {item ? ( -
- -
- ) : null} -
-

{item?.name ?? reference.key}

-

{labels[reference.kind]}

-
- - - -
-
- ); - })} -
+ + +
+ {value.map((reference, index) => { + const item = catalogs[reference.kind].find( + (candidate) => candidate.key === reference.key, + ); + const label = item?.name ?? reference.key; + return ( + + {(dragHandle) => ( + + + {item ? ( +
+ +
+ ) : null} +
+

{label}

+

{labels[reference.kind]}

+
+ {dragHandle} + +
+
+ )} +
+ ); + })} +
+
+
) : null}