3.2.1.4
Fix location saving
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user