From a06468128892258de87d3150618ccb3c2188cf15 Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 6 Jul 2024 10:29:12 +0200 Subject: [PATCH] extending route should not zoom out to full extent, #396 --- src/actions/Actions.ts | 4 +++- src/map/ContextMenuContent.tsx | 4 ++-- src/sidebar/search/Search.tsx | 2 +- src/stores/QueryStore.ts | 2 +- test/stores/QueryStore.test.ts | 5 +++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/actions/Actions.ts b/src/actions/Actions.ts index 1f9164fa..1a0f0a5a 100644 --- a/src/actions/Actions.ts +++ b/src/actions/Actions.ts @@ -40,11 +40,13 @@ export class AddPoint implements Action { readonly atIndex: number readonly coordinate: Coordinate readonly isInitialized: boolean + readonly zoom: boolean - constructor(atIndex: number, coordinate: Coordinate, isInitialized: boolean) { + constructor(atIndex: number, coordinate: Coordinate, isInitialized: boolean, zoom: boolean) { this.atIndex = atIndex this.coordinate = coordinate this.isInitialized = isInitialized + this.zoom = zoom } } diff --git a/src/map/ContextMenuContent.tsx b/src/map/ContextMenuContent.tsx index ad1c2761..4c2132c8 100644 --- a/src/map/ContextMenuContent.tsx +++ b/src/map/ContextMenuContent.tsx @@ -22,7 +22,7 @@ export function ContextMenuContent({ }) { const dispatchAddPoint = function (coordinate: Coordinate) { onSelect() - Dispatcher.dispatch(new AddPoint(queryPoints.length, coordinate, true)) + Dispatcher.dispatch(new AddPoint(queryPoints.length, coordinate, true, false)) } const dispatchSetPoint = function (point: QueryPoint, coordinate: Coordinate) { @@ -62,7 +62,7 @@ export function ContextMenuContent({ // to be closest to the clicked location, because for every route the n-th snapped_waypoint corresponds to // the n-th query point const index = findNextWayPoint(routes, coordinate).nextWayPoint - Dispatcher.dispatch(new AddPoint(index, coordinate, true)) + Dispatcher.dispatch(new AddPoint(index, coordinate, true, true)) } } diff --git a/src/sidebar/search/Search.tsx b/src/sidebar/search/Search.tsx index 28e6ab75..2473e245 100644 --- a/src/sidebar/search/Search.tsx +++ b/src/sidebar/search/Search.tsx @@ -50,7 +50,7 @@ export default function Search({ points }: { points: QueryPoint[] }) { ? { paddingTop: '2rem' } : {} } - onClick={() => Dispatcher.dispatch(new AddPoint(points.length, { lat: 0, lng: 0 }, false))} + onClick={() => Dispatcher.dispatch(new AddPoint(points.length, { lat: 0, lng: 0 }, false, true))} className={styles.addSearchBox} > diff --git a/src/stores/QueryStore.ts b/src/stores/QueryStore.ts index c1e4edbf..924b67d7 100644 --- a/src/stores/QueryStore.ts +++ b/src/stores/QueryStore.ts @@ -193,7 +193,7 @@ export default class QueryStore extends Store { queryPoints: newPoints, } - return this.routeIfReady(newState, true) + return this.routeIfReady(newState, action.zoom) } else if (action instanceof SetQueryPoints) { // make sure that some things are set correctly, regardless of what was passed in here. const queryPoints = action.queryPoints.map((point, i) => { diff --git a/test/stores/QueryStore.test.ts b/test/stores/QueryStore.test.ts index 04bd9400..3ed53258 100644 --- a/test/stores/QueryStore.test.ts +++ b/test/stores/QueryStore.test.ts @@ -12,6 +12,7 @@ import { SetPoint, SetVehicleProfile, } from '@/actions/Actions' +import { tr } from '@/translation/Translation' class ApiMock implements Api { private readonly callback: { (args: RoutingArgs): void } @@ -168,7 +169,7 @@ describe('QueryStore', () => { const newPointId = store.state.nextQueryPointId const atIndex = 1 - const newState = store.reduce(store.state, new AddPoint(atIndex, { lat: 1, lng: 1 }, false)) + const newState = store.reduce(store.state, new AddPoint(atIndex, { lat: 1, lng: 1 }, false, true)) expect(newState.queryPoints.findIndex(p => p.id === newPointId)).toEqual(atIndex) expect(newState.queryPoints.every((p, i) => isCorrectType(p, i, newState.queryPoints.length))).toBeTruthy() @@ -190,7 +191,7 @@ describe('QueryStore', () => { routingProfile: { name: 'car' }, } - const newState = store.reduce(state, new AddPoint(atIndex, { lat: 1, lng: 1 }, true)) + const newState = store.reduce(state, new AddPoint(atIndex, { lat: 1, lng: 1 }, true, true)) expect(newState.queryPoints.findIndex(p => p.id === newPointId)).toEqual(atIndex) expect(newState.queryPoints[atIndex].queryText).toEqual('1,1') // if initialized flag is set the coordinates are set as query text expect(counter).toEqual(1)