mirror of
https://github.com/NinjaCheetah/RIT-Dining.git
synced 2025-12-02 01:21:35 -05:00
There is now a filter button by the search bar in the menu view for locations! This opens a menu that allows you to filter by diets and to filter out any allergens that you need to avoid. These options are all written to UserDefaults, allowing you to set your options once and have them persist across menus and sessions. Also started on some refactors, these will be furthered in a later commit.
52 lines
1.1 KiB
Swift
52 lines
1.1 KiB
Swift
//
|
|
// DietaryRestrictions.swift
|
|
// RIT Dining
|
|
//
|
|
// Created by Campbell on 11/11/25.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
enum Allergen: String, Codable, CaseIterable {
|
|
case coconut
|
|
case egg
|
|
case gluten
|
|
case milk
|
|
case peanut
|
|
case sesame
|
|
case shellfish
|
|
case soy
|
|
case treenut
|
|
case wheat
|
|
}
|
|
|
|
@Observable
|
|
class DietaryRestrictions {
|
|
private var dietaryRestrictions: Set<String>
|
|
private let key = "DietaryRestrictions"
|
|
|
|
init() {
|
|
let favorites = UserDefaults.standard.array(forKey: key) as? [String] ?? [String]()
|
|
dietaryRestrictions = Set(favorites)
|
|
}
|
|
|
|
func contains(_ restriction: Allergen) -> Bool {
|
|
dietaryRestrictions.contains(restriction.rawValue)
|
|
}
|
|
|
|
func add(_ restriction: Allergen) {
|
|
dietaryRestrictions.insert(restriction.rawValue)
|
|
save()
|
|
}
|
|
|
|
func remove(_ restriction: Allergen) {
|
|
dietaryRestrictions.remove(restriction.rawValue)
|
|
save()
|
|
}
|
|
|
|
func save() {
|
|
let favorites = Array(dietaryRestrictions)
|
|
UserDefaults.standard.set(favorites, forKey: key)
|
|
}
|
|
}
|