mirror of
https://github.com/tonytins/amtkstat.git
synced 2026-10-24 05:32:54 -04:00
Use ContentView and add station input UI
- Replace the placeholder window content with ContentView and implement a basic station lookup UI. - Added a station code TextField, Refresh button that triggers an async load, loading indicator, and error message display. Introduces a Table for TrainStatusRow with columns for number, route, on-time and platform. - Started plumbing for row population (work in progress). - Also tweaked window title and fixes station comment (Ashland).
This commit is contained in:
parent
f81ae23bb0
commit
3eb2018a8e
2 changed files with 45 additions and 10 deletions
|
|
@ -4,9 +4,8 @@ import DefaultBackend
|
||||||
@main
|
@main
|
||||||
struct AmtrakStatusApp: App {
|
struct AmtrakStatusApp: App {
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup("AmtrakStatus") {
|
WindowGroup("Amtrak Status") {
|
||||||
Text("Hello, World!")
|
ContentView()
|
||||||
.padding()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,45 @@ import SwiftCrossUI
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@State var client = AmtrakClient()
|
@State var client = AmtrakClient()
|
||||||
|
|
||||||
@State var stationCode = "ASD" // Ashville, VA
|
@State var stationCode = "ASD" // Ashland, VA
|
||||||
@State var rows: [TrainStatusRow] = []
|
@State var rows: [TrainStatusRow] = []
|
||||||
@State var isLoading = false
|
@State var isLoading = false
|
||||||
@State var errorMessage: String?
|
@State var errorMessage: String?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
// TODO: Add pre-selected options in the form of buttons like the original
|
||||||
HStack {
|
HStack {
|
||||||
|
Text("Station Code:")
|
||||||
|
TextField("e.g. ASD", text: $stationCode)
|
||||||
|
.frame(width: 100)
|
||||||
|
|
||||||
|
Button("Refresh")
|
||||||
|
{
|
||||||
|
Task {
|
||||||
|
await loadTrainStatus(forStationCode: normalizedStationCode)
|
||||||
|
}
|
||||||
|
}.disabled(normalizedStationCode.isEmpty || isLoading)
|
||||||
|
}.padding(10)
|
||||||
|
|
||||||
|
if let errorMessage {
|
||||||
|
Text(errorMessage).padding(10)
|
||||||
|
}
|
||||||
|
|
||||||
|
Table(rows)
|
||||||
|
{
|
||||||
|
TableColumn("Number", value: \TrainStatusRow.trainNum)
|
||||||
|
TableColumn("Number", value: \TrainStatusRow.routeName)
|
||||||
|
TableColumn("On Time", value: \TrainStatusRow.onTime)
|
||||||
|
TableColumn("Platform", value: \TrainStatusRow.platform)
|
||||||
|
|
||||||
|
}.overlay(alignment: .bottomTrailing)
|
||||||
|
{
|
||||||
|
if isLoading {
|
||||||
|
ProgressView()
|
||||||
|
.padding(10)
|
||||||
|
}
|
||||||
|
}
|
||||||
}.padding()
|
}.padding()
|
||||||
.onAppear {
|
.onAppear {
|
||||||
Task {
|
Task {
|
||||||
|
|
@ -44,6 +75,11 @@ struct ContentView: View {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var newRows: [TrainStatusRow] = []
|
||||||
|
for number in trainNumbers {
|
||||||
|
// let trains = await client.fet
|
||||||
|
}
|
||||||
|
|
||||||
} catch AmtrakError.stationNotFound(let code)
|
} catch AmtrakError.stationNotFound(let code)
|
||||||
{
|
{
|
||||||
errorMessage = "Station \(code) not foudn"
|
errorMessage = "Station \(code) not foudn"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue