feat: build production-ready wtr weather PWA
This commit is contained in:
28
lib/store.ts
Normal file
28
lib/store.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
"use client";
|
||||
|
||||
import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
|
||||
interface WeatherStore {
|
||||
favorites: string[];
|
||||
selectedStationId: string | null;
|
||||
toggleFavorite: (id: string) => void;
|
||||
selectStation: (id: string) => void;
|
||||
}
|
||||
|
||||
export const useWeatherStore = create<WeatherStore>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
favorites: [],
|
||||
selectedStationId: null,
|
||||
toggleFavorite: (id) =>
|
||||
set((state) => ({
|
||||
favorites: state.favorites.includes(id)
|
||||
? state.favorites.filter((favoriteId) => favoriteId !== id)
|
||||
: [...state.favorites, id],
|
||||
})),
|
||||
selectStation: (id) => set({ selectedStationId: id }),
|
||||
}),
|
||||
{ name: "wtr:preferences" },
|
||||
),
|
||||
);
|
||||
Reference in New Issue
Block a user