mirror of
https://github.com/NinjaCheetah/RIT-Dining.git
synced 2026-03-05 13:35:29 -05:00
Added notifications for visiting chefs
You can now get notified when visiting chefs are on campus! A menu is available from the toolbar on the main screen that allows you to enable notifications and configure what visiting chefs you want to be notified for. You can also toggle if you want to be notified 1, 2, or 3 hours before the chef arrives on campus. Other changes in this commit: - Updated maps URL to be compatible with the new RIT map (however they don't open correctly- this is outside of my control) - Removed button linking to OnDemand at the request of RIT ITS
This commit is contained in:
@@ -116,6 +116,7 @@ struct DetailView: View {
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
HStack(spacing: 0) {
|
||||
ForEach(Range(1...5), id: \.self) { index in
|
||||
if occupancyPercentage > (20 * Double(index)) {
|
||||
@@ -134,6 +135,7 @@ struct DetailView: View {
|
||||
}
|
||||
.foregroundStyle(Color.accent.opacity(occupancyLoading ? 0.5 : 1.0))
|
||||
.font(.title3)
|
||||
#endif
|
||||
}
|
||||
Spacer()
|
||||
VStack(alignment: .trailing) {
|
||||
@@ -156,14 +158,16 @@ struct DetailView: View {
|
||||
.font(.title3)
|
||||
}
|
||||
}
|
||||
// Open OnDemand. Unfortunately the locations use arbitrary IDs, so just open the main OnDemand page.
|
||||
Button(action: {
|
||||
openURL(URL(string: "https://ondemand.rit.edu")!)
|
||||
}) {
|
||||
Image(systemName: "cart")
|
||||
.font(.title3)
|
||||
}
|
||||
.disabled(location.open == .closed || location.open == .openingSoon)
|
||||
// THIS FEATURE DISABLED AT RIT'S REQUEST FOR SECURITY REASONS.
|
||||
// No hard feelings or anything though, I get it.
|
||||
// // Open OnDemand. Unfortunately the locations use arbitrary IDs, so just open the main OnDemand page.
|
||||
// Button(action: {
|
||||
// openURL(URL(string: "https://ondemand.rit.edu")!)
|
||||
// }) {
|
||||
// Image(systemName: "cart")
|
||||
// .font(.title3)
|
||||
// }
|
||||
// .disabled(location.open == .closed || location.open == .openingSoon)
|
||||
// Open this location on the RIT map in embedded Safari.
|
||||
Button(action: {
|
||||
showingSafari = true
|
||||
|
||||
@@ -200,6 +200,7 @@ struct MenuView: View {
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "clock")
|
||||
Text("Meal Periods")
|
||||
}
|
||||
}
|
||||
ToolbarItemGroup(placement: .bottomBar) {
|
||||
|
||||
@@ -9,7 +9,8 @@ import SwiftUI
|
||||
|
||||
struct VisitingChefPush: View {
|
||||
@AppStorage("visitingChefPushEnabled") var pushEnabled: Bool = false
|
||||
@Environment(NotifyingChefs.self) var notifyingChefs
|
||||
@AppStorage("notificationOffset") var notificationOffset: Int = 2
|
||||
@Environment(DiningModel.self) var model
|
||||
@State private var pushAllowed: Bool = false
|
||||
private let visitingChefs = [
|
||||
"California Rollin' Sushi",
|
||||
@@ -32,18 +33,39 @@ struct VisitingChefPush: View {
|
||||
Text("Notifications Enabled")
|
||||
}
|
||||
.disabled(!pushAllowed)
|
||||
.onChange(of: pushEnabled) {
|
||||
if pushEnabled {
|
||||
Task {
|
||||
await model.scheduleAllPushes()
|
||||
}
|
||||
} else {
|
||||
Task {
|
||||
await model.cancelAllPushes()
|
||||
}
|
||||
}
|
||||
}
|
||||
Picker("Send Notifications", selection: $notificationOffset) {
|
||||
Text("1 Hour Before").tag(1)
|
||||
Text("2 Hours Before").tag(2)
|
||||
Text("3 Hours Before").tag(3)
|
||||
}
|
||||
.disabled(!pushAllowed || !pushEnabled)
|
||||
}
|
||||
Section(footer: Text("Get notified when a specific visiting chef is on campus and where they'll be.")) {
|
||||
Section(footer: Text("Get notified when and where a specific visiting chef will be on campus.")) {
|
||||
ForEach(visitingChefs, id: \.self) { chef in
|
||||
Toggle(isOn: Binding(
|
||||
get: {
|
||||
notifyingChefs.contains(chef)
|
||||
model.notifyingChefs.contains(chef)
|
||||
},
|
||||
set: { isOn in
|
||||
if isOn {
|
||||
notifyingChefs.add(chef)
|
||||
model.notifyingChefs.add(chef)
|
||||
Task {
|
||||
await model.schedulePushesForChef(chef)
|
||||
}
|
||||
} else {
|
||||
notifyingChefs.remove(chef)
|
||||
model.notifyingChefs.remove(chef)
|
||||
model.visitingChefPushes.cancelPushesForChef(name: chef)
|
||||
}
|
||||
}
|
||||
)) {
|
||||
@@ -52,8 +74,49 @@ struct VisitingChefPush: View {
|
||||
}
|
||||
}
|
||||
.disabled(!pushAllowed || !pushEnabled)
|
||||
#if DEBUG
|
||||
Section(header: Text("DEBUG - Scheduled Pushes")) {
|
||||
Button(action: {
|
||||
Task {
|
||||
await model.scheduleAllPushes()
|
||||
}
|
||||
}) {
|
||||
Text("Schedule All")
|
||||
}
|
||||
Button(action: {
|
||||
let uuids = model.visitingChefPushes.pushes.map(\.uuid)
|
||||
Task {
|
||||
await cancelVisitingChefNotifs(uuids: uuids)
|
||||
model.visitingChefPushes.pushes.removeAll()
|
||||
}
|
||||
}) {
|
||||
Text("Cancel All")
|
||||
}
|
||||
.tint(.red)
|
||||
ForEach(model.visitingChefPushes.pushes, id: \.uuid) { push in
|
||||
VStack(alignment: .leading) {
|
||||
Text("\(push.name) at \(push.location)")
|
||||
Text(push.uuid)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
Text("\(push.startTime) - \(push.endTime)")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.swipeActions {
|
||||
Button(action: {
|
||||
Task {
|
||||
await cancelVisitingChefNotifs(uuids: [push.uuid])
|
||||
model.visitingChefPushes.pushes.remove(at: model.visitingChefPushes.pushes.firstIndex(of: push)!)
|
||||
}
|
||||
}) {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
.tint(.red)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.onAppear {
|
||||
Task {
|
||||
|
||||
Reference in New Issue
Block a user