183 lines
6.7 KiB
Swift
183 lines
6.7 KiB
Swift
//
|
|
// ContentView.swift
|
|
// Nextcloud Cookbook iOS Client
|
|
//
|
|
// Created by Vincent Meilinger on 06.09.23.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SwiftData
|
|
|
|
struct MainView: View {
|
|
//@State var cookbookState: CookbookState = CookbookState()
|
|
@Environment(\.modelContext) var modelContext
|
|
@Query var recipes: [Recipe] = []
|
|
|
|
|
|
var body: some View {
|
|
VStack {
|
|
List {
|
|
ForEach(recipes) { recipe in
|
|
Text(recipe.name)
|
|
}
|
|
}
|
|
Button("New") {
|
|
let recipe = Recipe(id: UUID().uuidString, name: "Neues Rezept", keywords: [], prepTime: "", cookTime: "", totalTime: "", recipeDescription: "", yield: 0, category: "", tools: [], ingredients: [], instructions: [], nutrition: [:], ingredientMultiplier: 0)
|
|
modelContext.insert(recipe)
|
|
}
|
|
}
|
|
/*NavigationSplitView {
|
|
VStack {
|
|
List(selection: $cookbookState.selectedCategory) {
|
|
ForEach(cookbookState.categories) { category in
|
|
Text(category.name)
|
|
.tag(category)
|
|
}
|
|
}
|
|
.listStyle(.plain)
|
|
.onAppear {
|
|
Task {
|
|
await cookbookState.loadCategories()
|
|
}
|
|
}
|
|
}
|
|
} content: {
|
|
if let selectedCategory = cookbookState.selectedCategory {
|
|
List(selection: $cookbookState.selectedRecipeStub) {
|
|
ForEach(cookbookState.recipeStubs[selectedCategory.name] ?? [], id: \.id) { recipeStub in
|
|
Text(recipeStub.title)
|
|
.tag(recipeStub)
|
|
}
|
|
}
|
|
.onAppear {
|
|
Task {
|
|
await cookbookState.loadRecipeStubs(category: selectedCategory.name)
|
|
}
|
|
}
|
|
} else {
|
|
Text("Please select a category.")
|
|
.foregroundColor(.secondary)
|
|
}
|
|
} detail: {
|
|
if let selectedRecipe = cookbookState.selectedRecipe {
|
|
if let recipe = cookbookState.recipes[selectedRecipe.id] {
|
|
RecipeView(recipe: recipe)
|
|
} else {
|
|
ProgressView()
|
|
.onAppear {
|
|
Task {
|
|
await cookbookState.loadRecipe(id: selectedRecipe.id)
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
Text("Please select a recipe.")
|
|
.foregroundColor(.secondary)
|
|
}
|
|
}
|
|
.toolbar {
|
|
ToolbarItem(placement: .bottomBar) {
|
|
Button(action: {
|
|
cookbookState.showGroceries = true
|
|
}) {
|
|
Label("Grocery List", systemImage: "cart")
|
|
}
|
|
}
|
|
ToolbarItem(placement: .topBarLeading) {
|
|
Button(action: {
|
|
cookbookState.showSettings = true
|
|
}) {
|
|
Label("Settings", systemImage: "gearshape")
|
|
}
|
|
}
|
|
}*/
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/*struct CategoryListView: View {
|
|
@Bindable var cookbookState: CookbookState
|
|
|
|
var body: some View {
|
|
List(cookbookState.selectedAccountState.categories) { category in
|
|
NavigationLink {
|
|
RecipeListView(
|
|
cookbookState: cookbookState,
|
|
selectedCategory: category.name,
|
|
showEditView: .constant(false)
|
|
)
|
|
} label: {
|
|
HStack(alignment: .center) {
|
|
if cookbookState.selectedAccountState.selectedCategory != nil &&
|
|
category.name == cookbookState.selectedAccountState.selectedCategory?.name {
|
|
Image(systemName: "book")
|
|
} else {
|
|
Image(systemName: "book.closed.fill")
|
|
}
|
|
|
|
if category.name == "*" {
|
|
Text("Other")
|
|
.font(.system(size: 20, weight: .medium, design: .default))
|
|
} else {
|
|
Text(category.name)
|
|
.font(.system(size: 20, weight: .medium, design: .default))
|
|
}
|
|
|
|
Spacer()
|
|
Text("\(category.recipe_count)")
|
|
.font(.system(size: 15, weight: .bold, design: .default))
|
|
.foregroundStyle(Color.background)
|
|
.frame(width: 25, height: 25, alignment: .center)
|
|
.minimumScaleFactor(0.5)
|
|
.background {
|
|
Circle()
|
|
.foregroundStyle(Color.secondary)
|
|
}
|
|
}.padding(7)
|
|
|
|
}
|
|
}
|
|
}
|
|
}*/
|
|
/*struct CategoryListView: View {
|
|
@State var state: CookbookState
|
|
|
|
var body: some View {
|
|
List(selection: $state.categoryListSelection) {
|
|
ForEach(state.categories) { category in
|
|
NavigationLink(value: category) {
|
|
HStack(alignment: .center) {
|
|
if state.categoryListSelection != nil &&
|
|
category.name == state.categoryListSelection {
|
|
Image(systemName: "book")
|
|
} else {
|
|
Image(systemName: "book.closed.fill")
|
|
}
|
|
|
|
if category.name == "*" {
|
|
Text("Other")
|
|
.font(.system(size: 20, weight: .medium, design: .default))
|
|
} else {
|
|
Text(category.name)
|
|
.font(.system(size: 20, weight: .medium, design: .default))
|
|
}
|
|
|
|
Spacer()
|
|
Text("\(category.recipe_count)")
|
|
.font(.system(size: 15, weight: .bold, design: .default))
|
|
.foregroundStyle(Color.background)
|
|
.frame(width: 25, height: 25, alignment: .center)
|
|
.minimumScaleFactor(0.5)
|
|
.background {
|
|
Circle()
|
|
.foregroundStyle(Color.secondary)
|
|
}
|
|
}.padding(7)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}*/
|