Fixed: edited recipes were not saved locally
This commit is contained in:
Binary file not shown.
@@ -189,7 +189,7 @@ import UIKit
|
||||
```swift
|
||||
let recipeDetail = await mainViewModel.getRecipe(id: 123)
|
||||
*/
|
||||
func getRecipe(id: Int, fetchMode: FetchMode) async -> RecipeDetail? {
|
||||
func getRecipe(id: Int, fetchMode: FetchMode, save: Bool = false) async -> RecipeDetail? {
|
||||
func getLocal() async -> RecipeDetail? {
|
||||
if let recipe: RecipeDetail = await loadLocal(path: "recipe\(id).data") { return recipe }
|
||||
return nil
|
||||
@@ -201,6 +201,10 @@ import UIKit
|
||||
id: id
|
||||
)
|
||||
if let recipe = recipe {
|
||||
if save {
|
||||
self.recipeDetails[id] = recipe
|
||||
await self.saveLocal(recipe, path: "recipe\(id).data")
|
||||
}
|
||||
return recipe
|
||||
} else if let error = error {
|
||||
print(error)
|
||||
|
||||
@@ -406,6 +406,9 @@ struct RecipeViewToolBar: ToolbarContent {
|
||||
}
|
||||
await appState.getCategories()
|
||||
await appState.getCategory(named: viewModel.observableRecipeDetail.recipeCategory, fetchMode: .preferServer)
|
||||
if let id = Int(viewModel.observableRecipeDetail.id) {
|
||||
await appState.getRecipe(id: id, fetchMode: .onlyServer, save: true)
|
||||
}
|
||||
viewModel.editMode = false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user