feat(panel): add a FAVORITED tab with a star on every recipe

This commit is contained in:
2026-09-11 09:32:21 +07:00
parent ba7e579986
commit ba971f136c
4 changed files with 120 additions and 16 deletions
+23
View File
@@ -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 {