Skip to content

Commit

Permalink
Merge pull request #248 from MikePlante1/pause_add_carbs
Browse files Browse the repository at this point in the history
Ensure meal is only saved once
  • Loading branch information
dnzxy authored Jun 1, 2024
2 parents 8de9979 + a20399e commit 14c7643
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ extension AddCarbs {
@StateObject var state = StateModel()
@State var dish: String = ""
@State var isPromtPresented = false
@State var saved = false
@State var noteSaved = false
@State var mealSaved = false
@State private var showAlert = false
@FocusState private var isFocused: Bool

Expand Down Expand Up @@ -117,9 +118,12 @@ extension AddCarbs {
}

Section {
Button { state.add() }
Button {
mealSaved = true
state.add()
}
label: { Text("Save and continue").font(.title3) }
.disabled(state.carbs <= 0 && state.fat <= 0 && state.protein <= 0)
.disabled(mealSaved || state.carbs <= 0 && state.fat <= 0 && state.protein <= 0)
.frame(maxWidth: .infinity, alignment: .center)
} footer: { Text(state.waitersNotepad().description) }

Expand All @@ -138,23 +142,23 @@ extension AddCarbs {
Section {
TextField("Name Of Dish", text: $dish)
Button {
saved = true
if dish != "", saved {
noteSaved = true
if dish != "", noteSaved {
let preset = Presets(context: moc)
preset.dish = dish
preset.fat = state.fat as NSDecimalNumber
preset.protein = state.protein as NSDecimalNumber
preset.carbs = state.carbs as NSDecimalNumber
try? moc.save()
state.addNewPresetToWaitersNotepad(dish)
saved = false
noteSaved = false
isPromtPresented = false
}
}
label: { Text("Save") }
Button {
dish = ""
saved = false
noteSaved = false
isPromtPresented = false }
label: { Text("Cancel") }
} header: { Text("Enter Meal Preset Name") }
Expand Down

0 comments on commit 14c7643

Please sign in to comment.