application iOS de notes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
notes/Notes/NoteEditorView.swift

69 lines
2.0 KiB

//
// NoteEditorView.swift
// Notes
//
// Created by Claude Code on 13/10/2025.
//
import SwiftUI
import CoreData
struct NoteEditorView: View {
@ObservedObject var note: Note
@Environment(\.managedObjectContext) private var viewContext
@StateObject private var autoSaveManager = AutoSaveManager()
@FocusState private var isFocused: Bool
var body: some View {
VStack {
TextEditor(text: Binding(
get: { note.content ?? "" },
set: { newValue in
note.content = newValue
note.lastEditDate = Date()
autoSaveManager.requestSave {
PersistenceController.shared.save()
}
}
))
.font(.system(size: 18, weight: .regular))
.foregroundColor(Color(UIColor.label))
.padding(8)
.focused($isFocused)
}
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
if let date = note.lastEditDate {
Text("last edit: \(date.formatted())")
.font(.footnote)
.foregroundStyle(.secondary)
.frame(width: 220.0)
}
Spacer()
Button {
isFocused = false
} label: {
Label("Done", systemImage: "text.badge.checkmark")
.labelStyle(.iconOnly)
}
.buttonStyle(.bordered)
.tint(.primary)
}
}
}
}
struct NoteEditorView_Previews: PreviewProvider {
static var previews: some View {
let context = PersistenceController.preview.container.viewContext
let note = Note(context: context)
note.content = "Sample note content\n\nThis is a preview."
note.lastEditDate = Date()
return NoteEditorView(note: note)
.environment(\.managedObjectContext, context)
}
}