From 56ec002b41c4f27265dd6c35f4a6ccb55052e7b9 Mon Sep 17 00:00:00 2001 From: fraxle Date: Mon, 6 Jul 2026 18:14:05 +0100 Subject: [PATCH] 3.2.1.4 Fix location saving --- assets/js/hooks/useAppState.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/js/hooks/useAppState.js b/assets/js/hooks/useAppState.js index 208f982..49bebe5 100644 --- a/assets/js/hooks/useAppState.js +++ b/assets/js/hooks/useAppState.js @@ -72,14 +72,20 @@ export function useAppState() { const setLocationAndSave = (loc) => { try { localStorage.setItem('sunscope_last_location', JSON.stringify(loc)); } catch (e) { /* ignore */ } - setLocation(loc); setRecentLocations((prev) => { + // Make sure the spot we're switching away from lands in the recent + // list too - otherwise the very first switch drops it on the floor + // since it was never added to recentLocations before now. + const withCurrent = locKey(location) !== locKey(loc) + ? [location, ...prev.filter((l) => locKey(l) !== locKey(location))] + : prev; // Keep the current spot at the front and the 3 previous distinct // ones behind it (4 total, so 3 chips remain after excluding current). - const next = [loc, ...prev.filter((l) => locKey(l) !== locKey(loc))].slice(0, 4); + const next = [loc, ...withCurrent.filter((l) => locKey(l) !== locKey(loc))].slice(0, 4); try { localStorage.setItem('sunscope_recent_locations', JSON.stringify(next)); } catch (e) { /* ignore */ } return next; }); + setLocation(loc); }; // Pro tier flag is read early so useForecast can pick its refresh cadence