Added a few pre-selected stations

- Went with the popular Virtual Railfan ones first.
- Moved the error message to its own dedicated space so it doesn't pop up out of nowhere
- Fixed a few typos
This commit is contained in:
Tony Bark 2026-08-22 18:19:14 -04:00
parent b9349e2c24
commit 789e697828
2 changed files with 38 additions and 11 deletions

View file

@ -5,8 +5,8 @@
## 🖥️ Supported Platforms ## 🖥️ Supported Platforms
| Platform | Minimum Version | | Platform | Minimum Version |
| --- | --- | | ---------------------------- | --------------- |
| macOS | 13+ | | macOS | 10.15+ |
| Windows | 10+ | | Windows | 10+ |
| Linux | gtk 3+ | | Linux | gtk 3+ |

View file

@ -10,7 +10,6 @@ struct ContentView: View {
var body: some View { var body: some View {
VStack { VStack {
// TODO: Add pre-selected options in the form of buttons like the original
HStack { HStack {
Text("Station Code:") Text("Station Code:")
TextField("e.g. ASD", text: $stationCode) TextField("e.g. ASD", text: $stationCode)
@ -23,9 +22,30 @@ struct ContentView: View {
}.disabled(normalizedStationCode.isEmpty || isLoading) }.disabled(normalizedStationCode.isEmpty || isLoading)
}.padding(10) }.padding(10)
if let errorMessage { // Most popular Virtual Railfan stations
Text(errorMessage).padding(10) HStack {
Button("Ashland, VA")
{
Task {
await loadTrainStatus(forStationCode: "ASD")
} }
}
Button("San Juan Capistrano, CA")
{
Task {
await loadTrainStatus(forStationCode: "SNC")
}
}
Button("La Plata, MO")
{
Task {
await loadTrainStatus(forStationCode: "LAP")
}
}
}
Table(rows) { Table(rows) {
TableColumn("Number", value: \TrainStatusRow.trainNum) TableColumn("Number", value: \TrainStatusRow.trainNum)
@ -39,6 +59,13 @@ struct ContentView: View {
.padding(10) .padding(10)
} }
} }
HStack {
if let errorMessage {
Text(errorMessage)
}
}.padding(10)
}.padding() }.padding()
.onAppear { .onAppear {
Task { Task {
@ -67,7 +94,7 @@ struct ContentView: View {
) )
guard !trainNumbers.isEmpty else { guard !trainNumbers.isEmpty else {
errorMessage = "Station \(code) has no trains listed right now" errorMessage = "\(code) has no trains listed right now"
rows = [] rows = []
return return
} }
@ -93,7 +120,7 @@ struct ContentView: View {
} }
rows = newRows rows = newRows
} catch let AmtrakError.stationNotFound(code) { } catch let AmtrakError.stationNotFound(code) {
errorMessage = "Station \(code) not foudn" errorMessage = "Station \(code) not found"
rows = [] rows = []
} catch { } catch {
errorMessage = "Couldn't load train status: \(error.localizedDescription)" errorMessage = "Couldn't load train status: \(error.localizedDescription)"