Added dining location menus from FD MealPlanner API

Dining locations that also exist on FD MealPlanner now have a "View Menu" button under the favorite/OnDemand/map buttons that take you to a new view that pulls the location's menu from FD MealPlanner. You can view all of the menu items that have actually been added to that site, and tap them for more details (which will be expanded on later). Searching the item list is supported, with more filtering options coming in the next update. Meal periods can be browsed using the clock button in the top right for locations that are open more than once per day.
Other changes:
- App renamed from "RIT Dining" to "TigerDine" to not get me in trouble for an App Store release
- Slightly changed the way that dining locations' short descriptions and current open times are displayed in the detail view
- Fixed the box truck icon used in the food truck view being squished
This commit is contained in:
2025-11-08 22:33:20 -05:00
parent 2c512180d9
commit c7639de06b
17 changed files with 785 additions and 198 deletions

View File

@@ -18,8 +18,10 @@ struct AboutView: View {
.resizable()
.frame(width: 128, height: 128)
.clipShape(RoundedRectangle(cornerRadius: 20))
Text("An RIT Dining App")
Text("TigerDine")
.font(.title)
Text("An unofficial RIT Dining app")
.font(.subheadline)
Text("Version \(appVersionString) (\(buildNumber))")
.foregroundStyle(.secondary)
VStack(alignment: .leading, spacing: 10) {

View File

@@ -14,7 +14,6 @@ struct DetailView: View {
@Environment(DiningModel.self) var model
@Environment(\.openURL) private var openURL
@State private var showingSafari: Bool = false
@State private var openString: String = ""
@State private var occupancyLoading: Bool = true
@State private var occupancyPercentage: Double = 0.0
@@ -80,98 +79,108 @@ struct DetailView: View {
ScrollView {
VStack(alignment: .leading) {
HStack(alignment: .center) {
Text(location.name)
.font(.title)
.fontWeight(.bold)
Spacer()
Button(action: {
if favorites.contains(location) {
favorites.remove(location)
} else {
favorites.add(location)
}
}) {
if favorites.contains(location) {
Image(systemName: "star.fill")
.foregroundStyle(.yellow)
.font(.title3)
} else {
Image(systemName: "star")
.foregroundStyle(.yellow)
.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)
Button(action: {
showingSafari = true
}) {
Image(systemName: "map")
.font(.title3)
}
}
Text(location.summary)
.font(.title2)
.foregroundStyle(.secondary)
HStack(alignment: .top, spacing: 3) {
switch location.open {
case .open:
Text("Open")
.foregroundStyle(.green)
case .closed:
Text("Closed")
.foregroundStyle(.red)
case .openingSoon:
Text("Opening Soon")
.foregroundStyle(.orange)
case .closingSoon:
Text("Closing Soon")
.foregroundStyle(.orange)
}
Text("")
.foregroundStyle(.secondary)
VStack {
if let times = location.diningTimes, !times.isEmpty {
Text(openString)
.foregroundStyle(.secondary)
.onAppear {
openString = ""
for time in times {
openString += "\(dateDisplay.string(from: time.openTime)) - \(dateDisplay.string(from: time.closeTime)), "
}
openString = String(openString.prefix(openString.count - 2))
VStack(alignment: .leading) {
Text(location.name)
.font(.title)
.fontWeight(.bold)
Text(location.summary)
.font(.title2)
.fontWeight(.semibold)
.foregroundStyle(.secondary)
VStack(alignment: .leading) {
switch location.open {
case .open:
Text("Open")
.font(.title3)
.foregroundStyle(.green)
case .closed:
Text("Closed")
.font(.title3)
.foregroundStyle(.red)
case .openingSoon:
Text("Opening Soon")
.font(.title3)
.foregroundStyle(.orange)
case .closingSoon:
Text("Closing Soon")
.font(.title3)
.foregroundStyle(.orange)
}
if let times = location.diningTimes, !times.isEmpty {
ForEach(times, id: \.self) { time in
Text("\(dateDisplay.string(from: time.openTime)) - \(dateDisplay.string(from: time.closeTime))")
.foregroundStyle(.secondary)
}
} else {
Text("Not Open Today")
.foregroundStyle(.secondary)
} else {
Text("Not Open Today")
.foregroundStyle(.secondary)
}
}
HStack(spacing: 0) {
ForEach(Range(1...5), id: \.self) { index in
if occupancyPercentage > (20 * Double(index)) {
Image(systemName: "person.fill")
} else {
Image(systemName: "person")
}
}
ProgressView()
.progressViewStyle(.circular)
.frame(width: 18, height: 18)
.opacity(occupancyLoading ? 1 : 0)
.task {
await getOccupancy()
}
}
.foregroundStyle(Color.accent.opacity(occupancyLoading ? 0.5 : 1.0))
.font(.title3)
}
Spacer()
VStack(alignment: .trailing) {
HStack(alignment: .center) {
// Favorites toggle button.
Button(action: {
if favorites.contains(location) {
favorites.remove(location)
} else {
favorites.add(location)
}
}) {
if favorites.contains(location) {
Image(systemName: "star.fill")
.foregroundStyle(.yellow)
.font(.title3)
} else {
Image(systemName: "star")
.foregroundStyle(.yellow)
.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)
// Open this location on the RIT map in embedded Safari.
Button(action: {
showingSafari = true
}) {
Image(systemName: "map")
.font(.title3)
}
}
if let fdmpIds = location.fdmpIds {
NavigationLink(destination: MenuView(accountId: fdmpIds.accountId, locationId: fdmpIds.locationId)) {
Text("View Menu")
}
.padding(.top, 5)
}
Spacer()
}
}
HStack(spacing: 0) {
ForEach(Range(1...5), id: \.self) { index in
if occupancyPercentage > (20 * Double(index)) {
Image(systemName: "person.fill")
} else {
Image(systemName: "person")
}
}
ProgressView()
.progressViewStyle(.circular)
.frame(width: 18, height: 18)
.opacity(occupancyLoading ? 1 : 0)
.task {
await getOccupancy()
}
}
.foregroundStyle(Color.accent.opacity(occupancyLoading ? 0.5 : 1.0))
.font(.title3)
.padding(.bottom, 12)
if let visitingChefs = location.visitingChefs, !visitingChefs.isEmpty {
VStack(alignment: .leading) {

View File

@@ -46,6 +46,7 @@ struct FoodTruckView: View {
} else {
Image(systemName: "truck.box")
.resizable()
.scaledToFit()
.frame(width: 75, height: 75)
.foregroundStyle(.accent)
.rotationEffect(.degrees(rotationDegrees))

View File

@@ -0,0 +1,97 @@
//
// MenuItemView.swift
// RIT Dining
//
// Created by Campbell on 11/6/25.
//
import SwiftUI
struct MenuItemView: View {
@State var menuItem: FDMenuItem
private var infoString: String {
// Calories SHOULD always be available, so start there.
var str = "\(menuItem.calories) Cal • "
// Price might be $0.00, so don't display it if that's the case because that's obviously wrong. RIT Dining would never give
// us free food!
if menuItem.price == 0.0 {
str += "Price Unavailable"
} else {
str += "$\(String(format: "%.2f", menuItem.price))"
}
// Same with the price, the serving size might be 0 which is also wrong so don't display that.
if menuItem.servingSize != 0 {
str += "\(menuItem.servingSize) \(menuItem.servingSizeUnit)"
}
return str
}
var body: some View {
ScrollView {
VStack(alignment: .leading) {
Text(menuItem.name)
.font(.title)
.fontWeight(.bold)
Text(menuItem.category)
.font(.title2)
.fontWeight(.semibold)
.foregroundStyle(.secondary)
Text(infoString)
.font(.title3)
.foregroundStyle(.secondary)
HStack {
ForEach(menuItem.dietaryMarkers, id: \.self) { dietaryMarker in
Text(dietaryMarker)
.foregroundStyle(Color.white)
.font(.caption)
.padding(5)
.background(
RoundedRectangle(cornerRadius: 16)
.fill({
switch dietaryMarker {
case "Vegan", "Vegetarian":
return Color.green
default:
return Color.orange
}
}())
)
}
}
Text("Allergens")
.font(.headline)
.padding(.top, 8)
Text(menuItem.allergens.joined(separator: ", "))
.foregroundStyle(.secondary)
.textSelection(.enabled)
.padding(.bottom, 8)
Text("Ingredients")
.font(.headline)
Text(menuItem.ingredients)
.foregroundStyle(.secondary)
.textSelection(.enabled)
}
.padding(.horizontal, 8)
}
.navigationTitle("Details")
.navigationBarTitleDisplayMode(.inline)
}
}
#Preview {
MenuItemView(
menuItem: FDMenuItem(
id: 0,
name: "Chocolate Chip Muffin",
exactName: "Muffin Chocolate Chip Thaw and Serve A; Case; 72 Ounce; 12",
category: "Baked Goods",
allergens: ["Wheat", "Gluten", "Egg", "Milk", "Soy"],
calories: 470,
dietaryMarkers: ["Vegetarian"],
ingredients: "Some ingredients that you'd expect to find inside of a chocolate chip muffin",
price: 2.79,
servingSize: 1,
servingSizeUnit: "Each")
)
}

View File

@@ -0,0 +1,178 @@
//
// MenuView.swift
// RIT Dining
//
// Created by Campbell on 11/3/25.
//
import SwiftUI
struct MenuView: View {
@State var accountId: Int
@State var locationId: Int
@State private var menuItems: [FDMenuItem] = []
@State private var searchText: String = ""
@State private var isLoading: Bool = true
@State private var loadFailed: Bool = false
@State private var rotationDegrees: Double = 0
@State private var selectedMealPeriod: Int = 0
@State private var openPeriods: [Int] = []
private var animation: Animation {
.linear
.speed(0.1)
.repeatForever(autoreverses: false)
}
func getOpenPeriods() async {
// Only run this if we haven't already gotten the open periods. This is somewhat of a bandaid solution to the issue of
// fetching this information more than once, but hey it works!
if openPeriods.isEmpty {
switch await getFDMealPlannerOpenings(locationId: locationId) {
case .success(let openingResults):
openPeriods = openingResults.data.map { Int($0.id) }
selectedMealPeriod = openPeriods[0]
// Since this only runs once when the view first loads, we can safely use this to call the method to get the data
// the first time. This also ensures that it doesn't happen until we have the opening periods collected.
await getMenuForPeriod(mealPeriodId: selectedMealPeriod)
case .failure(let error):
print(error)
loadFailed = true
}
}
}
func getMenuForPeriod(mealPeriodId: Int) async {
switch await getFDMealPlannerMenu(locationId: locationId, accountId: accountId, mealPeriodId: mealPeriodId) {
case .success(let menus):
menuItems = parseFDMealPlannerMenu(menu: menus)
isLoading = false
case .failure(let error):
print(error)
loadFailed = true
}
}
func getPriceString(price: Double) -> String {
if price == 0.0 {
return "Price Unavailable"
} else {
return "$\(String(format: "%.2f", price))"
}
}
private var filteredMenuItems: [FDMenuItem] {
var newItems = menuItems
newItems = newItems.filter { item in
let searchedLocations = searchText.isEmpty || item.name.localizedCaseInsensitiveContains(searchText)
return searchedLocations
}
return newItems
}
var body: some View {
if isLoading {
VStack {
if loadFailed {
Image(systemName: "wifi.exclamationmark.circle")
.resizable()
.frame(width: 75, height: 75)
.foregroundStyle(.accent)
Text("An error occurred while fetching the menu. Please check your network connection and try again.")
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
} else {
Image(systemName: "fork.knife.circle")
.resizable()
.frame(width: 75, height: 75)
.foregroundStyle(.accent)
.rotationEffect(.degrees(rotationDegrees))
.onAppear {
withAnimation(animation) {
rotationDegrees = 360.0
}
}
Text("One moment...")
.foregroundStyle(.secondary)
}
}
.task {
await getOpenPeriods()
}
.padding()
} else {
VStack {
if !menuItems.isEmpty {
List {
Section {
ForEach(filteredMenuItems) { item in
NavigationLink(destination: MenuItemView(menuItem: item)) {
VStack(alignment: .leading) {
HStack {
Text(item.name)
ForEach(item.dietaryMarkers, id: \.self) { dietaryMarker in
Text(dietaryMarker)
.foregroundStyle(Color.white)
.font(.caption)
.padding(5)
.background(
RoundedRectangle(cornerRadius: 16)
.fill({
switch dietaryMarker {
case "Vegan", "Vegetarian":
return Color.green
default:
return Color.orange
}
}())
)
}
}
Text("\(item.calories) Cal • \(getPriceString(price: item.price))")
.foregroundStyle(.secondary)
}
}
}
}
}
.navigationTitle("Menu")
.navigationBarTitleDisplayMode(.large)
.searchable(text: $searchText, prompt: "Search")
} else {
Image(systemName: "clock.badge.exclamationmark")
.resizable()
.scaledToFit()
.frame(width: 75, height: 75)
.foregroundStyle(.accent)
Text("No menu is available for the selected meal period today. Try selecting a different meal period.")
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
}
}
.toolbar {
ToolbarItem(placement: .primaryAction) {
Menu {
Picker("Meal Period", selection: $selectedMealPeriod) {
ForEach(openPeriods, id: \.self) { period in
Text(fdmpMealPeriodsMap[period]!).tag(period)
}
}
} label: {
Image(systemName: "clock")
}
}
}
.onChange(of: selectedMealPeriod) {
rotationDegrees = 0
isLoading = true
Task {
await getMenuForPeriod(mealPeriodId: selectedMealPeriod)
}
}
}
}
}
#Preview {
MenuView(accountId: 1, locationId: 1)
}