152 lines
5.3 KiB
Swift
152 lines
5.3 KiB
Swift
//
|
|
// ContentView.swift
|
|
// Nextcloud Cookbook iOS Client
|
|
//
|
|
// Created by Vincent Meilinger on 06.09.23.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SwiftData
|
|
|
|
struct MainView: View {
|
|
// Tab ViewModels
|
|
enum Tab {
|
|
case recipes, settings, groceryList
|
|
}
|
|
|
|
var body: some View {
|
|
TabView {
|
|
RecipeTabView()
|
|
.tabItem {
|
|
Label("Recipes", systemImage: "book.closed.fill")
|
|
}
|
|
.tag(Tab.recipes)
|
|
|
|
GroceryListTabView()
|
|
.tabItem {
|
|
if #available(iOS 17.0, *) {
|
|
Label("Grocery List", systemImage: "storefront")
|
|
} else {
|
|
Label("Grocery List", systemImage: "heart.text.square")
|
|
}
|
|
}
|
|
.tag(Tab.groceryList)
|
|
|
|
SettingsTabView()
|
|
.tabItem {
|
|
Label("Settings", systemImage: "gear")
|
|
}
|
|
.tag(Tab.settings)
|
|
|
|
}
|
|
.task {
|
|
/*
|
|
recipeViewModel.presentLoadingIndicator = true
|
|
await appState.getCategories()
|
|
await appState.updateAllRecipeDetails()
|
|
|
|
// Open detail view for default category
|
|
if UserSettings.shared.defaultCategory != "" {
|
|
if let cat = appState.categories.first(where: { c in
|
|
if c.name == UserSettings.shared.defaultCategory {
|
|
return true
|
|
}
|
|
return false
|
|
}) {
|
|
recipeViewModel.selectedCategory = cat
|
|
}
|
|
}
|
|
await groceryList.load()
|
|
recipeViewModel.presentLoadingIndicator = false
|
|
*/
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/*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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}*/
|