diff --git a/frontend/src/stores/recipes.ts b/frontend/src/stores/recipes.ts index e224f61..b41e521 100644 --- a/frontend/src/stores/recipes.ts +++ b/frontend/src/stores/recipes.ts @@ -21,6 +21,35 @@ const BOOKMARKS_MAX = 50 const MISSING_MODE_KEY = 'kiwi:builder_missing_mode' const FILTER_MODE_KEY = 'kiwi:builder_filter_mode' +const CONSTRAINTS_KEY = 'kiwi:constraints' +const ALLERGIES_KEY = 'kiwi:allergies' + +function loadConstraints(): string[] { + try { + const raw = localStorage.getItem(CONSTRAINTS_KEY) + return raw ? JSON.parse(raw) : [] + } catch { + return [] + } +} + +function saveConstraints(vals: string[]) { + localStorage.setItem(CONSTRAINTS_KEY, JSON.stringify(vals)) +} + +function loadAllergies(): string[] { + try { + const raw = localStorage.getItem(ALLERGIES_KEY) + return raw ? JSON.parse(raw) : [] + } catch { + return [] + } +} + +function saveAllergies(vals: string[]) { + localStorage.setItem(ALLERGIES_KEY, JSON.stringify(vals)) +} + type MissingIngredientMode = 'hidden' | 'greyed' | 'add-to-cart' type BuilderFilterMode = 'text' | 'tags' @@ -95,8 +124,8 @@ export const useRecipesStore = defineStore('recipes', () => { // Request parameters const level = ref(1) - const constraints = ref([]) - const allergies = ref([]) + const constraints = ref(loadConstraints()) + const allergies = ref(loadAllergies()) const hardDayMode = ref(false) const maxMissing = ref(null) const styleId = ref(null) @@ -126,6 +155,8 @@ export const useRecipesStore = defineStore('recipes', () => { // Persist wizard prefs on change watch(missingIngredientMode, (val) => localStorage.setItem(MISSING_MODE_KEY, val)) watch(builderFilterMode, (val) => localStorage.setItem(FILTER_MODE_KEY, val)) + watch(constraints, (val) => saveConstraints(val)) + watch(allergies, (val) => saveAllergies(val)) const dismissedCount = computed(() => dismissedIds.value.size) @@ -241,6 +272,16 @@ export const useRecipesStore = defineStore('recipes', () => { localStorage.removeItem(BOOKMARKS_KEY) } + function clearConstraints() { + constraints.value = [] + localStorage.removeItem(CONSTRAINTS_KEY) + } + + function clearAllergies() { + allergies.value = [] + localStorage.removeItem(ALLERGIES_KEY) + } + function clearResult() { result.value = null error.value = null @@ -270,6 +311,8 @@ export const useRecipesStore = defineStore('recipes', () => { isBookmarked, toggleBookmark, clearBookmarks, + clearConstraints, + clearAllergies, missingIngredientMode, builderFilterMode, suggest,