Bug fixes and UI polish
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// RecipeImportSection.swift
|
||||
// Nextcloud Cookbook iOS Client
|
||||
//
|
||||
// Created by Vincent Meilinger on 07.03.24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
|
||||
// MARK: - RecipeView Import Section
|
||||
|
||||
struct RecipeImportSection: View {
|
||||
@ObservedObject var viewModel: RecipeView.ViewModel
|
||||
var importRecipe: (String) async -> UserAlert?
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
SecondaryLabel(text: "Import Recipe")
|
||||
|
||||
Text(LocalizedStringKey("Paste the url of a recipe you would like to import in the above, and we will try to fill in the fields for you. This feature does not work with every website. If your favourite website is not supported, feel free to reach out for help. You can find the contact details in the app settings."))
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
|
||||
TextField(LocalizedStringKey("URL (e.g. example.com/recipe)"), text: $viewModel.importUrl)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.padding(.top, 5)
|
||||
Button {
|
||||
Task {
|
||||
if let res = await importRecipe(viewModel.importUrl) {
|
||||
viewModel.presentAlert(
|
||||
RecipeAlert.CUSTOM(
|
||||
title: res.localizedTitle,
|
||||
description: res.localizedDescription
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Text(LocalizedStringKey("Import"))
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
}
|
||||
.padding()
|
||||
.background(RoundedRectangle(cornerRadius: 20).foregroundStyle(Color.white.opacity(0.1)))
|
||||
.padding(5)
|
||||
.padding(.top, 5)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ struct RecipeIngredientSection: View {
|
||||
} else {
|
||||
Image(systemName: "heart.text.square")
|
||||
}
|
||||
}
|
||||
}.disabled(viewModel.editMode)
|
||||
}
|
||||
|
||||
ForEach(0..<viewModel.observableRecipeDetail.recipeIngredient.count, id: \.self) { ix in
|
||||
|
||||
@@ -70,17 +70,17 @@ struct RecipeMetadataSection: View {
|
||||
Button {
|
||||
presentServingsPopover.toggle()
|
||||
} label: {
|
||||
Text("\(viewModel.observableRecipeDetail.recipeYield) serving(s)")
|
||||
Text("\(viewModel.observableRecipeDetail.recipeYield) Serving(s)")
|
||||
.lineLimit(1)
|
||||
}
|
||||
.popover(isPresented: $presentServingsPopover) {
|
||||
PickerPopoverView(value: $viewModel.observableRecipeDetail.recipeYield, items: 0..<99, titleKey: "Servings")
|
||||
PickerPopoverView(isPresented: $presentServingsPopover, value: $viewModel.observableRecipeDetail.recipeYield, items: 0..<99, title: "Servings", titleKey: "Servings")
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.background(RoundedRectangle(cornerRadius: 20).foregroundStyle(Color.white.opacity(0.1)))
|
||||
.padding()
|
||||
.padding([.horizontal, .bottom], 5)
|
||||
.sheet(isPresented: $presentKeywordSheet) {
|
||||
KeywordPickerView(title: "Keywords", searchSuggestions: appState.allKeywords, selection: $viewModel.observableRecipeDetail.keywords)
|
||||
}
|
||||
@@ -88,20 +88,35 @@ struct RecipeMetadataSection: View {
|
||||
}
|
||||
|
||||
fileprivate struct PickerPopoverView<Item: Hashable & CustomStringConvertible, Collection: Sequence>: View where Collection.Element == Item {
|
||||
@Binding var isPresented: Bool
|
||||
@Binding var value: Item
|
||||
@State var items: Collection
|
||||
var title: LocalizedStringKey
|
||||
var titleKey: LocalizedStringKey = ""
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Picker(selection: $value, label: Text(titleKey)) {
|
||||
ForEach(Array(items), id: \.self) { item in
|
||||
Text(item.description).tag(item)
|
||||
VStack {
|
||||
HStack {
|
||||
SecondaryLabel(text: title)
|
||||
Spacer()
|
||||
Button {
|
||||
isPresented = false
|
||||
} label: {
|
||||
Text("Done")
|
||||
}
|
||||
}
|
||||
.pickerStyle(WheelPickerStyle())
|
||||
.frame(width: 150, height: 150)
|
||||
.clipped()
|
||||
Spacer()
|
||||
HStack {
|
||||
Picker(selection: $value, label: Text(titleKey)) {
|
||||
ForEach(Array(items), id: \.self) { item in
|
||||
Text(item.description).tag(item)
|
||||
}
|
||||
}
|
||||
.pickerStyle(WheelPickerStyle())
|
||||
.frame(width: 150, height: 150)
|
||||
.clipped()
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user