| 
									
										
										
										
											2024-05-06 10:01:56 -05:00
										 |  |  | import { useLocalStorage, useSessionStorage } from "@vueuse/core"; | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | import type { RegisteredParser, TimelineEventType } from "~/lib/api/types/recipe"; | 
					
						
							|  |  |  | import type { QueryFilterJSON } from "~/lib/api/types/response"; | 
					
						
							| 
									
										
										
										
											2022-07-31 14:39:35 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-19 18:37:18 -06:00
										 |  |  | export interface UserPrintPreferences { | 
					
						
							|  |  |  |   imagePosition: string; | 
					
						
							|  |  |  |   showDescription: boolean; | 
					
						
							|  |  |  |   showNotes: boolean; | 
					
						
							| 
									
										
										
										
											2024-06-18 11:08:22 +02:00
										 |  |  |   showNutrition: boolean; | 
					
						
							| 
									
										
										
										
											2023-02-19 18:37:18 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-06 10:01:56 -05:00
										 |  |  | export interface UserSearchQuery { | 
					
						
							|  |  |  |   recipe: string; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-19 18:37:18 -06:00
										 |  |  | export enum ImagePosition { | 
					
						
							|  |  |  |   hidden = "hidden", | 
					
						
							|  |  |  |   left = "left", | 
					
						
							|  |  |  |   right = "right", | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-27 07:30:15 +10:00
										 |  |  | export interface UserMealPlanPreferences { | 
					
						
							|  |  |  |   numberOfDays: number; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-31 14:39:35 -05:00
										 |  |  | export interface UserRecipePreferences { | 
					
						
							|  |  |  |   orderBy: string; | 
					
						
							|  |  |  |   orderDirection: string; | 
					
						
							| 
									
										
										
										
											2022-11-30 23:59:30 -06:00
										 |  |  |   filterNull: boolean; | 
					
						
							| 
									
										
										
										
											2022-07-31 14:39:35 -05:00
										 |  |  |   sortIcon: string; | 
					
						
							|  |  |  |   useMobileCards: boolean; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-21 21:58:41 -06:00
										 |  |  | export interface UserShoppingListPreferences { | 
					
						
							| 
									
										
										
										
											2024-03-06 15:11:43 +00:00
										 |  |  |   viewAllLists: boolean; | 
					
						
							| 
									
										
										
										
											2023-02-21 21:58:41 -06:00
										 |  |  |   viewByLabel: boolean; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 12:46:00 -05:00
										 |  |  | export interface UserTimelinePreferences { | 
					
						
							|  |  |  |   orderDirection: string; | 
					
						
							| 
									
										
										
										
											2024-03-12 10:20:48 -05:00
										 |  |  |   types: TimelineEventType[]; | 
					
						
							| 
									
										
										
										
											2023-04-25 12:46:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-22 04:45:07 -05:00
										 |  |  | export interface UserParsingPreferences { | 
					
						
							|  |  |  |   parser: RegisteredParser; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-05 13:57:30 -06:00
										 |  |  | export interface UserCookbooksPreferences { | 
					
						
							|  |  |  |   hideOtherHouseholds: boolean; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-03 07:27:41 -06:00
										 |  |  | export interface UserRecipeFinderPreferences { | 
					
						
							|  |  |  |   foodIds: string[]; | 
					
						
							|  |  |  |   toolIds: string[]; | 
					
						
							|  |  |  |   queryFilter: string; | 
					
						
							|  |  |  |   queryFilterJSON: QueryFilterJSON; | 
					
						
							|  |  |  |   maxMissingFoods: number; | 
					
						
							|  |  |  |   maxMissingTools: number; | 
					
						
							|  |  |  |   includeFoodsOnHand: boolean; | 
					
						
							|  |  |  |   includeToolsOnHand: boolean; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-27 07:30:15 +10:00
										 |  |  | export function useUserMealPlanPreferences(): Ref<UserMealPlanPreferences> { | 
					
						
							|  |  |  |   const fromStorage = useLocalStorage( | 
					
						
							|  |  |  |     "meal-planner-preferences", | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       numberOfDays: 7, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     { mergeDefaults: true }, | 
					
						
							| 
									
										
										
										
											2024-05-27 07:30:15 +10:00
										 |  |  |     // we cast to a Ref because by default it will return an optional type ref
 | 
					
						
							|  |  |  |     // but since we pass defaults we know all properties are set.
 | 
					
						
							|  |  |  |   ) as unknown as Ref<UserMealPlanPreferences>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return fromStorage; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-19 18:37:18 -06:00
										 |  |  | export function useUserPrintPreferences(): Ref<UserPrintPreferences> { | 
					
						
							|  |  |  |   const fromStorage = useLocalStorage( | 
					
						
							|  |  |  |     "recipe-print-preferences", | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       imagePosition: "left", | 
					
						
							|  |  |  |       showDescription: true, | 
					
						
							|  |  |  |       showNotes: true, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     { mergeDefaults: true }, | 
					
						
							| 
									
										
										
										
											2023-02-19 18:37:18 -06:00
										 |  |  |     // we cast to a Ref because by default it will return an optional type ref
 | 
					
						
							|  |  |  |     // but since we pass defaults we know all properties are set.
 | 
					
						
							|  |  |  |   ) as unknown as Ref<UserPrintPreferences>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return fromStorage; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-31 14:39:35 -05:00
										 |  |  | export function useUserSortPreferences(): Ref<UserRecipePreferences> { | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |   const { $globals } = useNuxtApp(); | 
					
						
							| 
									
										
										
										
											2022-07-31 14:39:35 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const fromStorage = useLocalStorage( | 
					
						
							|  |  |  |     "recipe-section-preferences", | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       orderBy: "name", | 
					
						
							|  |  |  |       orderDirection: "asc", | 
					
						
							| 
									
										
										
										
											2022-11-30 23:59:30 -06:00
										 |  |  |       filterNull: false, | 
					
						
							| 
									
										
										
										
											2022-07-31 14:39:35 -05:00
										 |  |  |       sortIcon: $globals.icons.sortAlphabeticalAscending, | 
					
						
							|  |  |  |       useMobileCards: false, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     { mergeDefaults: true }, | 
					
						
							| 
									
										
										
										
											2022-07-31 14:39:35 -05:00
										 |  |  |     // we cast to a Ref because by default it will return an optional type ref
 | 
					
						
							|  |  |  |     // but since we pass defaults we know all properties are set.
 | 
					
						
							| 
									
										
										
										
											2022-08-08 18:38:18 -08:00
										 |  |  |   ) as unknown as Ref<UserRecipePreferences>; | 
					
						
							| 
									
										
										
										
											2022-07-31 14:39:35 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return fromStorage; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-02-21 21:58:41 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-06 10:01:56 -05:00
										 |  |  | export function useUserSearchQuerySession(): Ref<UserSearchQuery> { | 
					
						
							|  |  |  |   const fromStorage = useSessionStorage( | 
					
						
							|  |  |  |     "search-query", | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       recipe: "", | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     { mergeDefaults: true }, | 
					
						
							| 
									
										
										
										
											2024-05-06 10:01:56 -05:00
										 |  |  |     // we cast to a Ref because by default it will return an optional type ref
 | 
					
						
							|  |  |  |     // but since we pass defaults we know all properties are set.
 | 
					
						
							|  |  |  |   ) as unknown as Ref<UserSearchQuery>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return fromStorage; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-21 21:58:41 -06:00
										 |  |  | export function useShoppingListPreferences(): Ref<UserShoppingListPreferences> { | 
					
						
							|  |  |  |   const fromStorage = useLocalStorage( | 
					
						
							|  |  |  |     "shopping-list-preferences", | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-03-06 15:11:43 +00:00
										 |  |  |       viewAllLists: false, | 
					
						
							| 
									
										
										
										
											2024-09-19 15:24:46 -05:00
										 |  |  |       viewByLabel: true, | 
					
						
							| 
									
										
										
										
											2023-02-21 21:58:41 -06:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     { mergeDefaults: true }, | 
					
						
							| 
									
										
										
										
											2023-02-21 21:58:41 -06:00
										 |  |  |     // we cast to a Ref because by default it will return an optional type ref
 | 
					
						
							|  |  |  |     // but since we pass defaults we know all properties are set.
 | 
					
						
							|  |  |  |   ) as unknown as Ref<UserShoppingListPreferences>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return fromStorage; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-04-25 12:46:00 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function useTimelinePreferences(): Ref<UserTimelinePreferences> { | 
					
						
							|  |  |  |   const fromStorage = useLocalStorage( | 
					
						
							|  |  |  |     "timeline-preferences", | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       orderDirection: "asc", | 
					
						
							| 
									
										
										
										
											2024-03-12 10:20:48 -05:00
										 |  |  |       types: ["info", "system", "comment"] as TimelineEventType[], | 
					
						
							| 
									
										
										
										
											2023-04-25 12:46:00 -05:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     { mergeDefaults: true }, | 
					
						
							| 
									
										
										
										
											2023-04-25 12:46:00 -05:00
										 |  |  |     // we cast to a Ref because by default it will return an optional type ref
 | 
					
						
							|  |  |  |     // but since we pass defaults we know all properties are set.
 | 
					
						
							|  |  |  |   ) as unknown as Ref<UserTimelinePreferences>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return fromStorage; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-05-22 04:45:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function useParsingPreferences(): Ref<UserParsingPreferences> { | 
					
						
							|  |  |  |   const fromStorage = useLocalStorage( | 
					
						
							|  |  |  |     "parsing-preferences", | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       parser: "nlp", | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     { mergeDefaults: true }, | 
					
						
							| 
									
										
										
										
											2024-05-22 04:45:07 -05:00
										 |  |  |     // we cast to a Ref because by default it will return an optional type ref
 | 
					
						
							|  |  |  |     // but since we pass defaults we know all properties are set.
 | 
					
						
							|  |  |  |   ) as unknown as Ref<UserParsingPreferences>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return fromStorage; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-11-05 13:57:30 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function useCookbookPreferences(): Ref<UserCookbooksPreferences> { | 
					
						
							|  |  |  |   const fromStorage = useLocalStorage( | 
					
						
							|  |  |  |     "cookbook-preferences", | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       hideOtherHouseholds: false, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     { mergeDefaults: true }, | 
					
						
							| 
									
										
										
										
											2024-11-05 13:57:30 -06:00
										 |  |  |     // we cast to a Ref because by default it will return an optional type ref
 | 
					
						
							|  |  |  |     // but since we pass defaults we know all properties are set.
 | 
					
						
							|  |  |  |   ) as unknown as Ref<UserCookbooksPreferences>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return fromStorage; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-12-03 07:27:41 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function useRecipeFinderPreferences(): Ref<UserRecipeFinderPreferences> { | 
					
						
							|  |  |  |   const fromStorage = useLocalStorage( | 
					
						
							|  |  |  |     "recipe-finder-preferences", | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       foodIds: [], | 
					
						
							|  |  |  |       toolIds: [], | 
					
						
							|  |  |  |       queryFilter: "", | 
					
						
							|  |  |  |       queryFilterJSON: { parts: [] } as QueryFilterJSON, | 
					
						
							|  |  |  |       maxMissingFoods: 20, | 
					
						
							|  |  |  |       maxMissingTools: 20, | 
					
						
							|  |  |  |       includeFoodsOnHand: true, | 
					
						
							|  |  |  |       includeToolsOnHand: true, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     { mergeDefaults: true }, | 
					
						
							| 
									
										
										
										
											2024-12-03 07:27:41 -06:00
										 |  |  |     // we cast to a Ref because by default it will return an optional type ref
 | 
					
						
							|  |  |  |     // but since we pass defaults we know all properties are set.
 | 
					
						
							|  |  |  |   ) as unknown as Ref<UserRecipeFinderPreferences>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return fromStorage; | 
					
						
							|  |  |  | } |