feat(panel): add a FAVORITED tab with a star on every recipe
This commit is contained in:
@@ -3,6 +3,29 @@ import { Recipe } from '../types';
|
||||
import { DEFAULT_RECIPES, DEFAULT_ADJUSTMENTS } from './defaultRecipes';
|
||||
|
||||
const CUSTOM_RECIPES_KEY = '@camrecipe_pro:custom_recipes';
|
||||
const FAVORITES_KEY = '@camrecipe_pro:favorites';
|
||||
|
||||
// FAVORITED recipes: a list of recipe ids. Pure metadata — starring a recipe
|
||||
// never touches the look, so RESET and re-selecting a recipe leave it alone.
|
||||
export async function getFavoriteIds(): Promise<string[]> {
|
||||
try {
|
||||
const data = await AsyncStorage.getItem(FAVORITES_KEY);
|
||||
if (!data) return [];
|
||||
const parsed = JSON.parse(data);
|
||||
return Array.isArray(parsed) ? parsed.filter((id) => typeof id === 'string') : [];
|
||||
} catch (error) {
|
||||
console.error('Failed to load favorites:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function setFavoriteId(id: string, on: boolean): Promise<void> {
|
||||
const ids = await getFavoriteIds();
|
||||
const updated = on
|
||||
? [...new Set([...ids, id])]
|
||||
: ids.filter((x) => x !== id);
|
||||
await AsyncStorage.setItem(FAVORITES_KEY, JSON.stringify(updated));
|
||||
}
|
||||
|
||||
export async function getCustomRecipes(): Promise<Recipe[]> {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user