Skip to content

Commit

Permalink
extending route should not zoom out to full extent, #396
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Jul 6, 2024
1 parent 7c10e23 commit a064681
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/actions/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/map/ContextMenuContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sidebar/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
>
<AddIcon />
Expand Down
2 changes: 1 addition & 1 deletion src/stores/QueryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export default class QueryStore extends Store<QueryStoreState> {
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) => {
Expand Down
5 changes: 3 additions & 2 deletions test/stores/QueryStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit a064681

Please sign in to comment.