Ship Expo Router screens, seeded stores, and polished UX so auth, shop, checkout, prescriptions, loyalty, family, and account processes work end-to-end offline. Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
971 B
TypeScript
35 lines
971 B
TypeScript
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
import { create } from "zustand";
|
|
import { createJSONStorage, persist } from "zustand/middleware";
|
|
import { seedFavoriteIds } from "@/lib/data/seed";
|
|
|
|
type FavState = {
|
|
ids: string[];
|
|
toggle: (id: string) => void;
|
|
has: (id: string) => boolean;
|
|
};
|
|
|
|
export const useFavoritesStore = create<FavState>()(
|
|
persist(
|
|
(set, get) => ({
|
|
ids: seedFavoriteIds,
|
|
toggle: (id) => {
|
|
const ids = get().ids;
|
|
set({
|
|
ids: ids.includes(id) ? ids.filter((x) => x !== id) : [...ids, id],
|
|
});
|
|
},
|
|
has: (id) => get().ids.includes(id),
|
|
}),
|
|
{
|
|
name: "gishen-favorites",
|
|
storage: createJSONStorage(() => AsyncStorage),
|
|
version: 2,
|
|
migrate: (persisted: unknown) => {
|
|
const state = (persisted ?? {}) as Partial<FavState>;
|
|
return !state.ids?.length ? { ...state, ids: seedFavoriteIds } : state;
|
|
},
|
|
}
|
|
)
|
|
);
|