forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivityDestinationChip.swift
More file actions
176 lines (157 loc) · 6.57 KB
/
Copy pathActivityDestinationChip.swift
File metadata and controls
176 lines (157 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//
// ActivityDestinationChip.swift — the Activity spine's chip row, and the door it now is.
//
// Activity used to carry two stacked rows of chips: the Memory hub's switcher
// (`Activity | Conversations | Memories | Brain Map`) and, directly beneath it, a filter row
// (`All | Conversations | Memories | Tasks | Rewind`) that narrowed the spine in place. Two rows
// that look alike, one word apart, doing different things is the ambiguity — you cannot tell from
// the row which `Conversations` you are about to press.
//
// So there is one row, and every chip in it navigates. That is the rule the row teaches and the
// rule it keeps: no chip here narrows the list while its neighbour leaves the page. `Brain Map`
// joins it because it is now a peer destination rather than a control hidden in the panel header.
//
// **This value is the reachability claim, not decoration.** `ShellDestination.Reach.activityChipRow`
// names this row as the mechanism that reaches Conversations, Memories and Brain Map now that the
// switcher is gone, and `ShellDestination.unreachable()` checks membership here. The row's `ForEach`
// and the invariant model therefore read the same list — a destination dropped from this enum is a
// test failure rather than a page someone discovers is stranded.
//
import OmiTheme
import SwiftUI
/// One chip in Activity's row. Every case is a destination; none is a filter.
enum ActivityDestinationChip: String, CaseIterable, Identifiable {
case activity
case conversations
case memories
case rewind
case brainMap
var id: String { rawValue }
var title: String {
switch self {
case .activity: return "Activity"
case .conversations: return "Conversations"
case .memories: return "Memories"
case .rewind: return "Rewind"
case .brainMap: return "Brain Map"
}
}
/// The Brain page this chip opens. Tasks stays global because it has its own primary pill. Rewind
/// belongs here because it is another way to inspect captured history.
///
/// **Not optional, and that is the reachability claim's teeth.** A chip that opens no hub page
/// would be a chip that reaches nothing while `reachableHubDestinations` quietly dropped it; the
/// type forbids adding one rather than leaving a test to notice.
var hubDestination: MemoryHubDestination {
switch self {
case .activity: return .activity
case .conversations: return .conversations
case .memories: return .memories
case .rewind: return .rewind
case .brainMap: return .brainMap
}
}
/// Every hub page this row can reach. `ShellDestination.unreachable()` reads exactly this.
static var reachableHubDestinations: [MemoryHubDestination] {
allCases.map(\.hubDestination)
}
}
/// Stable peer navigation for every Brain surface. A section selection is not a drill-in, so this
/// row stays visible instead of making each page manufacture a way back to Activity.
struct BrainSectionNavigation: View {
let selected: MemoryHubDestination
let onSelect: (MemoryHubDestination) -> Void
var body: some View {
ViewThatFits(in: .horizontal) {
navigationRow
ScrollView(.horizontal, showsIndicators: false) {
navigationRow
.padding(.trailing, QueryShellLayout.chipSpacing)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.accessibilityElement(children: .contain)
.accessibilityIdentifier("brain-section-navigation")
}
@ViewBuilder
private var navigationRow: some View {
HStack(spacing: QueryShellLayout.chipSpacing) {
ForEach(ActivityDestinationChip.allCases) { chip in
BrainSectionButton(
title: chip.title,
isActive: chip.hubDestination == selected,
action: { onSelect(chip.hubDestination) }
)
.accessibilityIdentifier("brain-section-\(chip.rawValue)")
}
}
}
}
private struct BrainSectionButton: View {
let title: String
let isActive: Bool
let action: () -> Void
@State private var isHovering = false
var body: some View {
Button(action: action) {
Text(title)
.scaledFont(size: OmiType.caption, weight: isActive ? .semibold : .regular)
.foregroundStyle(GlassShell.controlLabel(isProminent: isActive || isHovering))
.padding(.horizontal, 12)
.frame(height: QueryShellLayout.chipHeight)
.glassChip(isActive: isActive)
}
.buttonStyle(.plain)
.contentShape(Capsule(style: .continuous))
.onHover { isHovering = $0 }
.animation(InkReduceMotion.animation(.easeOut(duration: InkMotion.press)), value: isActive)
.accessibilityAddTraits(isActive ? .isSelected : [])
}
}
/// The shared Brain page shape: the product-wide search surface above a content panel whose first
/// row is Brain navigation. Search stays visually and behaviorally identical to Chat, Tasks, and
/// Apps; section switching belongs to the thing it changes rather than decorating the query field.
struct BrainSectionPageLayout<Search: View, Content: View>: View {
let selected: MemoryHubDestination
let onSelect: (MemoryHubDestination) -> Void
let search: Search
let content: Content
init(
selected: MemoryHubDestination,
onSelect: @escaping (MemoryHubDestination) -> Void,
@ViewBuilder search: () -> Search,
@ViewBuilder content: () -> Content
) {
self.selected = selected
self.onSelect = onSelect
self.search = search()
self.content = content()
}
var body: some View {
GeometryReader { proxy in
let lane = QueryShellLayout.laneWidth(for: proxy.size.width)
VStack(spacing: QueryShellLayout.panelGap) {
search
VStack(alignment: .leading, spacing: 0) {
BrainSectionNavigation(selected: selected, onSelect: onSelect)
.padding(.horizontal, QueryShellLayout.panelPaddingHorizontal)
.padding(.top, BrainSectionPageMetrics.navigationTopPadding)
.padding(.bottom, BrainSectionPageMetrics.navigationBottomPadding)
content
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.inkGlassPanel(cornerRadius: QueryShellLayout.panelCornerRadius, shadow: .ambient)
}
.frame(width: lane)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
.padding(.top, QueryShellLayout.surfaceTopInset)
}
}
}
enum BrainSectionPageMetrics {
static let navigationTopPadding = PagePanelFirstRowMetrics.topPadding
static let navigationBottomPadding = PagePanelVerticalRhythm.rowGap
static let navigationHeight: CGFloat =
QueryShellLayout.chipHeight + navigationTopPadding + navigationBottomPadding
}