Branchwell

OpenTalon / app / native / Sources / OpenTalon / TaskActivitySection.swift

1import AppKit
2import CompanionCore
3import SwiftUI
4
5struct TaskActivitySection: View {
6 @State private var showing = false
7 let taskID: String
8 var body: some View {
9 VStack(alignment: .leading, spacing: 12) {
10 Text("Activity").font(.headline)
11 Button("View activity", systemImage: "clock.arrow.circlepath") { showing = true }
12 .buttonStyle(GlassActionStyle()).accessibilityIdentifier("taskActivity")
13 }
14 .sheet(isPresented: $showing) { TaskActivityPanel(taskID: taskID) }
15 }
16}
17
18struct TaskActivityPanel: View {
19 @Environment(WorkspaceModel.self) private var model
20 @Environment(\.palette) private var palette
21 @State private var page: TaskActivityPage?
22 @State private var attachment: DraftImage?
23 @State private var error: String?
24 let taskID: String
25 var commentID: String? = nil
26 var body: some View {
27 TaskActivityView(page: page, colors: OpenTalonColors(theme: palette.theme), commentID: commentID, load: load) { image in
28 Task {
29 do { attachment = try await model.service.call("read_comment_image", ["imageId": image.id]) }
30 catch { self.error = error.localizedDescription }
31 }
32 }
33 .frame(minWidth: 600, minHeight: 650)
34 .overlay(alignment: .bottom) {
35 if let error { Text(error).foregroundStyle(palette.danger).padding() }
36 }
37 .sheet(item: $attachment) { image in
38 VStack(alignment: .trailing, spacing: 16) {
39 HStack { Text(image.name).lineLimit(1); Spacer(); Button("Close") { attachment = nil } }
40 if let bitmap = image.image { Image(nsImage: bitmap).resizable().scaledToFit().frame(maxHeight: 520) }
41 }.padding(20).frame(width: 680)
42 }
43 }
44 private func load(_ before: Int?) async throws {
45 var input: [String: Any] = ["taskId": taskID, "limit": 20]
46 input["beforeSequence"] = before
47 input["commentId"] = commentID
48 let result: TaskActivityPage = try await model.service.call("list_task_activity", input)
49 if before == nil { page = result }
50 else { page = page?.merging(result) ?? result }
51 }
52}