Fixed dietary restrictions not immediately applying to menu

The vegetarian/vegan/no beef/no pork toggles will now immediately update the menu listing as intended.
This commit is contained in:
Campbell 2025-11-12 23:26:15 -05:00
parent 5895313488
commit 662fece439
Signed by: NinjaCheetah
GPG Key ID: 39C2500E1778B156
4 changed files with 30 additions and 9 deletions

View File

@ -265,7 +265,7 @@
CODE_SIGN_ENTITLEMENTS = "RIT Dining/RIT Dining.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = 5GF7GKNTK4;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
@ -300,7 +300,7 @@
CODE_SIGN_ENTITLEMENTS = "RIT Dining/RIT Dining.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = 5GF7GKNTK4;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;

View File

@ -9,8 +9,29 @@ import SwiftUI
class MenuDietaryRestrictionsModel: ObservableObject {
var dietaryRestrictions = DietaryRestrictions()
@AppStorage("isVegetarian") var isVegetarian: Bool = false
@AppStorage("isVegan") var isVegan: Bool = false
@AppStorage("noBeef") var noBeef: Bool = false
@AppStorage("noPork") var noPork: Bool = false
// I thought these could be @AppStorage keys but apparently not, because SwiftUI would subscribe to updates from those if
// they aren't being used directly inside the view.
@Published var isVegetarian: Bool {
didSet { UserDefaults.standard.set(isVegetarian, forKey: "isVegetarian") }
}
@Published var isVegan: Bool {
didSet { UserDefaults.standard.set(isVegan, forKey: "isVegan") }
}
@Published var noBeef: Bool {
didSet { UserDefaults.standard.set(noBeef, forKey: "noBeef") }
}
@Published var noPork: Bool {
didSet { UserDefaults.standard.set(noPork, forKey: "noPork") }
}
init() {
self.isVegetarian = UserDefaults.standard.bool(forKey: "isVegetarian")
self.isVegan = UserDefaults.standard.bool(forKey: "isVegan")
self.noBeef = UserDefaults.standard.bool(forKey: "noBeef")
self.noPork = UserDefaults.standard.bool(forKey: "noPork")
}
}

View File

@ -9,7 +9,7 @@ import SwiftUI
struct MenuDietaryRestrictionsSheet: View {
@Environment(\.dismiss) var dismiss
@Binding var dietaryRestrictionsModel: MenuDietaryRestrictionsModel
@ObservedObject var dietaryRestrictionsModel: MenuDietaryRestrictionsModel
var body: some View {
NavigationView {

View File

@ -17,7 +17,7 @@ struct MenuView: View {
@State private var rotationDegrees: Double = 0
@State private var selectedMealPeriod: Int = 0
@State private var openPeriods: [Int] = []
@State private var dietaryRestrictionsModel = MenuDietaryRestrictionsModel()
@StateObject private var dietaryRestrictionsModel = MenuDietaryRestrictionsModel()
@State private var showingDietaryRestrictionsSheet: Bool = false
private var animation: Animation {
@ -225,7 +225,7 @@ struct MenuView: View {
}
}
.sheet(isPresented: $showingDietaryRestrictionsSheet) {
MenuDietaryRestrictionsSheet(dietaryRestrictionsModel: $dietaryRestrictionsModel)
MenuDietaryRestrictionsSheet(dietaryRestrictionsModel: dietaryRestrictionsModel)
}
}
}