| 1 | // Ported from the r7 mockups (Components.swift). |
| 2 | import SwiftUI |
| 3 | |
| 4 | struct Hairline: View { |
| 5 | var body: some View { Rectangle().fill(Palette.border).frame(height: 1) } |
| 6 | } |
| 7 | struct StepMark: View { |
| 8 | let state: String |
| 9 | let needsYou: Bool |
| 10 | var body: some View { |
| 11 | ZStack { |
| 12 | switch state { |
| 13 | case "done": |
| 14 | Image(systemName: "checkmark.circle.fill").resizable().foregroundStyle(Palette.positive) |
| 15 | case "failed": |
| 16 | Image(systemName: "exclamationmark.circle.fill").resizable().foregroundStyle(Palette.negative) |
| 17 | case "waiting": |
| 18 | Image(systemName: needsYou ? "hand.raised.circle.fill" : "pause.circle.fill").resizable() |
| 19 | .foregroundStyle(Palette.warning) |
| 20 | case "running": |
| 21 | Circle().strokeBorder(Palette.positive, lineWidth: 2) |
| 22 | Circle().fill(Palette.positive).padding(6) |
| 23 | default: |
| 24 | Circle().strokeBorder(Palette.controlBorder, style: StrokeStyle(lineWidth: 1.5, dash: [3, 3])) |
| 25 | } |
| 26 | }.frame(width: 22, height: 22) |
| 27 | } |
| 28 | } |
| 29 | /// The task's steps as a connected timeline, in plan order: who ran, how |
| 30 | /// it went, and the step's own headline. |
| 31 | struct StepsView: View { |
| 32 | let task: ThinTask |
| 33 | var client: EquipoClient? |
| 34 | var body: some View { |
| 35 | let steps = task.steps ?? [] |
| 36 | VStack(alignment: .leading, spacing: 0) { |
| 37 | ForEach(Array(steps.enumerated()), id: \.element.id) { index, step in |
| 38 | let last = index == steps.count - 1 |
| 39 | HStack(alignment: .top, spacing: 12) { |
| 40 | VStack(spacing: 4) { |
| 41 | StepMark(state: step.state, needsYou: false).accessibilityHidden(true) |
| 42 | if !last { |
| 43 | Capsule().fill(step.state == "done" ? Palette.positive.opacity(0.55) : Palette.border) |
| 44 | .frame(width: 2).frame(maxHeight: .infinity) |
| 45 | } |
| 46 | }.padding(.bottom, last ? 0 : 4) |
| 47 | VStack(alignment: .leading, spacing: 4) { |
| 48 | VStack(alignment: .leading, spacing: 4) { |
| 49 | HStack(alignment: .firstTextBaseline) { |
| 50 | SpecialistLabel(category: step.who, tone: step.state == "queued" ? Palette.secondary : Palette.text) |
| 51 | Spacer(minLength: 8) |
| 52 | Text(Self.label(step.state)).font(Typo.caption) |
| 53 | .foregroundStyle(step.state == "failed" ? Palette.negative : step.state == "done" ? Palette.positive : Palette.secondary) |
| 54 | } |
| 55 | let line = step.headline.isEmpty ? step.summary : step.headline |
| 56 | if !line.isEmpty { |
| 57 | Text(line).font(Typo.secondary) |
| 58 | .foregroundStyle(step.state == "queued" ? Palette.secondary : Palette.text) |
| 59 | .fixedSize(horizontal: false, vertical: true) |
| 60 | } |
| 61 | if let finished = step.finishedAt { |
| 62 | Text(finished.formatted(date: .abbreviated, time: .shortened)).font(Typo.caption).foregroundStyle(Palette.faint) |
| 63 | } |
| 64 | }.accessibilityElement(children: .combine) |
| 65 | if step.state == "failed", let client { StepLogView(stepID: step.id, client: client) } |
| 66 | }.padding(.bottom, last ? 0 : 20) |
| 67 | }.fixedSize(horizontal: false, vertical: true) |
| 68 | .accessibilityElement(children: .contain) |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | static func label(_ state: String) -> String { |
| 73 | switch state { |
| 74 | case "done": return String(localized: "step.done", bundle: .module) |
| 75 | case "running": return String(localized: "step.running", bundle: .module) |
| 76 | case "failed": return String(localized: "step.failed", bundle: .module) |
| 77 | case "cancelled": return String(localized: "step.cancelled", bundle: .module) |
| 78 | default: return String(localized: "step.queued", bundle: .module) |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | /// The app's own mark (estilo's Equipo icon, the chat bubble with two |
| 83 | /// sparkles), as the web shows it. |
| 84 | struct AppGlyph: View { |
| 85 | var size: CGFloat = 38 |
| 86 | var body: some View { |
| 87 | Image("AppMark", bundle: .module).resizable().interpolation(.high) |
| 88 | .frame(width: size, height: size) |
| 89 | .accessibilityHidden(true) |
| 90 | } |
| 91 | } |
| 92 | struct StatTile: View { |
| 93 | let label: String |
| 94 | let value: String |
| 95 | var body: some View { |
| 96 | VStack(alignment: .leading, spacing: 4) { |
| 97 | Text(value).font(Typo.stat).monospacedDigit().foregroundStyle(Palette.text) |
| 98 | Text(label).font(Typo.caption).foregroundStyle(Palette.secondary) |
| 99 | } |
| 100 | .frame(maxWidth: .infinity, alignment: .leading) |
| 101 | .padding(Metric.cardPadding - 2) |
| 102 | .background(Palette.surface, in: RoundedRectangle(cornerRadius: Metric.card, style: .continuous)) |
| 103 | .overlay(RoundedRectangle(cornerRadius: Metric.card, style: .continuous).strokeBorder(Palette.border, lineWidth: 1)) |
| 104 | .accessibilityElement(children: .combine) |
| 105 | } |
| 106 | } |
| 107 | |