diff --git a/Pulse/ContentView.swift b/Pulse/ContentView.swift index a021e20..d9b7606 100644 --- a/Pulse/ContentView.swift +++ b/Pulse/ContentView.swift @@ -8,6 +8,7 @@ struct ContentView: View { @ObservedObject var pullRequest: PullRequestModel @State private var selection = Tab.settled + @Binding var githubToken: String var body: some View { VStack { @@ -27,8 +28,22 @@ struct ContentView: View { } .padding(.top, 5) HStack { - Image(systemName: "clock.arrow.circlepath") - Text("00:00") // TODO: + Button { + Task { + let api = PullRequestAPI(githubToken) + await pullRequest.update(api) + } + } label: { + Image(systemName: "arrow.triangle.2.circlepath") + } + + let label = if let updatedAt = pullRequest.updatedAt { + updatedAt.shortTime() + } else { + "-" + } + + Text(label) } .padding(.bottom, 5) } @@ -37,5 +52,8 @@ struct ContentView: View { } #Preview { - ContentView(pullRequest: PullRequestModel()) + ContentView( + pullRequest: PullRequestModel(), + githubToken: .constant("") + ) } diff --git a/Pulse/PullRequestModel.swift b/Pulse/PullRequestModel.swift index 4493796..40a048c 100644 --- a/Pulse/PullRequestModel.swift +++ b/Pulse/PullRequestModel.swift @@ -3,8 +3,10 @@ import Foundation @MainActor class PullRequestModel: ObservableObject { // TODO: + @Published var updatedAt: Date? func update(_ api: PullRequestAPI) async { // TODO: + updatedAt = Date() } } diff --git a/Pulse/PulseApp.swift b/Pulse/PulseApp.swift index 0b44199..80e28d0 100644 --- a/Pulse/PulseApp.swift +++ b/Pulse/PulseApp.swift @@ -24,7 +24,7 @@ struct PulseApp: App { // TODO: // Notification.initialize() - let contentView = ContentView(pullRequest: pullRequest) + let contentView = ContentView(pullRequest: pullRequest, githubToken: $githubToken) popover.contentViewController = NSHostingController(rootView: contentView) scheduleUpdate()