mirror of
https://github.com/zvx-echo6/navi.git
synced 2026-05-20 14:44:51 +02:00
fix: search viewport init, theme-clears-route bug, preview-during-route
Three regressions fixed: 1. mapCenter is now initialized on map 'load' event, not just 'moveend'. Searches immediately after page load now correctly include viewport bias instead of falling back to default Twin Falls coords. 2. setThemeOverride had stray code from startDirections that wiped stops and added undefined place data. Toggling theme cleared the active route. Restored setThemeOverride to its correct theme-only implementation. 3. usePanelState returned ROUTE_CALCULATED before checking selectedPlace, so preview cards could never appear alongside a calculated route. Refactored to decouple preview state from route state - preview renders whenever selectedPlace exists, independent of route state.
This commit is contained in:
parent
5eb83e9b4b
commit
f5e0b9606e
3 changed files with 21 additions and 18 deletions
20
src/store.js
20
src/store.js
|
|
@ -1,4 +1,5 @@
|
|||
import { create } from 'zustand'
|
||||
import { shallow } from 'zustand/shallow'
|
||||
|
||||
export const useStore = create((set, get) => ({
|
||||
// ── Search state ──
|
||||
|
|
@ -108,9 +109,6 @@ export const useStore = create((set, get) => ({
|
|||
if (override) {
|
||||
localStorage.setItem('navi-theme-override', override)
|
||||
} else {
|
||||
// GPS denied, no stops: add destination, show empty origin slot
|
||||
clearStops()
|
||||
addStop({ lat: place.lat, lon: place.lon, name: place.name, source: place.source, matchCode: place.matchCode })
|
||||
localStorage.removeItem('navi-theme-override')
|
||||
}
|
||||
},
|
||||
|
|
@ -124,16 +122,14 @@ export const useStore = create((set, get) => ({
|
|||
setActiveTab: (tab) => set({ activeTab: tab }),
|
||||
setEditingContact: (c) => set({ editingContact: c }),
|
||||
clearEditingContact: () => set({ editingContact: null }),
|
||||
}))
|
||||
}), shallow)
|
||||
|
||||
// ── Panel state selector ──
|
||||
// IDLE | PREVIEW | ROUTING | PREVIEW_ROUTING | ROUTE_CALCULATED
|
||||
// Returns { hasPreview: boolean, routeState: 'NONE' | 'ROUTING' | 'CALCULATED' }
|
||||
// Preview and route states are now orthogonal - preview can show alongside any route state
|
||||
export const usePanelState = () => {
|
||||
return useStore((s) => {
|
||||
if (s.route) return "ROUTE_CALCULATED"
|
||||
if (s.selectedPlace && s.stops.length >= 1) return "PREVIEW_ROUTING"
|
||||
if (s.selectedPlace) return "PREVIEW"
|
||||
if (s.stops.length >= 1) return "ROUTING"
|
||||
return "IDLE"
|
||||
})
|
||||
return useStore((s) => ({
|
||||
hasPreview: !!s.selectedPlace,
|
||||
routeState: s.route ? "CALCULATED" : (s.stops.length >= 1 ? "ROUTING" : "NONE")
|
||||
}), shallow)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue