MainViewModel documentation and image caching improvements
This commit is contained in:
@@ -9,6 +9,7 @@ import SwiftUI
|
||||
|
||||
struct MainView: View {
|
||||
@StateObject var viewModel = MainViewModel()
|
||||
@StateObject var userSettings: UserSettings
|
||||
var columns: [GridItem] = [GridItem(.adaptive(minimum: 150), spacing: 0)]
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
@@ -29,7 +30,7 @@ struct MainView: View {
|
||||
}
|
||||
.navigationTitle("CookBook")
|
||||
.toolbar {
|
||||
NavigationLink( destination: SettingsView()) {
|
||||
NavigationLink( destination: SettingsView(userSettings: userSettings)) {
|
||||
Image(systemName: "gear")
|
||||
}
|
||||
}
|
||||
@@ -45,7 +46,7 @@ struct MainView: View {
|
||||
|
||||
struct MainView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MainView()
|
||||
MainView(userSettings: UserSettings())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,8 @@ struct LoginTextField: View {
|
||||
var body: some View {
|
||||
TextField(example, text: $text)
|
||||
.textFieldStyle(.plain)
|
||||
.textCase(.lowercase)
|
||||
.autocorrectionDisabled()
|
||||
.textInputAutocapitalization(.never)
|
||||
.foregroundColor(.white)
|
||||
.accentColor(.white)
|
||||
.padding()
|
||||
|
||||
@@ -16,7 +16,9 @@ struct RecipeCardView: View {
|
||||
HStack {
|
||||
Image(uiImage: recipeThumb ?? UIImage(named: "CookBook")!)
|
||||
.resizable()
|
||||
.frame(maxWidth: 80, maxHeight: 80)
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(width: 80, height: 80)
|
||||
.clipped()
|
||||
Text(recipe.name)
|
||||
.font(.headline)
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ struct RecipeDetailView: View {
|
||||
.frame(height: 300)
|
||||
.clipped()
|
||||
} else {
|
||||
Color.blue
|
||||
.frame(height: 300)
|
||||
Color("ncblue")
|
||||
.frame(height: 150)
|
||||
}
|
||||
|
||||
if let recipeDetail = recipeDetail {
|
||||
@@ -80,8 +80,7 @@ struct RecipeYieldSection: View {
|
||||
Text("Servings: \(recipeDetail.recipeYield)")
|
||||
Spacer()
|
||||
}.padding()
|
||||
.background(Color("accent"))
|
||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,14 @@ import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsView: View {
|
||||
@StateObject var userSettings = UserSettings()
|
||||
@ObservedObject var userSettings: UserSettings
|
||||
|
||||
var body: some View {
|
||||
ScrollView(showsIndicators: false) {
|
||||
LazyVStack {
|
||||
SettingsSection(headline: "Language", description: "Language settings coming soon.")
|
||||
SettingsSection(headline: "Accent Color", description: "The accent color setting will be released in a future update.")
|
||||
List {
|
||||
SettingsSection(title: "Language", description: "Language settings coming soon.")
|
||||
SettingsSection(title: "Accent Color", description: "The accent color setting will be released in a future update.")
|
||||
SettingsSection(title: "Log out", description: "Log out of your Nextcloud account in this app. Your recipes will be removed from local storage.")
|
||||
{
|
||||
Button("Log out") {
|
||||
print("Log out.")
|
||||
userSettings.serverAddress = ""
|
||||
@@ -26,7 +27,10 @@ struct SettingsView: View {
|
||||
.buttonStyle(.borderedProminent)
|
||||
.accentColor(.red)
|
||||
.padding()
|
||||
|
||||
}
|
||||
|
||||
SettingsSection(title: "Clear local data", description: "Your recipes will be removed from local storage.")
|
||||
{
|
||||
Button("Clear Cache") {
|
||||
print("Clear cache.")
|
||||
|
||||
@@ -35,21 +39,40 @@ struct SettingsView: View {
|
||||
.accentColor(.red)
|
||||
.padding()
|
||||
}
|
||||
|
||||
}.navigationTitle("Settings")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct SettingsSection: View {
|
||||
@State var headline: String
|
||||
@State var description: String
|
||||
struct SettingsSection<Content: View>: View {
|
||||
let title: String
|
||||
let description: String
|
||||
@ViewBuilder let content: () -> Content
|
||||
|
||||
init(title: String, description: String, content: @escaping () -> Content) {
|
||||
self.title = title
|
||||
self.description = description
|
||||
self.content = content
|
||||
}
|
||||
|
||||
init(title: String, description: String) where Content == EmptyView {
|
||||
self.title = title
|
||||
self.description = description
|
||||
self.content = { EmptyView() }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Text(headline)
|
||||
.font(.headline)
|
||||
Text(description)
|
||||
|
||||
Divider()
|
||||
}.padding()
|
||||
HStack {
|
||||
VStack(alignment: .leading) {
|
||||
Text(title)
|
||||
.font(.headline)
|
||||
Text(description)
|
||||
.font(.caption)
|
||||
}.padding()
|
||||
Spacer()
|
||||
content()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user