#if os(macOS) import RastrilloApple import SwiftUI /// The menu-bar panel (mockup `mac-menubar`): Ask, compact, over the sky. /// Jobs waiting on the person sit at the top; the field has focus when it /// opens; Open Base brings the window forward; the foot shows the team and, /// once the person has chosen one, the shortcut. public struct MenuPanel: View { let me: Me? let ask: AskModel? let shortcut: String? let openBase: () -> Void let actions: BaseActions @Environment(\.colorScheme) private var scheme public init(me: Me?, ask: AskModel?, shortcut: String?, openBase: @escaping () -> Void, actions: BaseActions) { self.me = me; self.ask = ask; self.shortcut = shortcut; self.openBase = openBase; self.actions = actions } public var body: some View { let p = Palette(scheme) VStack(spacing: 0) { HStack(spacing: 9) { BaseMark(size: 16) Text(BaseText.text("native.sidebar.ask")).font(BaseFont.heading(17, .semibold, relativeTo: .headline)) .accessibilityAddTraits(.isHeader) Spacer() Button(action: openBase) { HStack(spacing: 6) { Text(BaseText.text("native.menubar.open")).font(BaseFont.body(13, .medium)) Icon(.arrowOut, weight: 2).frame(width: 13, height: 13) } .padding(.horizontal, 12).frame(height: 30) .background(p[.chip], in: Capsule()) .overlay { Capsule().strokeBorder(p[.chipEdge], lineWidth: 1) } .contentShape(Capsule()) } .buttonStyle(.plain) } .padding(.top, 14).padding(.bottom, 10).padding(.leading, 18).padding(.trailing, 14) Group { if let ask { VStack(spacing: 0) { WaitingJobs(ask: ask, timeZone: me?.base.timeZone) AskView(model: ask, layout: .panel, timeZone: me?.base.timeZone, actions: AskActions(setUp: actions.setUpAsk, setUpOnWeb: actions.setUpAskOnWeb), focusOnAppear: true) } } else { Spacer() } } .glassSheet(cornerRadius: 16) .padding(.horizontal, 10) HStack { Text(verbatim: me?.base.name ?? "") Spacer() if let shortcut, !shortcut.isEmpty { Text(BaseText.format("native.menubar.shortcut_hint", ["shortcut": shortcut])) } } .font(BaseFont.body(12.5, relativeTo: .footnote)).foregroundStyle(p[.haze]) .padding(.horizontal, 18).padding(.top, 9).padding(.bottom, 11) } .foregroundStyle(p[.frost]) .background { Sky() } .frame(width: 410, height: 560) } } /// The panel's top: the jobs waiting on the person (asking, stopped), each /// with its open cards, so a question can be answered without scrolling /// the conversation. However many there are, they take at most /// `maxHeight` and scroll inside it, so the header, the conversation, the /// composer and Open Base stay in reach. struct WaitingJobs: View { let ask: AskModel let timeZone: TimeZone? static let maxHeight: CGFloat = 200 @Environment(\.colorScheme) private var scheme var body: some View { let jobs: [AskModel.Job] = ask.entries.compactMap { if case .job(let j) = $0, j.state == .asking || j.state == .stopped { return j } return nil } if !jobs.isEmpty { ViewThatFits(in: .vertical) { list(jobs) ScrollView { list(jobs) }.scrollIndicators(.visible) } .frame(maxHeight: Self.maxHeight) // A rule between them and the conversation. .overlay(alignment: .bottom) { Rectangle().fill(Palette(scheme)[.rule]).frame(height: 1) } } } private func list(_ jobs: [AskModel.Job]) -> some View { VStack(alignment: .leading, spacing: 8) { ForEach(jobs, id: \.card.id) { job in JobPill(job: job, busy: ask.answering, timeZone: timeZone) { card, option in Task { await ask.answer(card, option) } } } } .padding(.horizontal, 12).padding(.vertical, 12) .frame(maxWidth: .infinity, alignment: .leading) } } #endif