-
Notifications
You must be signed in to change notification settings - Fork 103
feat: see planned rout even when no actual ride was executed #1070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AvivAbachi
merged 18 commits into
main
from
1050-see-planned-rout-even-when-no-actual-ride-was-executed
Apr 4, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
acd4d16
feat: add locale support to useSingleLineData hook
AvivAbachi 4913c09
fix startTime is empty
AvivAbachi 3f45452
add gaps
AvivAbachi ce85822
clean code
AvivAbachi d8ef59f
refactor: remove gaps, optimze code, clean routeKey if line change
AvivAbachi faa2225
refactor: simplify state update handlers in SingleLineMapPage
AvivAbachi 70c6187
refactor: event handlers in SingleLineMapPage
AvivAbachi 7ac34a9
refactor: optimize time formatting and filtering logic in useSingleLi…
AvivAbachi 5393446
refactor: enhance useRecenterOnDataChange to center planned route stops
AvivAbachi 511f94f
refactor: optimizing MapContent component
AvivAbachi 6435774
refactor: format Map.scss and fix: map-index-item-title on dark mode
AvivAbachi 635749f
fix: Marker key to use stop.key for make uniqueness keys
AvivAbachi 7c2d7ac
test: SinglelinePage add test bus stop marker visibility route select…
AvivAbachi b8cab11
test: fix test seletors
AvivAbachi e2c03d8
refactor: improve logic in useRecenterOnDataChange
AvivAbachi 9dd504f
refactor: optimize useRecenterOnDataChange logic with useMemo for per…
AvivAbachi 6f9e658
refactor: useRecenterOnDataChange and useSingleLineData improved clar…
AvivAbachi 30ea942
refactor: rename values
AvivAbachi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 28 additions & 11 deletions
39
src/pages/components/map-related/useRecenterOnDataChange.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
import { useEffect } from 'react' | ||
import { useEffect, useMemo } from 'react' | ||
import { LatLngTuple } from 'leaflet' | ||
import { useMap } from 'react-leaflet' | ||
import { MapProps } from './map-types' | ||
|
||
export function useRecenterOnDataChange({ positions }: MapProps) { | ||
export function useRecenterOnDataChange({ positions, plannedRouteStops }: MapProps) { | ||
const map = useMap() | ||
const positionsSum = positions.reduce( | ||
(acc, { loc }) => [acc[0] + loc[0], acc[1] + loc[1]], | ||
[0, 0], | ||
) | ||
const mean: LatLngTuple = [positionsSum[0] / positions.length, positionsSum[1] / positions.length] | ||
console.log('mean: ', mean) | ||
|
||
const center = useMemo(() => { | ||
const sum: LatLngTuple = [0, 0] | ||
const totalPoints = positions.length + plannedRouteStops.length | ||
|
||
if (totalPoints === 0) return sum | ||
|
||
for (const position of positions) { | ||
sum[0] += position.loc[0] | ||
sum[1] += position.loc[1] | ||
} | ||
|
||
for (const stop of plannedRouteStops) { | ||
sum[0] += stop.location.latitude | ||
sum[1] += stop.location.longitude | ||
} | ||
|
||
sum[0] /= totalPoints | ||
sum[1] /= totalPoints | ||
|
||
return sum | ||
}, [positions, plannedRouteStops]) | ||
|
||
NoamGaash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
useEffect(() => { | ||
if (mean[0] || mean[1]) { | ||
map.setView(mean, map.getZoom(), { animate: true }) | ||
if (center[0] || center[1]) { | ||
map.setView(center, map.getZoom(), { animate: true }) | ||
} | ||
}, [mean]) | ||
}, [...center, map]) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.