import SwiftUI /// Tasks, grouped as the web groups them. public struct TasksScreen: View { let session: EquipoSession var openTask: (String) -> Void public init(session: EquipoSession, openTask: @escaping (String) -> Void) { self.session = session; self.openTask = openTask } public var body: some View { List { group(String(localized: "tasks.needs_you", bundle: .module), session.tasks.filter { session.waitsOnYou($0) }) group(String(localized: "tasks.in_progress", bundle: .module), session.tasks.filter { !session.waitsOnYou($0) && !Self.finished($0) }) group(String(localized: "tasks.finished", bundle: .module), session.tasks.filter { !session.waitsOnYou($0) && Self.finished($0) }) } .scrollContentBackground(.hidden).background(Palette.background) .refreshable { await session.refresh() } .overlay { if session.status == .ready && session.tasks.isEmpty { ContentUnavailableView(String(localized: "tasks.empty_title", bundle: .module), systemImage: "checklist", description: Text(String(localized: "tasks.empty", bundle: .module))) } } } static func finished(_ t: ThinTask) -> Bool { t.stage == "done" || t.stage == "cancelled" } @ViewBuilder private func group(_ title: String, _ tasks: [ThinTask]) -> some View { if !tasks.isEmpty { Section(title) { ForEach(tasks) { task in TaskRowButton(task: task, needsYou: session.waitsOnYou(task)) { openTask(task.id) } } }.listRowBackground(Palette.surface) } } } struct TaskRowButton: View { let task: ThinTask let needsYou: Bool var showsNeedsBadge = true var status: String? = nil var action: () -> Void var body: some View { let report = TaskReport(task, needsYou: needsYou) Button(action: action) { HStack(alignment: .center, spacing: 10) { VStack(alignment: .leading, spacing: 5) { HStack(spacing: 8) { if !task.project.isEmpty { ProjectChip(name: task.project) } Spacer(minLength: 8) if showsNeedsBadge && report.needsYou { NeedsChip() } } Text(task.title).font(Typo.cardTitle).foregroundStyle(Palette.text).multilineTextAlignment(.leading) Text(status ?? report.pause?.stop ?? report.eyebrow).font(Typo.eyebrow).foregroundStyle(report.tone.eyebrow) } Image(systemName: "chevron.right").font(.system(size: 12, weight: .semibold)).foregroundStyle(Palette.faint) } .padding(.vertical, 4).contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityElement(children: .combine) } } /// A task's open question or decision cards, as the conversation has them. struct TaskCards: View { let session: EquipoSession let task: ThinTask var body: some View { ForEach(session.cards.filter { $0.taskId == task.id && $0.kind != "task" && $0.isOpen }) { card in if card.kind == "question" { LiveQuestionCard(card: card, taskTitle: nil, session: session) } else { LiveDecisionCard(card: card, taskTitle: task.title, session: session) } } } } /// "Talk about this": the task's own thread, with a compact composer. struct TaskThread: View { let session: EquipoSession let task: ThinTask var sent: () -> Void = {} var body: some View { let turns = (task.thread ?? []).map { ThreadTurn($0, me: session.me?.address) } + session.outgoing.filter { $0.taskID == task.id }.map(ThreadTurn.init) VStack(alignment: .leading, spacing: Metric.gap) { if turns.isEmpty { Text(String(localized: "task.thread_empty", bundle: .module)).font(Typo.secondary).foregroundStyle(Palette.secondary) } ForEach(turns) { turn in ThreadBubble(turn: turn) { Task { await session.retry(turn.id) } } } MiniComposer(placeholder: String(localized: "task.reply", bundle: .module)) { text in Task { await session.send(text, inThreadOf: task.id); sent() } } } .padding(12) .background(Palette.surface2, in: RoundedRectangle(cornerRadius: Metric.raised - 4, style: .continuous)) .overlay(RoundedRectangle(cornerRadius: Metric.raised - 4, style: .continuous).strokeBorder(Palette.border, lineWidth: 1)) } } /// The team answered, but not with what the screens need: say so, offer again. struct ReadFailed: View { var retry: () -> Void var body: some View { ContentUnavailableView { Label(String(localized: "read.failed_title", bundle: .module), systemImage: "exclamationmark.triangle") } description: { Text(String(localized: "read.failed", bundle: .module)) } actions: { RosterButton(title: String(localized: "read.retry", bundle: .module), action: retry) } .padding(.top, 40) } }