Jotley / app · jotley.ai / iOS / Views / iOSNoteRowView.swift
| 1 | import SwiftUI |
| 2 | import UIKit |
| 3 | |
| 4 | struct NoteRowView: View { |
| 5 | @ObservedObject var note: Note |
| 6 | var isSelected: Bool = false |
| 7 | @ObservedObject private var themeManager = ThemeManager.shared |
| 8 | @EnvironmentObject private var transcriptionManager: LiveTranscriptionManager |
| 9 | @Environment(\.colorScheme) var colorScheme |
| 10 | @ScaledMetric(relativeTo: .subheadline) private var phoneTitleSize = 17 |
| 11 | @ScaledMetric(relativeTo: .footnote) private var phonePreviewSize = 15 |
| 12 | |
| 13 | private var isPhone: Bool { UIDevice.current.userInterfaceIdiom == .phone } |
| 14 | |
| 15 | private var hasRenderedSummary: Bool { |
| 16 | guard let summary = note.summary?.trimmingCharacters(in: .whitespacesAndNewlines) else { |
| 17 | return false |
| 18 | } |
| 19 | return !summary.isEmpty && |
| 20 | summary != "Generating summary..." && |
| 21 | summary != "Transcription in progress..." |
| 22 | } |
| 23 | |
| 24 | private var hasUsableTranscription: Bool { |
| 25 | let transcription = note.transcription?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" |
| 26 | |
| 27 | guard !transcription.isEmpty else { return false } |
| 28 | |
| 29 | return transcription != "Transcribing audio..." && |
| 30 | transcription != "Loading transcript..." && |
| 31 | transcription != "Loading content..." && |
| 32 | transcription != "Transcription in progress..." && |
| 33 | !transcription.hasPrefix("Transcription failed:") |
| 34 | } |
| 35 | |
| 36 | private var shouldShowGeneratingIcon: Bool { transcriptionManager.summaryNoteID == note.id } |
| 37 | |
| 38 | @ViewBuilder |
| 39 | private var statusIconView: some View { |
| 40 | if shouldShowGeneratingIcon { |
| 41 | Image(systemName: "arrow.triangle.2.circlepath") |
| 42 | .font(.caption2.weight(.semibold)) |
| 43 | .foregroundColor(.themePrimaryAccent) |
| 44 | .accessibilityIdentifier("noteRowGeneratingIcon") |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /// Get a preview snippet from summary or transcription. |
| 49 | private var previewText: String { |
| 50 | if hasRenderedSummary, let summary = note.summary { |
| 51 | return summary.previewSnippet() |
| 52 | } else if hasUsableTranscription, let transcription = note.transcription { |
| 53 | return transcription.previewSnippet() |
| 54 | } |
| 55 | return "" |
| 56 | } |
| 57 | |
| 58 | var body: some View { |
| 59 | VStack(alignment: .leading, spacing: isPhone ? 4 : 2) { |
| 60 | // Title - bold like Apple Notes |
| 61 | Text(note.title ?? "Untitled") |
| 62 | .font(isPhone ? .system(size: phoneTitleSize, weight: .semibold) : .subheadline.weight(.semibold)) |
| 63 | .foregroundColor(Color.themeTextPrimary) |
| 64 | .lineLimit(1) |
| 65 | .accessibilityIdentifier("noteRowTitle") |
| 66 | |
| 67 | // Date and preview on same line, like Apple Notes |
| 68 | HStack(spacing: 6) { |
| 69 | Text(note.timestamp ?? Date(), style: hasRenderedSummary ? .time : .date) |
| 70 | .font(isPhone ? .system(size: phonePreviewSize) : .footnote) |
| 71 | .foregroundColor(Color.themeTextSecondary) |
| 72 | .accessibilityIdentifier("noteRowTimestamp") |
| 73 | |
| 74 | statusIconView |
| 75 | |
| 76 | if !previewText.isEmpty { |
| 77 | Text(previewText) |
| 78 | .font(isPhone ? .system(size: phonePreviewSize) : .footnote) |
| 79 | .foregroundColor(Color.themeTextSecondary.opacity(0.8)) |
| 80 | .lineLimit(1) |
| 81 | |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | .accessibilityIdentifier("noteRow") |
| 86 | .frame(maxWidth: .infinity, alignment: .leading) |
| 87 | .padding(.horizontal, 12) |
| 88 | .padding(.vertical, isPhone ? 10 : 8) |
| 89 | .jotleyNoteSelection(isSelected, unselectedBackground: .themeContentBackground) |
| 90 | .contentShape(RoundedRectangle(cornerRadius: 8)) |
| 91 | } |
| 92 | } |