oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1#if os(macOS)
2import RastrilloApple
3import SwiftUI
4
5/// The menu-bar panel (mockup `mac-menubar`): Ask, compact, over the sky.
6/// Jobs waiting on the person sit at the top; the field has focus when it
7/// opens; Open Base brings the window forward; the foot shows the team and,
8/// once the person has chosen one, the shortcut.
9public struct MenuPanel: View {
10 let me: Me?
11 let ask: AskModel?
12 let shortcut: String?
13 let openBase: () -> Void
14 let actions: BaseActions
15 @Environment(\.colorScheme) private var scheme
16
17 public init(me: Me?, ask: AskModel?, shortcut: String?, openBase: @escaping () -> Void, actions: BaseActions) {
18 self.me = me; self.ask = ask; self.shortcut = shortcut; self.openBase = openBase; self.actions = actions
19 }
20
21 public var body: some View {
22 let p = Palette(scheme)
23 VStack(spacing: 0) {
24 HStack(spacing: 9) {
25 BaseMark(size: 16)
26 Text(BaseText.text("native.sidebar.ask")).font(BaseFont.heading(17, .semibold, relativeTo: .headline))
27 .accessibilityAddTraits(.isHeader)
28 Spacer()
29 Button(action: openBase) {
30 HStack(spacing: 6) {
31 Text(BaseText.text("native.menubar.open")).font(BaseFont.body(13, .medium))
32 Icon(.arrowOut, weight: 2).frame(width: 13, height: 13)
33 }
34 .padding(.horizontal, 12).frame(height: 30)
35 .background(p[.chip], in: Capsule())
36 .overlay { Capsule().strokeBorder(p[.chipEdge], lineWidth: 1) }
37 .contentShape(Capsule())
38 }
39 .buttonStyle(.plain)
40 }
41 .padding(.top, 14).padding(.bottom, 10).padding(.leading, 18).padding(.trailing, 14)
42 Group {
43 if let ask {
44 VStack(spacing: 0) {
45 WaitingJobs(ask: ask, timeZone: me?.base.timeZone)
46 AskView(model: ask, layout: .panel, timeZone: me?.base.timeZone, actions: AskActions(setUp: actions.setUpAsk, setUpOnWeb: actions.setUpAskOnWeb), focusOnAppear: true)
47 }
48 } else {
49 Spacer()
50 }
51 }
52 .glassSheet(cornerRadius: 16)
53 .padding(.horizontal, 10)
54 HStack {
55 Text(verbatim: me?.base.name ?? "")
56 Spacer()
57 if let shortcut, !shortcut.isEmpty {
58 Text(BaseText.format("native.menubar.shortcut_hint", ["shortcut": shortcut]))
59 }
60 }
61 .font(BaseFont.body(12.5, relativeTo: .footnote)).foregroundStyle(p[.haze])
62 .padding(.horizontal, 18).padding(.top, 9).padding(.bottom, 11)
63 }
64 .foregroundStyle(p[.frost])
65 .background { Sky() }
66 .frame(width: 410, height: 560)
67 }
68}
69
70/// The panel's top: the jobs waiting on the person (asking, stopped), each
71/// with its open cards, so a question can be answered without scrolling
72/// the conversation. However many there are, they take at most
73/// `maxHeight` and scroll inside it, so the header, the conversation, the
74/// composer and Open Base stay in reach.
75struct WaitingJobs: View {
76 let ask: AskModel
77 let timeZone: TimeZone?
78 static let maxHeight: CGFloat = 200
79 @Environment(\.colorScheme) private var scheme
80
81 var body: some View {
82 let jobs: [AskModel.Job] = ask.entries.compactMap {
83 if case .job(let j) = $0, j.state == .asking || j.state == .stopped { return j }
84 return nil
85 }
86 if !jobs.isEmpty {
87 ViewThatFits(in: .vertical) {
88 list(jobs)
89 ScrollView { list(jobs) }.scrollIndicators(.visible)
90 }
91 .frame(maxHeight: Self.maxHeight)
92 // A rule between them and the conversation.
93 .overlay(alignment: .bottom) { Rectangle().fill(Palette(scheme)[.rule]).frame(height: 1) }
94 }
95 }
96
97 private func list(_ jobs: [AskModel.Job]) -> some View {
98 VStack(alignment: .leading, spacing: 8) {
99 ForEach(jobs, id: \.card.id) { job in
100 JobPill(job: job, busy: ask.answering, timeZone: timeZone) { card, option in Task { await ask.answer(card, option) } }
101 }
102 }
103 .padding(.horizontal, 12).padding(.vertical, 12)
104 .frame(maxWidth: .infinity, alignment: .leading)
105 }
106}
107#endif
108