mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-08-08 11:13:58 +08:00
Darkmode for survey pages. Fixes for eslint.
This commit is contained in:
@@ -23,6 +23,7 @@ import { SortableItem } from "./SortableItem";
|
||||
export interface SortableProps {
|
||||
items: ReactNode[];
|
||||
onChange: (newSortedIndices: number[]) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
interface SortableItems {
|
||||
@@ -31,18 +32,18 @@ interface SortableItems {
|
||||
item: ReactNode;
|
||||
}
|
||||
|
||||
export const Sortable = ({ items, onChange }: SortableProps) => {
|
||||
export const Sortable = (props: SortableProps) => {
|
||||
const [itemsWithIds, setItemsWithIds] = useState<SortableItems[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
setItemsWithIds(
|
||||
items.map((item, idx) => ({
|
||||
props.items.map((item, idx) => ({
|
||||
item,
|
||||
id: idx + 1, // +1 because dndtoolkit has problem with "falsy" ids
|
||||
originalIndex: idx,
|
||||
}))
|
||||
);
|
||||
}, [items]);
|
||||
}, [props.items]);
|
||||
|
||||
const sensors = useSensors(
|
||||
useSensor(PointerSensor),
|
||||
@@ -50,6 +51,8 @@ export const Sortable = ({ items, onChange }: SortableProps) => {
|
||||
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
|
||||
);
|
||||
|
||||
const extraClasses = props.className || "";
|
||||
|
||||
return (
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
@@ -58,7 +61,7 @@ export const Sortable = ({ items, onChange }: SortableProps) => {
|
||||
modifiers={[restrictToVerticalAxis]}
|
||||
>
|
||||
<SortableContext items={itemsWithIds} strategy={verticalListSortingStrategy}>
|
||||
<Flex direction="column" gap={2}>
|
||||
<Flex direction="column" gap={2} className={extraClasses}>
|
||||
{itemsWithIds.map(({ id, item }) => (
|
||||
<SortableItem key={id} id={id}>
|
||||
{item}
|
||||
@@ -78,7 +81,7 @@ export const Sortable = ({ items, onChange }: SortableProps) => {
|
||||
const oldIndex = items.findIndex((x) => x.id === active.id);
|
||||
const newIndex = items.findIndex((x) => x.id === over.id);
|
||||
const newArray = arrayMove(items, oldIndex, newIndex);
|
||||
onChange(newArray.map((item) => item.originalIndex));
|
||||
props.onChange(newArray.map((item) => item.originalIndex));
|
||||
return newArray;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user