import EquipoKit import RastrilloApple import SwiftUI /// The signed-in window: a sidebar of Conversation, Needs you and Tasks, the /// chosen one in the middle, and a task in the inspector. struct MacMainView: View { let model: EquipoAppModel let session: EquipoSession typealias Pane = Destination.Pane @State private var workspace: MacWorkspace init(model: EquipoAppModel, session: EquipoSession) { self.model = model; self.session = session _workspace = State(initialValue: MacWorkspace(app: model, session: session)) } var body: some View { @Bindable var workspace = workspace NavigationSplitView { List(selection: Binding(get: { workspace.pane }, set: { workspace.go(.pane($0)) })) { Label(EquipoStrings.text("tab.conversation"), systemImage: "bubble.left.and.bubble.right").tag(Pane.conversation) needsRow.tag(Pane.needs) Label(EquipoStrings.text("tab.tasks"), systemImage: "checklist").tag(Pane.tasks) Label(EquipoStrings.text("nav.projects"), systemImage: "folder").tag(Pane.projects) } .listStyle(.sidebar) .navigationSplitViewColumnWidth(min: 200, ideal: 220, max: 280) } detail: { detail .safeAreaInset(edge: .top, spacing: 0) { NativeOfflineBanner(origin: session.origin) } .navigationTitle(session.teamName) .navigationSubtitle(title(for: workspace.pane)) } .inspector(isPresented: $workspace.inspector) { Group { if let context = workspace.context { TaskScreen(context: context).id(context.taskID) } else { Text(EquipoStrings.text("task.none_selected")).foregroundStyle(.secondary) } } .inspectorColumnWidth(min: 300, ideal: 360, max: 480) } .modifier(MacWorkspacePresenter(workspace: workspace)) .onChange(of: model.destination, initial: true) { _, destination in guard let destination else { return } go(destination) model.destination = nil } .toolbar { ToolbarItem(placement: .primaryAction) { needsPill } ToolbarItem(placement: .primaryAction) { Button { workspace.inspector.toggle() } label: { Image(systemName: "sidebar.right") } .help(EquipoStrings.text("task.inspector")) .accessibilityLabel(EquipoStrings.text("task.inspector")) } } } @ViewBuilder private var detail: some View { switch workspace.pane { case .conversation: 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) case .projects: HStack(spacing: 0) { ProjectsScreen(session: session) { workspace.go(.project($0)) } .frame(minWidth: 260, idealWidth: 340, maxWidth: 420) Divider() if let id = workspace.projectID { ProjectDetailScreen(session: session, projectID: id) { project in session.projectCatalog.selection = project; workspace.go(.pane(.conversation)) } openTask: { open($0) } } else { Color.clear.frame(maxWidth: .infinity) } } case .needs: NeedsScreen(session: session, openTask: open) case .tasks: TasksScreen(session: session, openTask: open) } } @ViewBuilder private var needsRow: some View { if let count = session.needsYouCount, count > 0 { Label(EquipoStrings.text("tab.needs"), systemImage: "tray").badge(count) } else { Label(EquipoStrings.text("tab.needs"), systemImage: "tray") } } /// The web's Needs you pill: an inbox and its count, only when known. private var needsPill: some View { Button { workspace.go(.pane(.needs)) } label: { HStack(spacing: 6) { Image(systemName: "tray") if let count = session.needsYouCount { Text(count.formatted()).monospacedDigit() } } } .help(EquipoStrings.text("tab.needs")) .accessibilityLabel(session.needsYouCount.map { count in EquipoStrings.text("needs.count \(count)") } ?? EquipoStrings.text("tab.needs")) } private func title(for pane: Pane) -> String { switch pane { case .conversation: return EquipoStrings.text("tab.conversation") case .needs: return EquipoStrings.text("tab.needs") case .tasks: return EquipoStrings.text("tab.tasks") case .projects: return EquipoStrings.text("nav.projects") } } /// A tapped notification: the conversation at its card, or the task in /// the inspector beside Tasks. private func go(_ destination: Destination) { workspace.open(destination) } private func open(_ taskID: String) { workspace.go(.task(taskID)) } }