Jotley / app / macOS / Views / NotesListView+Helpers.swift
| 1 | import SwiftUI |
| 2 | |
| 3 | extension NotesListView { |
| 4 | func getAllUniqueTags() -> [String] { |
| 5 | var allTags = Set<String>() |
| 6 | for note in notes { |
| 7 | allTags.formUnion(note.tagNames) |
| 8 | } |
| 9 | return Array(allTags).sorted() |
| 10 | } |
| 11 | |
| 12 | /// Count tags within search-matched notes, independent of selected tag filters. |
| 13 | func getTagCountsForVisibleResults() -> [String: Int] { |
| 14 | var counts: [String: Int] = [:] |
| 15 | for note in notes where noteMatchesSearch(note) { |
| 16 | // Avoid double counting if a note somehow stores duplicate tag values. |
| 17 | for tag in Set(note.tagNames) { |
| 18 | counts[tag, default: 0] += 1 |
| 19 | } |
| 20 | } |
| 21 | return counts |
| 22 | } |
| 23 | |
| 24 | // Helper struct to simplify type-checking by breaking up complex expressions |
| 25 | struct NoteRowView: View { |
| 26 | let note: Note |
| 27 | let isSelected: Bool |
| 28 | let toggleSelection: (Note, Bool) -> Void |
| 29 | let prepareDelete: (Note) -> Void |
| 30 | let rowIndex: Int |
| 31 | let isRecordingNote: Bool |
| 32 | @Environment(\.colorScheme) private var colorScheme |
| 33 | |
| 34 | private var recordingBadgeIconColor: Color { |
| 35 | Color.themePrimaryAccent |
| 36 | } |
| 37 | |
| 38 | private var recordingBadgeBackgroundColor: Color { |
| 39 | Color.white.opacity(colorScheme == .dark ? 0.95 : 1.0) |
| 40 | } |
| 41 | |
| 42 | var body: some View { |
| 43 | Button(action: { |
| 44 | // This captures the current key modifiers from the global NSEvent |
| 45 | let modifiers = NSEvent.modifierFlags |
| 46 | let isCommandPressed = modifiers.contains(.command) |
| 47 | toggleSelection(note, isCommandPressed) |
| 48 | }) { |
| 49 | NoteListRowView( |
| 50 | note: note, |
| 51 | isSelected: isSelected, |
| 52 | onDelete: { prepareDelete(note) } |
| 53 | ) |
| 54 | .padding(.horizontal, 16) |
| 55 | .contentShape(Rectangle()) |
| 56 | } |
| 57 | .buttonStyle(PlainButtonStyle()) |
| 58 | .tint(Color.themePrimaryAccent) |
| 59 | .accessibilityIdentifier("notesListNoteRow-\(rowIndex)") |
| 60 | .overlay(alignment: .bottom) { |
| 61 | if !isSelected { |
| 62 | Rectangle() |
| 63 | .fill(Color.primary.opacity(colorScheme == .dark ? 0.18 : 0.13)) |
| 64 | .frame(height: 1) |
| 65 | .padding(.leading, 28) |
| 66 | .padding(.trailing, 16) |
| 67 | .allowsHitTesting(false) |
| 68 | } |
| 69 | } |
| 70 | .overlay(alignment: .topTrailing) { |
| 71 | if isRecordingNote { |
| 72 | ZStack { |
| 73 | Circle() |
| 74 | .fill(recordingBadgeBackgroundColor) |
| 75 | .frame(width: 15, height: 15) |
| 76 | |
| 77 | Image(systemName: "mic.fill") |
| 78 | .symbolRenderingMode(.monochrome) |
| 79 | .font(.system(size: 8, weight: .bold)) |
| 80 | .foregroundColor(recordingBadgeIconColor) |
| 81 | } |
| 82 | .overlay( |
| 83 | Circle() |
| 84 | .stroke(Color.themePrimaryAccent, lineWidth: 0.8) |
| 85 | ) |
| 86 | .shadow(color: Color.black.opacity(colorScheme == .dark ? 0.4 : 0.18), radius: 2, x: 0, y: 1) |
| 87 | .padding(.top, 5) |
| 88 | .padding(.trailing, 20) |
| 89 | .offset(x: 4, y: 4) |
| 90 | .zIndex(10) |
| 91 | .help("Active transcription") |
| 92 | .accessibilityIdentifier("activeRecordingRowIcon") |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | } |