RIT-Dining/RIT Dining/Views/VisitingChefsPush.swift
NinjaCheetah dba5511ed5
Rewrote huge chunks of backend code to use a model
A model is now used to store all of the dining location information. This means that the data is now shared between all views, making it much easier to refresh and removing lots of excess API calls. dining-all is now called for the current day and the following 6 days on app launch and on refresh, but beyond that no additional API calls need to be made (excluding occupancy info). This means no more loading screens between views!
The window for hours in DetailView has been shifted to now show the current day and the next 6 days rather than the hours for each day in the current calendar week. This makes a lot more sense, because who cares what last Tuesday's hours were on Saturday, you'd rather know what's coming up in the next week.
The visiting chef screen now supports scrolling through 7 days of visiting chefs instead of just today and tomorrow.
Some basic frameworks laid for the visiting chef notification feature, however it does not work yet and is not exposed in the app.
Also fixed sorting and searching bugs introduced by changes in the previous commit.
2025-10-02 01:01:18 -04:00

79 lines
2.5 KiB
Swift

//
// VisitingChefsPush.swift
// RIT Dining
//
// Created by Campbell on 10/1/25.
//
import SwiftUI
struct VisitingChefPush: View {
@AppStorage("visitingChefPushEnabled") var pushEnabled: Bool = false
@Environment(NotifyingChefs.self) var notifyingChefs
@State private var pushAllowed: Bool = false
private let visitingChefs = [
"California Rollin' Sushi",
"D'Mangu",
"Esan's Kitchen",
"Halal n Out",
"just chik'n",
"KO-BQ",
"Macarollin'",
"P.H. Express",
"Tandoor of India"
]
var body: some View {
VStack {
Form {
Section(header: Text("Visiting Chef Notifications"),
footer: Text(!pushAllowed ? "You must allow notifications from RIT Dining to use this feature." : "")) {
Toggle(isOn: $pushEnabled) {
Text("Notifications Enabled")
}
.disabled(!pushAllowed)
}
Section(footer: Text("Get notified when a specific visiting chef is on campus and where they'll be.")) {
ForEach(visitingChefs, id: \.self) { chef in
Toggle(isOn: Binding(
get: {
notifyingChefs.contains(chef)
},
set: { isOn in
if isOn {
notifyingChefs.add(chef)
} else {
notifyingChefs.remove(chef)
}
}
)) {
Text(chef)
}
}
}
.disabled(!pushAllowed || !pushEnabled)
}
Spacer()
}
.onAppear {
Task {
let center = UNUserNotificationCenter.current()
do {
try await center.requestAuthorization(options: [.alert])
} catch {
print(error)
}
let settings = await center.notificationSettings()
guard (settings.authorizationStatus == .authorized) else { pushEnabled = false; return }
pushAllowed = true
}
}
.navigationTitle("Notifications")
.navigationBarTitleDisplayMode(.inline)
}
}
#Preview {
VisitingChefPush()
}