Jotley / app / macOS / Views / NoteDetailPlaceholderView.swift
| 1 | import SwiftUI |
| 2 | import CoreData // For Note, NSManagedObjectID |
| 3 | import AppKit // For NSImage, NSSavePanel |
| 4 | import UniformTypeIdentifiers // For UTType in export |
| 5 | |
| 6 | // This file now serves as the entry point for the view |
| 7 | // Split the view into smaller parts to reduce complexity |
| 8 | struct NoteDetailPlaceholderView: View { |
| 9 | // Keep the Note as ObservedObject to track its changes |
| 10 | @ObservedObject private var themeManager = ThemeManager.shared |
| 11 | @ObservedObject var note: Note |
| 12 | @Environment(\.managedObjectContext) var viewContext |
| 13 | var isGeneratingThisSummary: Bool { viewModel.isGeneratingSummary && viewModel.generatingSummaryNoteID == note.objectID } |
| 14 | @AppStorage(kJotleyObsidianSyncFolderBookmarkDefaultsKey) var obsidianSyncFolderBookmarkData: Data? |
| 15 | @AppStorage("preferCleanedTranscript") var preferCleanedTranscript: Bool = false // Make transcript view preference persistent |
| 16 | @Binding var selectedTab: Int // Raw value of DetailTab |
| 17 | @ObservedObject var viewModel: NotesListViewModel |
| 18 | @EnvironmentObject var persistenceController: SharedPersistenceController |
| 19 | |
| 20 | @AppStorage("showTags") var showTags: Bool = false |
| 21 | |
| 22 | // Original properties to maintain app functionality |
| 23 | @Namespace var transcriptionFooterNamespace |
| 24 | @State var transcriptFollow = MacTranscriptFollowState() |
| 25 | @State var showActionsPopover: Bool = false |
| 26 | @State var showingAskAI = false |
| 27 | @State var isEditingTranscript = false |
| 28 | @State var showObsidianSaveAlert = false |
| 29 | @State var obsidianAlertTitle = "" |
| 30 | @State var obsidianAlertMessage = "" |
| 31 | @State var manualTitle: String = "" |
| 32 | @State var summaryGenerationError: String? = nil |
| 33 | |
| 34 | // New state for template selection |
| 35 | @ObservedObject var templateCatalog = SummaryTemplateStore.shared |
| 36 | @State var templatePresentation: SummaryTemplatePresentation? |
| 37 | @State var showsSummaryTemplatePicker = false |
| 38 | var availableTemplates: [Template] { |
| 39 | templateCatalog.definitions.map { Template(key: $0.key, title: $0.title, description: $0.prompt, category: $0.isCustom ? "My Templates" : LocalSummaryTemplate.resolve($0.key).category) } |
| 40 | } |
| 41 | |
| 42 | // New state to hold the template key selected from the popover |
| 43 | @State var selectedTemplateKeyForAction: String = "default-summary" // Default to auto/default |
| 44 | // Track the currently selected template for display |
| 45 | @State var currentSelectedTemplate: Template? = nil |
| 46 | |
| 47 | // New state variables for editable summary and transcript |
| 48 | @State var editableSummary: String = "" |
| 49 | @State var savedSummary: String = "" |
| 50 | @FocusState var isSummaryEditorFocused: Bool |
| 51 | @State var summaryInlineEditRequestCounter: Int = 0 |
| 52 | @State var editableTranscript: String = "" |
| 53 | @State var savedTranscript: String = "" |
| 54 | @FocusState var isTranscriptEditorFocused: Bool |
| 55 | // Tracks which note `editableTranscript` currently reflects. Used to tell a |
| 56 | // genuine note switch apart from a loading placeholder resurfacing over a |
| 57 | // real transcript on the SAME note (a CloudKit store-trump merge echo), so |
| 58 | // the resurface guard never copies one note's transcript onto another. |
| 59 | @State var editableTranscriptNoteID: NSManagedObjectID? = nil |
| 60 | |
| 61 | // State for Tags |
| 62 | @State var currentTags: [String] = [] |
| 63 | @State var isEditingTags: Bool = false |
| 64 | @State var isTagsExpanded: Bool = false |
| 65 | @State var newTagText: String = "" |
| 66 | @State var showAddTagPopover: Bool = false |
| 67 | |
| 68 | // Add a refresh ID to force view updates when needed |
| 69 | @State var viewRefreshID = UUID() |
| 70 | |
| 71 | // State for Markdown view mode |
| 72 | @State var showRawMarkdown: Bool = false |
| 73 | // Per-tab markdown/rendered state |
| 74 | @State var showRawMarkdownSummary: Bool = false // Default: Rendered |
| 75 | |
| 76 | // Animation state for sparkle spinner |
| 77 | |
| 78 | // Animation state for transcript loading spinner |
| 79 | |
| 80 | // State for toolbar button positions |
| 81 | @State var hasSimulatedStoppedRecordingFlowForUITests = false |
| 82 | |
| 83 | // Timers for debounced saving |
| 84 | @State var summarySaveTimer: Timer? |
| 85 | @State var transcriptSaveTimer: Timer? |
| 86 | var body: some View { |
| 87 | contentWithAlerts |
| 88 | } |
| 89 | } |