oficina / base Public

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

Plain git — no account needed to clone.

Download

Download this file

1import RastrilloApple
2import SwiftUI
3
4/// The iPhone's first screen (A, mockup `phone-ask`): Ask. Round glass
5/// buttons for the apps (left, with a dot while a job waits on the person)
6/// and the person (right, the account's menu); "Ask Base" with the team
7/// under it; then the conversation and the composer, which rides above
8/// the keyboard.
9public struct PhoneAskScreen: View {
10 let me: Me?
11 let home: HomeData?
12 let ask: AskModel?
13 let transport: NativeTransport?
14 let actions: BaseActions
15 @State private var appsShown: Bool
16 @State private var switching = false
17 @State private var confirmingSignOut = false
18 @Environment(\.colorScheme) private var scheme
19
20 public init(me: Me?, home: HomeData?, ask: AskModel?, transport: NativeTransport?, actions: BaseActions, appsShown: Bool = false) {
21 self.me = me; self.home = home; self.ask = ask; self.transport = transport; self.actions = actions
22 _appsShown = State(initialValue: appsShown)
23 }
24
25 public var body: some View {
26 let p = Palette(scheme)
27 ZStack {
28 Sky()
29 VStack(spacing: 0) {
30 bar(p)
31 Group {
32 if let ask {
33 AskView(model: ask, layout: .phone, timeZone: me?.base.timeZone,
34 actions: AskActions(setUp: actions.setUpAsk, setUpOnWeb: actions.setUpAskOnWeb))
35 } else {
36 Color.clear
37 }
38 }
39 .frame(maxWidth: .infinity, maxHeight: .infinity)
40 // The sheet's lower corners run off the screen; Ask stays on it.
41 .padding(.bottom, 26)
42 .glassSheet(cornerRadius: 26)
43 .padding(.horizontal, 8)
44 .padding(.bottom, -26)
45 }
46 }
47 .foregroundStyle(p[.frost])
48 .scrollDismissesKeyboard(.interactively)
49 .sheet(isPresented: $appsShown) {
50 AppsSheet(me: me, home: home, transport: transport, actions: actions) { appsShown = false }
51 .presentationDetents([.medium, .large])
52 .presentationDragIndicator(.visible)
53 .presentationBackground { Palette(scheme)[.menuBase] }
54 }
55 .accountChoices(actions: actions, switching: $switching, confirmingSignOut: $confirmingSignOut)
56 }
57
58 private func bar(_ p: Palette) -> some View {
59 HStack(spacing: 10) {
60 Button { appsShown = true } label: {
61 RoundGlass {
62 Image(systemName: "square.grid.2x2").font(.system(size: 18, weight: .medium))
63 }
64 .overlay(alignment: .topTrailing) {
65 if (ask?.waitingJobs ?? 0) > 0 {
66 Circle().fill(p[.stAsk]).frame(width: 10, height: 10)
67 .overlay { Circle().strokeBorder(p[.sky2], lineWidth: 2) }
68 .offset(x: -6, y: 6)
69 }
70 }
71 }
72 .buttonStyle(.plain)
73 .accessibilityLabel(Text(BaseText.text("native.phone.apps_a11y")))
74 .accessibilityValue(Text((ask?.waitingJobs ?? 0) > 0 ? BaseText.plural("native.sidebar.ask.badge_a11y", ask?.waitingJobs ?? 0) : ""))
75 VStack(spacing: 1) {
76 HStack(spacing: 7) {
77 BaseMark(size: 14)
78 Text(BaseText.text("native.sidebar.ask")).font(BaseFont.heading(17, .semibold, relativeTo: .headline))
79 }
80 Text(verbatim: me?.base.name ?? "").font(BaseFont.body(12, relativeTo: .caption)).foregroundStyle(p[.haze])
81 }
82 .frame(maxWidth: .infinity)
83 .accessibilityElement(children: .combine)
84 .accessibilityAddTraits(.isHeader)
85 Menu {
86 AccountMenuItems(actions: actions, switching: $switching, confirmingSignOut: $confirmingSignOut)
87 } label: {
88 RoundGlass { Avatar(me?.member.initials ?? "", size: 32) }
89 }
90 .accessibilityLabel(Text(BaseText.text("native.phone.account_a11y")))
91 }
92 .padding(.horizontal, 14)
93 .frame(minHeight: 56)
94 }
95}
96
97/// A round glass button: 44 pt.
98struct RoundGlass<Content: View>: View {
99 @ViewBuilder let content: Content
100 var body: some View {
101 content.frame(width: 44, height: 44).glass(cornerRadius: 22).contentShape(Circle())
102 }
103}
104
105/// The Apps sheet (mockup `phone-apps`): the team's name, Getting started
106/// while a step is open, and every app in four columns, Base's own pages
107/// (Store, People, Settings) on a row of their own; each opens through
108/// Opener (P12).
109public struct AppsSheet: View {
110 let me: Me?
111 let home: HomeData?
112 let transport: NativeTransport?
113 let actions: BaseActions
114 let close: () -> Void
115 @Environment(\.colorScheme) private var scheme
116 @Environment(\.dynamicTypeSize) private var typeSize
117
118 public init(me: Me?, home: HomeData?, transport: NativeTransport?, actions: BaseActions, close: @escaping () -> Void) {
119 self.me = me; self.home = home; self.transport = transport; self.actions = actions; self.close = close
120 }
121
122 public var body: some View {
123 let p = Palette(scheme)
124 ScrollView {
125 VStack(alignment: .leading, spacing: 14) {
126 HStack(spacing: 10) {
127 Text(verbatim: me?.base.name ?? "").font(BaseFont.heading(20, .semibold, relativeTo: .title3))
128 .accessibilityAddTraits(.isHeader)
129 Spacer()
130 Button(action: close) {
131 Icon(.close).frame(width: 18, height: 18).frame(width: 36, height: 36)
132 .background(p[.chip], in: Circle()).overlay { Circle().strokeBorder(p[.chipEdge], lineWidth: 1) }
133 .frame(width: 44, height: 44).contentShape(Circle())
134 }
135 .buttonStyle(.plain)
136 .accessibilityLabel(Text(BaseText.text("native.phone.apps.close_a11y")))
137 }
138 if let home, home.stepsOpen {
139 FlowLayout(spacing: 6) {
140 ForEach(home.steps, id: \.self) { step in
141 HStack(spacing: 8) {
142 StepDot(done: step.done, size: 18)
143 Text(verbatim: step.label).font(BaseFont.body(13, relativeTo: .footnote))
144 }
145 .padding(.vertical, 7).padding(.horizontal, 11)
146 .glass(cornerRadius: 12)
147 .accessibilityElement(children: .combine)
148 .accessibilityAddTraits(step.done ? .isSelected : [])
149 }
150 }
151 }
152 if let home {
153 grid(home.launchable)
154 grid(home.own)
155 }
156 }
157 .padding(.horizontal, 18).padding(.top, 20).padding(.bottom, 24)
158 }
159 .foregroundStyle(p[.frost])
160 .background(p[.menuBase])
161 }
162
163 private func grid(_ apps: [HomeData.App]) -> some View {
164 let columns = typeSize.isAccessibilitySize ? 2 : 4
165 return LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 0, alignment: .top), count: columns), spacing: 16) {
166 ForEach(apps) { app in
167 Button { actions.open(app) } label: {
168 VStack(spacing: 6) {
169 AppIcon(app, size: 60, transport: transport)
170 Text(verbatim: app.name).font(BaseFont.body(12, .medium, relativeTo: .caption))
171 .lineLimit(2).multilineTextAlignment(.center)
172 }
173 .frame(maxWidth: .infinity)
174 .contentShape(Rectangle())
175 }
176 .buttonStyle(.plain)
177 .accessibilityLabel(Text(verbatim: app.name))
178 }
179 }
180 }
181}
182