feat(recipe): Save and Save As for recipes
Custom recipes can be overwritten in place (TopBar SAVE now offers CANCEL / SAVE AS / SAVE and prefills the current name); bundled recipes stay read-only and only offer Save As. Adds updateCustomRecipe to storageUtils.
This commit is contained in:
@@ -35,6 +35,13 @@ export async function saveCustomRecipe(recipe: Omit<Recipe, 'id' | 'isCustom'>):
|
||||
return newRecipe;
|
||||
}
|
||||
|
||||
// Overwrite an existing custom recipe in place (Save). No-op if the id is gone.
|
||||
export async function updateCustomRecipe(id: string, recipe: Omit<Recipe, 'id' | 'isCustom'>): Promise<void> {
|
||||
const custom = await getCustomRecipes();
|
||||
const updated = custom.map((r) => (r.id === id ? { ...r, ...recipe, id, isCustom: true } : r));
|
||||
await AsyncStorage.setItem(CUSTOM_RECIPES_KEY, JSON.stringify(updated));
|
||||
}
|
||||
|
||||
export async function deleteCustomRecipe(id: string): Promise<void> {
|
||||
const custom = await getCustomRecipes();
|
||||
const updated = custom.filter(r => r.id !== id);
|
||||
|
||||
Reference in New Issue
Block a user