| 
									
										
										
										
											2022-07-31 14:39:35 -05:00
										 |  |  | import { Ref, useContext } from "@nuxtjs/composition-api"; | 
					
						
							|  |  |  | import { useLocalStorage } from "@vueuse/core"; | 
					
						
							| 
									
										
										
										
											2024-03-12 10:20:48 -05:00
										 |  |  | import { 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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export enum ImagePosition { | 
					
						
							|  |  |  |   hidden = "hidden", | 
					
						
							|  |  |  |   left = "left", | 
					
						
							|  |  |  |   right = "right", | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2024-03-25 11:04:42 -05:00
										 |  |  |   searchQuery: string; | 
					
						
							| 
									
										
										
										
											2022-07-31 14:39:35 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2024-03-25 11:04:42 -05:00
										 |  |  |       searchQuery: "", | 
					
						
							| 
									
										
										
										
											2022-07-31 14:39:35 -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.
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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; | 
					
						
							|  |  |  | } |