mirror of
https://github.com/NinjaCheetah/RIT-Dining.git
synced 2026-01-17 12:05:57 -05:00
- The favorites model now lives inside of the base dining model, since it was only ever used in places where the main dining model was also available and is only relevant when the dining model is available. - Removed unnecessary instances of models that were going unused. - Moved the favorite/map/menu buttons in the top right of the DetailView into the right side toolbar. - This frees up a good bit of space at the top of the DetailView and looks cleaner, especially with iOS 26's new toolbar style. - Actually added a copyright string to the about screen. More refactors, both internally and for the UI, will be coming soon.
105 lines
3.8 KiB
Swift
105 lines
3.8 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 rotationDegrees: Double = 0
|
|
@State private var showingSafari: Bool = false
|
|
|
|
private var animation: Animation {
|
|
.linear
|
|
.speed(0.1)
|
|
.repeatForever(autoreverses: 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 {
|
|
if loadFailed {
|
|
Image(systemName: "wifi.exclamationmark.circle")
|
|
.resizable()
|
|
.frame(width: 75, height: 75)
|
|
.foregroundStyle(.accent)
|
|
Text("An error occurred while fetching food truck data. Please check your network connection and try again.")
|
|
.foregroundStyle(.secondary)
|
|
.multilineTextAlignment(.center)
|
|
} else {
|
|
Image(systemName: "truck.box")
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(width: 75, height: 75)
|
|
.foregroundStyle(.accent)
|
|
.rotationEffect(.degrees(rotationDegrees))
|
|
.onAppear {
|
|
withAnimation(animation) {
|
|
rotationDegrees = 360.0
|
|
}
|
|
}
|
|
Text("One moment...")
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
.task {
|
|
await doFoodTruckStuff()
|
|
}
|
|
.padding()
|
|
} 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")!)
|
|
}
|
|
}
|
|
}
|
|
}
|