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"