| 1 | import EquipoKit |
| 2 | import RastrilloApple |
| 3 | import SwiftUI |
| 4 | |
| 5 | /// The signed-in window: a sidebar of Conversation, Needs you and Tasks, the |
| 6 | /// chosen one in the middle, and a task in the inspector. |
| 7 | struct MacMainView: View { |
| 8 | let model: EquipoAppModel |
| 9 | let session: EquipoSession |
| 10 | |
| 11 | typealias Pane = Destination.Pane |
| 12 | @State private var workspace: MacWorkspace |
| 13 | init(model: EquipoAppModel, session: EquipoSession) { |
| 14 | self.model = model; self.session = session |
| 15 | _workspace = State(initialValue: MacWorkspace(app: model, session: session)) |
| 16 | } |
| 17 | |
| 18 | var body: some View { |
| 19 | @Bindable var workspace = workspace |
| 20 | NavigationSplitView { |
| 21 | List(selection: Binding(get: { workspace.pane }, set: { workspace.go(.pane($0)) })) { |
| 22 | Label(EquipoStrings.text("tab.conversation"), systemImage: "bubble.left.and.bubble.right").tag(Pane.conversation) |
| 23 | needsRow.tag(Pane.needs) |
| 24 | Label(EquipoStrings.text("tab.tasks"), systemImage: "checklist").tag(Pane.tasks) |
| 25 | Label(EquipoStrings.text("nav.projects"), systemImage: "folder").tag(Pane.projects) |
| 26 | } |
| 27 | .listStyle(.sidebar) |
| 28 | .navigationSplitViewColumnWidth(min: 200, ideal: 220, max: 280) |
| 29 | } detail: { |
| 30 | detail |
| 31 | .safeAreaInset(edge: .top, spacing: 0) { NativeOfflineBanner(origin: session.origin) } |
| 32 | .navigationTitle(session.teamName) |
| 33 | .navigationSubtitle(title(for: workspace.pane)) |
| 34 | } |
| 35 | .inspector(isPresented: $workspace.inspector) { |
| 36 | Group { |
| 37 | if let context = workspace.context { TaskScreen(context: context).id(context.taskID) } |
| 38 | else { Text(EquipoStrings.text("task.none_selected")).foregroundStyle(.secondary) } |
| 39 | } |
| 40 | .inspectorColumnWidth(min: 300, ideal: 360, max: 480) |
| 41 | } |
| 42 | .modifier(MacWorkspacePresenter(workspace: workspace)) |
| 43 | .onChange(of: model.destination, initial: true) { _, destination in |
| 44 | guard let destination else { return } |
| 45 | go(destination) |
| 46 | model.destination = nil |
| 47 | } |
| 48 | .toolbar { |
| 49 | ToolbarItem(placement: .primaryAction) { needsPill } |
| 50 | ToolbarItem(placement: .primaryAction) { |
| 51 | Button { workspace.inspector.toggle() } label: { Image(systemName: "sidebar.right") } |
| 52 | .help(EquipoStrings.text("task.inspector")) |
| 53 | .accessibilityLabel(EquipoStrings.text("task.inspector")) |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | @ViewBuilder private var detail: some View { |
| 59 | switch workspace.pane { |
| 60 | case .conversation: |
| 61 | TranscriptView(projectSelectionID: session.projectCatalog.selection?.id, projectSelectionNotice: session.projectCatalog.selectionNotice, items: Feed.build(session), session: session, focusCard: Binding(get: { workspace.focusCard }, set: { workspace.focusCard = $0 }), openTask: open, composerFocus: workspace.composerFocus, draft: workspace.composerDraft) |
| 62 | case .projects: |
| 63 | HStack(spacing: 0) { |
| 64 | ProjectsScreen(session: session) { workspace.go(.project($0)) } |
| 65 | .frame(minWidth: 260, idealWidth: 340, maxWidth: 420) |
| 66 | Divider() |
| 67 | if let id = workspace.projectID { |
| 68 | ProjectDetailScreen(session: session, projectID: id) { project in |
| 69 | session.projectCatalog.selection = project; workspace.go(.pane(.conversation)) |
| 70 | } openTask: { open($0) } |
| 71 | } else { Color.clear.frame(maxWidth: .infinity) } |
| 72 | } |
| 73 | case .needs: |
| 74 | NeedsScreen(session: session, openTask: open) |
| 75 | case .tasks: |
| 76 | TasksScreen(session: session, openTask: open) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | @ViewBuilder private var needsRow: some View { |
| 81 | if let count = session.needsYouCount, count > 0 { |
| 82 | Label(EquipoStrings.text("tab.needs"), systemImage: "tray").badge(count) |
| 83 | } else { |
| 84 | Label(EquipoStrings.text("tab.needs"), systemImage: "tray") |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /// The web's Needs you pill: an inbox and its count, only when known. |
| 89 | private var needsPill: some View { |
| 90 | Button { workspace.go(.pane(.needs)) } label: { |
| 91 | HStack(spacing: 6) { |
| 92 | Image(systemName: "tray") |
| 93 | if let count = session.needsYouCount { Text(count.formatted()).monospacedDigit() } |
| 94 | } |
| 95 | } |
| 96 | .help(EquipoStrings.text("tab.needs")) |
| 97 | .accessibilityLabel(session.needsYouCount.map { count in EquipoStrings.text("needs.count \(count)") } ?? EquipoStrings.text("tab.needs")) |
| 98 | } |
| 99 | |
| 100 | private func title(for pane: Pane) -> String { |
| 101 | switch pane { |
| 102 | case .conversation: return EquipoStrings.text("tab.conversation") |
| 103 | case .needs: return EquipoStrings.text("tab.needs") |
| 104 | case .tasks: return EquipoStrings.text("tab.tasks") |
| 105 | case .projects: return EquipoStrings.text("nav.projects") |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /// A tapped notification: the conversation at its card, or the task in |
| 110 | /// the inspector beside Tasks. |
| 111 | private func go(_ destination: Destination) { |
| 112 | workspace.open(destination) |
| 113 | } |
| 114 | |
| 115 | private func open(_ taskID: String) { |
| 116 | workspace.go(.task(taskID)) |
| 117 | } |
| 118 | } |
| 119 | |