minor tweaks and optimizations

main
Inga 🏳‍🌈 6 months ago
parent ed1f4bc47c
commit 1022ad5e97
  1. 8
      src/routePlanner/export.tsx
  2. 6
      src/routePlanner/hooks/useMarkers/reducer.ts
  3. 7
      src/shared/collections.test.ts
  4. 7
      src/shared/collections.ts

@ -3,10 +3,8 @@ import type { ExportProps } from './types';
export const ExportComponent = ({ markers }: ExportProps) => {
return (
<>
<button onClick={() => exportMarkersToGpx(markers)}>
Download your route
</button>
</>
<button onClick={() => exportMarkersToGpx(markers)}>
Download your route
</button>
);
};

@ -56,11 +56,11 @@ export const markersReducer = (
switch (type) {
case 'add': {
const key = nanoid(10);
return reindexMarkers([
return [
...markers,
{
key,
shortLabel: 'placeholder',
shortLabel: `${markers.length + 1}`,
longLabel: key.substring(0, 4),
remove: () =>
action.data.dispatcher({
@ -84,7 +84,7 @@ export const markersReducer = (
}),
coordinates: action.data.coordinates,
},
]);
];
}
case 'remove': {
return reindexMarkers([

@ -13,13 +13,6 @@ void t.test('reorderElements', (t) => {
);
};
checkReordering(0, -1, 'bcde');
checkReordering(1, -1, 'acde');
checkReordering(2, -1, 'abde');
checkReordering(3, -1, 'abce');
checkReordering(4, -1, 'abcd');
checkReordering(5, -1, 'abcde');
checkReordering(0, 0, 'abcde');
checkReordering(0, 1, 'bacde');
checkReordering(0, 2, 'bcade');

@ -3,13 +3,6 @@ export const reorderElements = <T>(
oldIndex: number,
newIndex: number,
) => {
if (newIndex < 0) {
return [
...collection.slice(0, oldIndex),
...collection.slice(oldIndex + 1, collection.length),
];
}
if (oldIndex < newIndex) {
return [
...collection.slice(0, oldIndex),

Loading…
Cancel
Save