forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiveNotesView.swift
More file actions
321 lines (275 loc) · 8.68 KB
/
Copy pathLiveNotesView.swift
File metadata and controls
321 lines (275 loc) · 8.68 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
import OmiTheme
import SwiftUI
enum LiveNotesEscapeHandling {
static func shouldCancelEdit(editingNoteId: Int64?) -> Bool {
editingNoteId != nil
}
}
/// Live notes view showing AI-generated and manual notes during recording
struct LiveNotesView: View {
@ObservedObject var monitor: LiveNotesMonitor = .shared
/// Text for manual note input
@State private var manualNoteText: String = ""
/// Currently editing note ID
@State private var editingNoteId: Int64?
/// Edit text buffer
@State private var editText: String = ""
/// Focus state for manual input
@FocusState private var isInputFocused: Bool
var body: some View {
VStack(spacing: 0) {
// Header with AI toggle
headerView
// `GlassSeparator`, not `Divider().background(_:)`: a `Divider` resolves against the host
// window's appearance rather than the panel's pinned light one.
GlassSeparator()
// Notes list
if monitor.notes.isEmpty {
emptyStateView
} else {
notesListView
}
// Manual note input
manualInputView
}
// No background: the glass owns the ground. This used to paint `backgroundSecondary` over it.
.glassContent()
.onEscapeKey(priority: .editing) {
guard LiveNotesEscapeHandling.shouldCancelEdit(editingNoteId: editingNoteId) else { return false }
cancelEdit()
return true
}
}
// MARK: - Header
private var headerView: some View {
HStack {
Text("Notes")
.scaledFont(size: OmiType.body, weight: .semibold)
.foregroundColor(Ink.primary)
Spacer()
// AI toggle
HStack(spacing: OmiSpacing.xs) {
Image(systemName: "sparkles")
.scaledFont(size: OmiType.caption)
.foregroundColor(monitor.isAiEnabled ? Ink.primary : Ink.secondary)
Toggle("", isOn: $monitor.isAiEnabled)
.toggleStyle(OmiToggleStyle())
.scaleEffect(0.7)
.frame(width: 40)
}
// Generating indicator
if monitor.isGenerating {
ProgressView()
.scaleEffect(0.6)
.frame(width: 16, height: 16)
}
}
.padding(.horizontal, OmiSpacing.md)
.padding(.vertical, OmiSpacing.sm)
}
// MARK: - Empty State
private var emptyStateView: some View {
// The shared empty state rather than a fourth hand-built one — it already carries the glyph
// size and the two rungs glass allows.
GlassEmptyState(
systemImage: "note.text",
title: "Notes will appear here",
message: monitor.isAiEnabled ? "AI generates notes as you speak" : nil
)
}
// MARK: - Notes List
private var notesListView: some View {
ScrollViewReader { proxy in
ScrollView {
LazyVStack(alignment: .leading, spacing: OmiSpacing.sm) {
ForEach(monitor.notes) { note in
NoteRowView(
note: note,
isEditing: editingNoteId == note.id,
editText: $editText,
onStartEdit: { startEditing(note) },
onSaveEdit: { saveEdit(note) },
onCancelEdit: { cancelEdit() },
onDelete: { deleteNote(note) }
)
.id(note.id)
}
}
.padding(OmiSpacing.md)
}
.onChange(of: monitor.notes.count) { _, _ in
// Auto-scroll to latest note
if let lastNote = monitor.notes.last {
OmiMotion.withGated(.easeOut(duration: 0.2)) {
proxy.scrollTo(lastNote.id, anchor: .bottom)
}
}
}
}
}
// MARK: - Manual Input
private var manualInputView: some View {
VStack(spacing: 0) {
GlassSeparator()
HStack(spacing: OmiSpacing.sm) {
TextField("Add a note...", text: $manualNoteText)
.textFieldStyle(.plain)
.scaledFont(size: OmiType.body)
.foregroundColor(Ink.primary)
.focused($isInputFocused)
.onSubmit {
addManualNote()
}
Button(action: addManualNote) {
Image(systemName: "plus.circle.fill")
.scaledFont(size: OmiType.heading)
.foregroundColor(manualNoteText.isEmpty ? Ink.secondary : Ink.primary)
}
.buttonStyle(.plain)
.disabled(manualNoteText.isEmpty)
}
.padding(.horizontal, OmiSpacing.md)
.padding(.vertical, OmiSpacing.sm)
// A wash, not a fill: the composer strip reads as a shade of the glass it sits on.
.background(Ink.rowFill)
}
}
// MARK: - Actions
private func addManualNote() {
let text = manualNoteText.trimmingCharacters(in: .whitespacesAndNewlines)
guard !text.isEmpty else { return }
monitor.addManualNote(text: text)
manualNoteText = ""
}
private func startEditing(_ note: LiveNote) {
editingNoteId = note.id
editText = note.text
}
private func saveEdit(_ note: LiveNote) {
let text = editText.trimmingCharacters(in: .whitespacesAndNewlines)
guard !text.isEmpty else {
cancelEdit()
return
}
monitor.updateNote(id: note.id, text: text)
cancelEdit()
}
private func cancelEdit() {
editingNoteId = nil
editText = ""
}
private func deleteNote(_ note: LiveNote) {
monitor.deleteNote(id: note.id)
}
}
// MARK: - Note Row View
private struct NoteRowView: View {
let note: LiveNote
let isEditing: Bool
@Binding var editText: String
let onStartEdit: () -> Void
let onSaveEdit: () -> Void
let onCancelEdit: () -> Void
let onDelete: () -> Void
@State private var isHovering = false
@FocusState private var isEditFocused: Bool
private static let timeFormatter: DateFormatter = {
let f = DateFormatter()
f.dateFormat = "h:mm a"
return f
}()
private var formattedTime: String {
Self.timeFormatter.string(from: note.timestamp)
}
var body: some View {
HStack(alignment: .top, spacing: OmiSpacing.sm) {
// AI indicator
if note.isAiGenerated {
Image(systemName: "sparkles")
.scaledFont(size: OmiType.micro)
.foregroundColor(Ink.primary)
.frame(width: 14)
} else {
Image(systemName: "pencil")
.scaledFont(size: OmiType.micro)
.foregroundColor(Ink.secondary)
.frame(width: 14)
}
VStack(alignment: .leading, spacing: OmiSpacing.xxs) {
if isEditing {
// Edit mode
TextField("", text: $editText)
.textFieldStyle(.plain)
.scaledFont(size: OmiType.body)
.foregroundColor(Ink.primary)
.focused($isEditFocused)
.onSubmit { onSaveEdit() }
.onAppear { isEditFocused = true }
.onExitCommand { onCancelEdit() }
} else {
// Display mode
Text(note.text)
.scaledFont(size: OmiType.body)
.foregroundColor(Ink.primary)
.lineLimit(nil)
.onTapGesture(count: 2) {
onStartEdit()
}
}
// Timestamp
Text(formattedTime)
.scaledFont(size: OmiType.micro)
.foregroundColor(Ink.secondary)
}
Spacer()
// Action buttons (visible on hover or editing)
if isHovering || isEditing {
HStack(spacing: OmiSpacing.xxs) {
if isEditing {
Button(action: onSaveEdit) {
Image(systemName: "checkmark")
.scaledFont(size: OmiType.caption)
.foregroundColor(Ink.listeningGreen)
}
.buttonStyle(.plain)
Button(action: onCancelEdit) {
Image(systemName: "xmark")
.scaledFont(size: OmiType.caption)
.foregroundColor(Ink.secondary)
}
.buttonStyle(.plain)
} else {
Button(action: onStartEdit) {
Image(systemName: "pencil")
.scaledFont(size: OmiType.caption)
.foregroundColor(Ink.secondary)
}
.buttonStyle(.plain)
Button(action: onDelete) {
Image(systemName: "trash")
.scaledFont(size: OmiType.caption)
.foregroundColor(Ink.errorRed)
}
.buttonStyle(.plain)
}
}
}
}
.padding(.horizontal, OmiSpacing.sm)
.padding(.vertical, OmiSpacing.sm)
// The shared row, which already resolves rest/hover to the glass washes and animates colour
// only. Editing outranks hover so an edited row under the pointer does not dim back a step.
.glassRow(isEditing ? .selected : (isHovering ? .hover : .rest))
.onHover { hovering in
isHovering = hovering
}
}
}
// MARK: - Preview
#if canImport(PreviewsMacros)
#Preview {
LiveNotesView()
.frame(width: 300, height: 500)
.inkGlassPanel()
}
#endif