feat: redesign dashboard around place search
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
|
||||
import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
import type { SelectedLocation } from "@/types/location";
|
||||
|
||||
interface WeatherStore {
|
||||
favorites: string[];
|
||||
selectedStationId: string | null;
|
||||
selectedLocation: SelectedLocation | null;
|
||||
toggleFavorite: (id: string) => void;
|
||||
selectStation: (id: string) => void;
|
||||
selectLocation: (location: SelectedLocation) => void;
|
||||
}
|
||||
|
||||
export const useWeatherStore = create<WeatherStore>()(
|
||||
@@ -15,13 +18,15 @@ export const useWeatherStore = create<WeatherStore>()(
|
||||
(set) => ({
|
||||
favorites: [],
|
||||
selectedStationId: null,
|
||||
selectedLocation: null,
|
||||
toggleFavorite: (id) =>
|
||||
set((state) => ({
|
||||
favorites: state.favorites.includes(id)
|
||||
? state.favorites.filter((favoriteId) => favoriteId !== id)
|
||||
: [...state.favorites, id],
|
||||
})),
|
||||
selectStation: (id) => set({ selectedStationId: id }),
|
||||
selectStation: (id) => set({ selectedStationId: id, selectedLocation: null }),
|
||||
selectLocation: (location) => set({ selectedStationId: location.stationId, selectedLocation: location }),
|
||||
}),
|
||||
{ name: "wtr:preferences" },
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user