Files
RIT-Dining/TigerDine/Views/FoodTruckView.swift
NinjaCheetah 42b3c35f68 Added deep links for widgets
- Widgets will now open the appropriate DetailView in the app when you tap on them.
  - ...except when they don't. This is still a little buggy. It works correctly when the app is already alive in the background but only works about 75% of the time when the app isn't running yet.
- Unified the loading view into a shared view used in all places requiring loading
2026-01-24 15:11:45 -05:00

75 lines
2.6 KiB
Swift

//
// FoodTruckView.swift
// TigerDine
//
// Created by Campbell on 10/5/25.
//
import SwiftUI
import SafariServices
struct FoodTruckView: View {
@State private var foodTruckEvents: [FoodTruckEvent] = []
@State private var isLoading: Bool = true
@State private var loadFailed: Bool = false
@State private var showingSafari: Bool = false
private func doFoodTruckStuff() async {
switch await getFoodTruckPage() {
case .success(let schedule):
foodTruckEvents = parseWeekendFoodTrucks(htmlString: schedule)
isLoading = false
case .failure(let error):
print(error)
loadFailed = true
}
}
var body: some View {
if isLoading {
VStack {
LoadingView(loadFailed: $loadFailed, loadingType: .truck)
}
.task {
await doFoodTruckStuff()
}
} else {
ScrollView {
VStack(alignment: .leading) {
Text("Weekend Food Trucks")
.font(.title)
.fontWeight(.semibold)
ForEach(foodTruckEvents, id: \.self) { event in
Divider()
Text(visitingChefDateDisplay.string(from: event.date))
.font(.title2)
.fontWeight(.semibold)
Text("\(dateDisplay.string(from: event.openTime)) - \(dateDisplay.string(from: event.closeTime))")
.font(.title3)
ForEach(event.trucks, id: \.self) { truck in
Text(truck)
}
Spacer()
}
Spacer()
Text("Food truck data is sourced directly from the RIT Events website, and may not be presented correctly. Use the globe button in the top right to access the RIT Events website directly to see the original source of the information.")
.foregroundStyle(.secondary)
}
.padding(.horizontal, 8)
}
.toolbar {
ToolbarItemGroup(placement: .primaryAction) {
Button(action: {
showingSafari = true
}) {
Image(systemName: "network")
}
}
}
.sheet(isPresented: $showingSafari) {
SafariView(url: URL(string: "https://www.rit.edu/events/weekend-food-trucks")!)
}
}
}
}