| 
									
										
										
										
											2022-07-31 14:39:35 -05:00
										 |  |  | import { Ref, useContext } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2024-05-06 10:01:56 -05:00
										 |  |  | import { useLocalStorage, useSessionStorage } from "@vueuse/core"; | 
					
						
							| 
									
										
										
										
											2024-05-22 04:45:07 -05:00
										 |  |  | import { RegisteredParser, TimelineEventType } from "~/lib/api/types/recipe"; | 
					
						
							| 
									
										
										
										
											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-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-05-27 07:30:15 +10:00
										 |  |  | export function useUserMealPlanPreferences(): Ref<UserMealPlanPreferences> { | 
					
						
							|  |  |  |   const fromStorage = useLocalStorage( | 
					
						
							|  |  |  |     "meal-planner-preferences", | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       numberOfDays: 7, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { mergeDefaults: true } | 
					
						
							|  |  |  |     // 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, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { mergeDefaults: true } | 
					
						
							|  |  |  |     // 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> { | 
					
						
							|  |  |  |   const { $globals } = useContext(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { mergeDefaults: true } | 
					
						
							|  |  |  |     // 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: "", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { mergeDefaults: true } | 
					
						
							|  |  |  |     // 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, | 
					
						
							| 
									
										
										
										
											2023-02-21 21:58:41 -06:00
										 |  |  |       viewByLabel: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { mergeDefaults: true } | 
					
						
							|  |  |  |     // 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
										 |  |  |     }, | 
					
						
							|  |  |  |     { mergeDefaults: true } | 
					
						
							|  |  |  |     // 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", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { mergeDefaults: true } | 
					
						
							|  |  |  |     // 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; | 
					
						
							|  |  |  | } |