| 1 | import EquipoKit |
| 2 | import SwiftUI |
| 3 | |
| 4 | struct MacTaskWindow: View { |
| 5 | let model: EquipoAppModel |
| 6 | let identity: MacTaskWindowID? |
| 7 | @Environment(\.dismiss) private var dismiss |
| 8 | var body: some View { |
| 9 | Group { |
| 10 | if let identity, let session = model.session, identity.matches(session), !model.needsPairing { |
| 11 | MacTaskWindowContent(app: model, session: session, identity: identity) |
| 12 | .id(identity) |
| 13 | } else { Color.clear.task { dismiss() } } |
| 14 | }.modifier(MacSessionLifecycle(model: model)) |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | private struct MacTaskWindowContent: View { |
| 19 | let session: EquipoSession |
| 20 | let identity: MacTaskWindowID |
| 21 | @State private var workspace: MacWorkspace |
| 22 | @State private var initialRepo: String? |
| 23 | @Environment(\.dismiss) private var dismiss |
| 24 | init(app: EquipoAppModel, session: EquipoSession, identity: MacTaskWindowID) { |
| 25 | self.session = session; self.identity = identity |
| 26 | _workspace = State(initialValue: MacWorkspace(app: app, session: session, taskID: identity.taskID)) |
| 27 | _initialRepo = State(initialValue: session.task(identity.taskID)?.repo) |
| 28 | } |
| 29 | private var shouldClose: Bool { |
| 30 | workspace.context?.refused == true || !identity.matches(session) || |
| 31 | MacTaskWindowPolicy.shouldClose(task: workspace.context?.task, initialRepo: initialRepo, status: nil) |
| 32 | } |
| 33 | var body: some View { |
| 34 | Group { |
| 35 | if let context = workspace.context { TaskScreen(context: context) } |
| 36 | } |
| 37 | .navigationTitle(workspace.context?.title ?? EquipoStrings.text("task.title")) |
| 38 | .frame(minWidth: 520, minHeight: 480) |
| 39 | .modifier(MacWorkspacePresenter(workspace: workspace)) |
| 40 | .onChange(of: shouldClose, initial: true) { _, close in if close { dismiss() } } |
| 41 | .onChange(of: workspace.context?.task?.repo) { _, repo in if initialRepo == nil { initialRepo = repo } } |
| 42 | |
| 43 | } |
| 44 | } |
| 45 | |