From 3eb2018a8eea128901be102e7c7d1fffff1ffa40 Mon Sep 17 00:00:00 2001 From: Tony Bark <35226681+tonytins@users.noreply.github.com> Date: Sat, 22 Aug 2026 17:36:14 -0400 Subject: [PATCH] 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). --- Sources/AmtrakStatus/AmtrakStatusApp.swift | 5 +-- Sources/AmtrakStatus/ContentView.swift | 50 +++++++++++++++++++--- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/Sources/AmtrakStatus/AmtrakStatusApp.swift b/Sources/AmtrakStatus/AmtrakStatusApp.swift index 5c12b87..0c42f21 100644 --- a/Sources/AmtrakStatus/AmtrakStatusApp.swift +++ b/Sources/AmtrakStatus/AmtrakStatusApp.swift @@ -4,9 +4,8 @@ import DefaultBackend @main struct AmtrakStatusApp: App { var body: some Scene { - WindowGroup("AmtrakStatus") { - Text("Hello, World!") - .padding() + WindowGroup("Amtrak Status") { + ContentView() } } } diff --git a/Sources/AmtrakStatus/ContentView.swift b/Sources/AmtrakStatus/ContentView.swift index 1aceb27..0137798 100644 --- a/Sources/AmtrakStatus/ContentView.swift +++ b/Sources/AmtrakStatus/ContentView.swift @@ -3,20 +3,51 @@ import SwiftCrossUI struct ContentView: View { @State var client = AmtrakClient() - @State var stationCode = "ASD" // Ashville, VA + @State var stationCode = "ASD" // Ashland, VA @State var rows: [TrainStatusRow] = [] @State var isLoading = false @State var errorMessage: String? var body: some View { - HStack { + VStack { + // TODO: Add pre-selected options in the form of buttons like the original + 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) - }.padding() - .onAppear { - Task { - await loadTrainStatus(forStationCode: normalizedStationCode) + 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() + .onAppear { + Task { + await loadTrainStatus(forStationCode: normalizedStationCode) + } } - } } var normalizedStationCode: String { @@ -44,6 +75,11 @@ struct ContentView: View { return } + var newRows: [TrainStatusRow] = [] + for number in trainNumbers { + // let trains = await client.fet + } + } catch AmtrakError.stationNotFound(let code) { errorMessage = "Station \(code) not foudn"