From 1022ad5e97f9c3b186fdd443b08f0087164fda31 Mon Sep 17 00:00:00 2001 From: Inga Date: Sun, 19 Nov 2023 04:38:39 +0000 Subject: [PATCH] minor tweaks and optimizations --- src/routePlanner/export.tsx | 8 +++----- src/routePlanner/hooks/useMarkers/reducer.ts | 6 +++--- src/shared/collections.test.ts | 7 ------- src/shared/collections.ts | 7 ------- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/routePlanner/export.tsx b/src/routePlanner/export.tsx index 21c8621..5760173 100644 --- a/src/routePlanner/export.tsx +++ b/src/routePlanner/export.tsx @@ -3,10 +3,8 @@ import type { ExportProps } from './types'; export const ExportComponent = ({ markers }: ExportProps) => { return ( - <> - - + ); }; diff --git a/src/routePlanner/hooks/useMarkers/reducer.ts b/src/routePlanner/hooks/useMarkers/reducer.ts index dd19ae6..e8f594b 100644 --- a/src/routePlanner/hooks/useMarkers/reducer.ts +++ b/src/routePlanner/hooks/useMarkers/reducer.ts @@ -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([ diff --git a/src/shared/collections.test.ts b/src/shared/collections.test.ts index 2a59454..8ff22b8 100644 --- a/src/shared/collections.test.ts +++ b/src/shared/collections.test.ts @@ -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'); diff --git a/src/shared/collections.ts b/src/shared/collections.ts index 58388ea..edefd9d 100644 --- a/src/shared/collections.ts +++ b/src/shared/collections.ts @@ -3,13 +3,6 @@ export const reorderElements = ( 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),