Redesign recipe creation and edit view with Form-based layout and URL import
Replace the single "+" button with a 2-option menu (Create New Recipe / Import from URL) across RecipeTabView, RecipeListView, and AllRecipesListView. Add ImportURLSheet for server-side recipe import with loading and error states. Completely redesign edit mode to use a native Form layout with inline editing for all sections (metadata, duration, ingredients, instructions, tools, nutrition) instead of the previous sheet-based EditableListView approach. Move delete action from edit toolbar to view mode context menu. Add recipe image display to the edit form. Refactor RecipeListView and AllRecipesListView to use closure-based callbacks instead of Binding<Bool> for the create/import actions. Add preloadedRecipeDetail support to RecipeView.ViewModel for imported recipes. Add DE/ES/FR translations for all new UI strings. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,23 +21,70 @@ struct RecipeDurationSection: View {
|
||||
DurationView(time: viewModel.observableRecipeDetail.cookTime, title: LocalizedStringKey("Cooking"))
|
||||
DurationView(time: viewModel.observableRecipeDetail.totalTime, title: LocalizedStringKey("Total time"))
|
||||
}
|
||||
if viewModel.editMode {
|
||||
Button {
|
||||
presentPopover.toggle()
|
||||
} label: {
|
||||
Text("Edit")
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.padding(.top, 5)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.popover(isPresented: $presentPopover) {
|
||||
EditableDurationView(
|
||||
prepTime: viewModel.observableRecipeDetail.prepTime,
|
||||
cookTime: viewModel.observableRecipeDetail.cookTime,
|
||||
totalTime: viewModel.observableRecipeDetail.totalTime
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Recipe Edit Duration Section (Form-based)
|
||||
|
||||
struct RecipeEditDurationSection: View {
|
||||
@ObservedObject var prepTime: DurationComponents
|
||||
@ObservedObject var cookTime: DurationComponents
|
||||
@ObservedObject var totalTime: DurationComponents
|
||||
|
||||
var body: some View {
|
||||
Section("Duration") {
|
||||
DurationPickerRow(label: "Preparation", time: prepTime)
|
||||
DurationPickerRow(label: "Cooking", time: cookTime)
|
||||
DurationPickerRow(label: "Total time", time: totalTime)
|
||||
}
|
||||
.onChange(of: prepTime.hourComponent) { _ in updateTotalTime() }
|
||||
.onChange(of: prepTime.minuteComponent) { _ in updateTotalTime() }
|
||||
.onChange(of: cookTime.hourComponent) { _ in updateTotalTime() }
|
||||
.onChange(of: cookTime.minuteComponent) { _ in updateTotalTime() }
|
||||
}
|
||||
|
||||
private func updateTotalTime() {
|
||||
var hourComponent = prepTime.hourComponent + cookTime.hourComponent
|
||||
var minuteComponent = prepTime.minuteComponent + cookTime.minuteComponent
|
||||
if minuteComponent >= 60 {
|
||||
hourComponent += minuteComponent / 60
|
||||
minuteComponent %= 60
|
||||
}
|
||||
totalTime.hourComponent = hourComponent
|
||||
totalTime.minuteComponent = minuteComponent
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate struct DurationPickerRow: View {
|
||||
let label: LocalizedStringKey
|
||||
@ObservedObject var time: DurationComponents
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Text(label)
|
||||
Spacer()
|
||||
Menu {
|
||||
ForEach(0..<25, id: \.self) { hour in
|
||||
Button("\(hour) h") {
|
||||
time.hourComponent = hour
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Text("\(time.hourComponent) h")
|
||||
.monospacedDigit()
|
||||
}
|
||||
Menu {
|
||||
ForEach(0..<60, id: \.self) { minute in
|
||||
Button("\(minute) min") {
|
||||
time.minuteComponent = minute
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Text("\(time.minuteComponent) min")
|
||||
.monospacedDigit()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,20 +69,44 @@ struct RecipeIngredientSection: View {
|
||||
}.padding(.top)
|
||||
}
|
||||
|
||||
if viewModel.editMode {
|
||||
Button {
|
||||
viewModel.presentIngredientEditView.toggle()
|
||||
} label: {
|
||||
Text("Edit")
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.animation(.easeInOut, value: viewModel.observableRecipeDetail.ingredientMultiplier)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Recipe Edit Ingredient Section (Form-based)
|
||||
|
||||
struct RecipeEditIngredientSection: View {
|
||||
@Binding var ingredients: [String]
|
||||
|
||||
var body: some View {
|
||||
Section {
|
||||
ForEach(ingredients.indices, id: \.self) { index in
|
||||
HStack {
|
||||
TextField("Ingredient", text: $ingredients[index])
|
||||
Image(systemName: "line.3.horizontal")
|
||||
.foregroundStyle(.tertiary)
|
||||
}
|
||||
}
|
||||
.onDelete { indexSet in
|
||||
ingredients.remove(atOffsets: indexSet)
|
||||
}
|
||||
.onMove { from, to in
|
||||
ingredients.move(fromOffsets: from, toOffset: to)
|
||||
}
|
||||
|
||||
Button {
|
||||
ingredients.append("")
|
||||
} label: {
|
||||
Label("Add Ingredient", systemImage: "plus.circle.fill")
|
||||
}
|
||||
} header: {
|
||||
Text("Ingredients")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - RecipeIngredientSection List Item
|
||||
|
||||
fileprivate struct IngredientListItem: View {
|
||||
|
||||
@@ -22,14 +22,6 @@ struct RecipeInstructionSection: View {
|
||||
ForEach(viewModel.observableRecipeDetail.recipeInstructions.indices, id: \.self) { ix in
|
||||
RecipeInstructionListItem(instruction: $viewModel.observableRecipeDetail.recipeInstructions[ix], index: ix+1)
|
||||
}
|
||||
if viewModel.editMode {
|
||||
Button {
|
||||
viewModel.presentInstructionEditView.toggle()
|
||||
} label: {
|
||||
Text("Edit")
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
|
||||
@@ -37,6 +29,44 @@ struct RecipeInstructionSection: View {
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Recipe Edit Instruction Section (Form-based)
|
||||
|
||||
struct RecipeEditInstructionSection: View {
|
||||
@Binding var instructions: [String]
|
||||
|
||||
var body: some View {
|
||||
Section {
|
||||
ForEach(instructions.indices, id: \.self) { index in
|
||||
HStack(alignment: .top) {
|
||||
Text("\(index + 1).")
|
||||
.foregroundStyle(.secondary)
|
||||
.monospacedDigit()
|
||||
TextField("Step \(index + 1)", text: $instructions[index], axis: .vertical)
|
||||
.lineLimit(1...10)
|
||||
Image(systemName: "line.3.horizontal")
|
||||
.foregroundStyle(.tertiary)
|
||||
.padding(.top, 4)
|
||||
}
|
||||
}
|
||||
.onDelete { indexSet in
|
||||
instructions.remove(atOffsets: indexSet)
|
||||
}
|
||||
.onMove { from, to in
|
||||
instructions.move(fromOffsets: from, toOffset: to)
|
||||
}
|
||||
|
||||
Button {
|
||||
instructions.append("")
|
||||
} label: {
|
||||
Label("Add Step", systemImage: "plus.circle.fill")
|
||||
}
|
||||
} header: {
|
||||
Text("Instructions")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fileprivate struct RecipeInstructionListItem: View {
|
||||
@Binding var instruction: String
|
||||
|
||||
@@ -87,6 +87,52 @@ struct RecipeMetadataSection: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Recipe Edit Metadata Section (Form-based)
|
||||
|
||||
struct RecipeEditMetadataSection: View {
|
||||
@EnvironmentObject var appState: AppState
|
||||
@ObservedObject var viewModel: RecipeView.ViewModel
|
||||
|
||||
var categories: [String] {
|
||||
appState.categories.map { $0.name }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Section("Details") {
|
||||
Picker("Category", selection: $viewModel.observableRecipeDetail.recipeCategory) {
|
||||
Text("None").tag("")
|
||||
ForEach(categories, id: \.self) { item in
|
||||
Text(item).tag(item)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.menu)
|
||||
|
||||
Stepper("Servings: \(viewModel.observableRecipeDetail.recipeYield)", value: $viewModel.observableRecipeDetail.recipeYield, in: 1...99)
|
||||
|
||||
Button {
|
||||
viewModel.presentKeywordSheet = true
|
||||
} label: {
|
||||
HStack {
|
||||
Text("Keywords")
|
||||
.foregroundStyle(.primary)
|
||||
Spacer()
|
||||
if viewModel.observableRecipeDetail.keywords.isEmpty {
|
||||
Text("None")
|
||||
.foregroundStyle(.secondary)
|
||||
} else {
|
||||
Text(viewModel.observableRecipeDetail.keywords.joined(separator: ", "))
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
}
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate struct PickerPopoverView<Item: Hashable & CustomStringConvertible, Collection: Sequence>: View where Collection.Element == Item {
|
||||
@Binding var isPresented: Bool
|
||||
@Binding var value: Item
|
||||
|
||||
@@ -63,10 +63,42 @@ struct RecipeNutritionSection: View {
|
||||
|
||||
func nutritionEmpty() -> Bool {
|
||||
for nutrition in Nutrition.allCases {
|
||||
if let value = viewModel.observableRecipeDetail.nutrition[nutrition.dictKey] {
|
||||
if let _ = viewModel.observableRecipeDetail.nutrition[nutrition.dictKey] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Recipe Edit Nutrition Section (Form-based)
|
||||
|
||||
struct RecipeEditNutritionSection: View {
|
||||
@Binding var nutrition: [String: String]
|
||||
|
||||
@State private var isExpanded: Bool = false
|
||||
|
||||
var body: some View {
|
||||
Section {
|
||||
DisclosureGroup("Nutrition Information", isExpanded: $isExpanded) {
|
||||
ForEach(Nutrition.allCases, id: \.self) { item in
|
||||
HStack {
|
||||
Text(item.localizedDescription)
|
||||
.lineLimit(1)
|
||||
Spacer()
|
||||
TextField("", text: nutritionBinding(for: item.dictKey))
|
||||
.multilineTextAlignment(.trailing)
|
||||
.frame(maxWidth: 150)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func nutritionBinding(for key: String) -> Binding<String> {
|
||||
Binding(
|
||||
get: { nutrition[key, default: ""] },
|
||||
set: { nutrition[key] = $0 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,40 @@ struct RecipeToolSection: View {
|
||||
}
|
||||
|
||||
RecipeListSection(list: $viewModel.observableRecipeDetail.tool)
|
||||
|
||||
if viewModel.editMode {
|
||||
Button {
|
||||
viewModel.presentToolEditView.toggle()
|
||||
} label: {
|
||||
Text("Edit")
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
}
|
||||
}.padding()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Recipe Edit Tool Section (Form-based)
|
||||
|
||||
struct RecipeEditToolSection: View {
|
||||
@Binding var tools: [String]
|
||||
|
||||
var body: some View {
|
||||
Section {
|
||||
ForEach(tools.indices, id: \.self) { index in
|
||||
HStack {
|
||||
TextField("Tool", text: $tools[index])
|
||||
Image(systemName: "line.3.horizontal")
|
||||
.foregroundStyle(.tertiary)
|
||||
}
|
||||
}
|
||||
.onDelete { indexSet in
|
||||
tools.remove(atOffsets: indexSet)
|
||||
}
|
||||
.onMove { from, to in
|
||||
tools.move(fromOffsets: from, toOffset: to)
|
||||
}
|
||||
|
||||
Button {
|
||||
tools.append("")
|
||||
} label: {
|
||||
Label("Add Tool", systemImage: "plus.circle.fill")
|
||||
}
|
||||
} header: {
|
||||
Text("Tools")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user