Skip to content

Commit

Permalink
Merge pull request #796 from MarechJ/fix/map_rotation_list
Browse files Browse the repository at this point in the history
fix removing and changing to map in map rotation list
  • Loading branch information
FlorianSW authored Dec 19, 2024
2 parents abd0312 + fc8bdc4 commit aacacbd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ const Item = ({thisList, isDragging, mapLayer, index, onRemove, onChange, isSave
edge="end"
aria-label="set map"
disabled={!isSaved}
onClick={() => onChange(mapLayer)}
onClick={(event) => {
event.stopPropagation();
onChange({
...mapLayer,
id: mapLayer.originalId,
});
}}
size="large"
>
<InputIcon/>
Expand All @@ -80,7 +86,10 @@ const Item = ({thisList, isDragging, mapLayer, index, onRemove, onChange, isSave
<IconButton
edge="end"
aria-label="delete"
onClick={() => onRemove(index)}
onClick={(event) => {
event.stopPropagation();
onRemove(index);
}}
size="large"
>
<DeleteIcon/>
Expand All @@ -101,6 +110,9 @@ const DraggableList = memo(({maps, onDragEnd, onRemove, onChange, isSaved}) => {
function handleDragEnd(event) {
const {active, over} = event;

// if the item is only being clicked, don't do anything
if (!over) return;

if (active.id !== over.id) {
const oldIndex = items.findIndex((m) => m.id === active.id);
const newIndex = items.findIndex((m) => m.id === over.id);
Expand All @@ -117,13 +129,20 @@ const DraggableList = memo(({maps, onDragEnd, onRemove, onChange, isSaved}) => {
}

useEffect(() => {
setItems(maps.map((m, idx) => ({...m, id: `${m.id}-${idx}`})));
setItems(maps.map((m, idx) => ({...m, originalId: m.id, id: `${m.id}-${idx}`})));
}, [maps]);

const [items, setItems] = useState([]);
const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
}));
const sensors = useSensors(
useSensor(PointerSensor, {
activationConstraint: {
delay: 100,
},
}),
useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
}),
);

return <DndContext
sensors={sensors}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ const MapRotation = () => {
};

const onRemoveItem = useCallback((index) => {
rotation.splice(index, 1);
setRotation(Array.from(rotation));
setRotation((prevRotation) => {
const newRotation = prevRotation.slice(0, index).concat(prevRotation.slice(index + 1));
return newRotation;
});
});

const onMapChange = useCallback((mapLayer) => {
Expand Down

0 comments on commit aacacbd

Please sign in to comment.