WIP - Complete App refactoring
This commit is contained in:
@@ -9,11 +9,11 @@ import Foundation
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
|
||||
/*
|
||||
@MainActor class AppState: ObservableObject {
|
||||
@Published var categories: [Category] = []
|
||||
@Published var recipes: [String: [Recipe]] = [:]
|
||||
@Published var recipeDetails: [Int: RecipeDetail] = [:]
|
||||
@Published var recipes: [String: [CookbookApiRecipeV1]] = [:]
|
||||
@Published var recipeDetails: [Int: CookbookApiRecipeDetailV1] = [:]
|
||||
@Published var timers: [String: RecipeTimer] = [:]
|
||||
var recipeImages: [Int: [String: UIImage]] = [:]
|
||||
var imagesNeedUpdate: [Int: [String: Bool]] = [:]
|
||||
@@ -86,7 +86,7 @@ import UIKit
|
||||
func getCategory(named name: String, fetchMode: FetchMode) async {
|
||||
print("getCategory(\(name), fetchMode: \(fetchMode))")
|
||||
func getLocal() async -> Bool {
|
||||
if let recipes: [Recipe] = await loadLocal(path: "category_\(categoryString).data") {
|
||||
if let recipes: [CookbookApiRecipeV1] = await loadLocal(path: "category_\(categoryString).data") {
|
||||
self.recipes[name] = recipes
|
||||
return true
|
||||
}
|
||||
@@ -159,7 +159,7 @@ import UIKit
|
||||
```swift
|
||||
let recipes = await mainViewModel.getRecipes()
|
||||
*/
|
||||
func getRecipes() async -> [Recipe] {
|
||||
func getRecipes() async -> [CookbookApiRecipeV1] {
|
||||
let (recipes, error) = await cookbookApi.getRecipes(
|
||||
auth: UserSettings.shared.authString
|
||||
)
|
||||
@@ -168,7 +168,7 @@ import UIKit
|
||||
} else if let error = error {
|
||||
print(error)
|
||||
}
|
||||
var allRecipes: [Recipe] = []
|
||||
var allRecipes: [CookbookApiRecipeV1] = []
|
||||
for category in categories {
|
||||
if let recipeArray = self.recipes[category.name] {
|
||||
allRecipes.append(contentsOf: recipeArray)
|
||||
@@ -193,13 +193,13 @@ import UIKit
|
||||
```swift
|
||||
let recipeDetail = await mainViewModel.getRecipe(id: 123)
|
||||
*/
|
||||
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 }
|
||||
func getRecipe(id: Int, fetchMode: FetchMode, save: Bool = false) async -> CookbookApiRecipeDetailV1? {
|
||||
func getLocal() async -> CookbookApiRecipeDetailV1? {
|
||||
if let recipe: CookbookApiRecipeDetailV1 = await loadLocal(path: "recipe\(id).data") { return recipe }
|
||||
return nil
|
||||
}
|
||||
|
||||
func getServer() async -> RecipeDetail? {
|
||||
func getServer() async -> CookbookApiRecipeDetailV1? {
|
||||
let (recipe, error) = await cookbookApi.getRecipe(
|
||||
auth: UserSettings.shared.authString,
|
||||
id: id
|
||||
@@ -483,7 +483,7 @@ import UIKit
|
||||
```swift
|
||||
let uploadResult = await mainViewModel.uploadRecipe(recipeDetail: myRecipeDetail, createNew: true)
|
||||
*/
|
||||
func uploadRecipe(recipeDetail: RecipeDetail, createNew: Bool) async -> RequestAlert? {
|
||||
func uploadRecipe(recipeDetail: CookbookApiRecipeDetailV1, createNew: Bool) async -> RequestAlert? {
|
||||
var error: NetworkError? = nil
|
||||
if createNew {
|
||||
error = await cookbookApi.createRecipe(
|
||||
@@ -502,7 +502,7 @@ import UIKit
|
||||
return nil
|
||||
}
|
||||
|
||||
func importRecipe(url: String) async -> (RecipeDetail?, RequestAlert?) {
|
||||
func importRecipe(url: String) async -> (CookbookApiRecipeDetailV1?, RequestAlert?) {
|
||||
guard let data = JSONEncoder.safeEncode(RecipeImportRequest(url: url)) else { return (nil, .REQUEST_DROPPED) }
|
||||
let (recipeDetail, error) = await cookbookApi.importRecipe(
|
||||
auth: UserSettings.shared.authString,
|
||||
@@ -633,3 +633,4 @@ extension AppState {
|
||||
timers.removeValue(forKey: recipeId)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user