mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-11-03 02:33:31 -05:00 
			
		
		
		
	* changed default sort direction for certain attrs * added workaround for filtering out null datetimes * filtered out null-valued results for certain sorts * removed unecessary parse * used minyear instead of 1900
		
			
				
	
	
		
			31 lines
		
	
	
		
			870 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			870 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { Ref, useContext } from "@nuxtjs/composition-api";
 | 
						|
import { useLocalStorage } from "@vueuse/core";
 | 
						|
 | 
						|
export interface UserRecipePreferences {
 | 
						|
  orderBy: string;
 | 
						|
  orderDirection: string;
 | 
						|
  filterNull: boolean;
 | 
						|
  sortIcon: string;
 | 
						|
  useMobileCards: boolean;
 | 
						|
}
 | 
						|
 | 
						|
export function useUserSortPreferences(): Ref<UserRecipePreferences> {
 | 
						|
  const { $globals } = useContext();
 | 
						|
 | 
						|
  const fromStorage = useLocalStorage(
 | 
						|
    "recipe-section-preferences",
 | 
						|
    {
 | 
						|
      orderBy: "name",
 | 
						|
      orderDirection: "asc",
 | 
						|
      filterNull: false,
 | 
						|
      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.
 | 
						|
  ) as unknown as Ref<UserRecipePreferences>;
 | 
						|
 | 
						|
  return fromStorage;
 | 
						|
}
 |