Files
dotdenote/Sources/Views/NoteEditorView.swift
andros 340770861e Apply theme background colors to NoteListView, NoteDetailView, NoteEditorView
Each view now uses themeManager.current.background and secondaryBackground explicitly, matching the pattern in SetupView. preferredColorScheme alone only toggles system dark/light — specific hex colors require explicit background modifiers.
2026-05-26 11:49:01 +02:00

63 lines
2.1 KiB
Swift

import SwiftUI
struct NoteEditorView: View {
@EnvironmentObject var client: WebDAVClient
let note: DenoteNote
@Environment(\.dismiss) private var dismiss
@State private var editedContent: String
@State private var isSaving = false
@State private var saveError: String?
@State private var themeManager = ThemeManager.shared
init(note: DenoteNote) {
self.note = note
_editedContent = State(initialValue: note.content ?? "")
}
var body: some View {
NavigationStack {
TextEditor(text: $editedContent)
.font(.system(.body, design: .monospaced))
.scrollContentBackground(.hidden)
.background(themeManager.current.background)
.padding(4)
.navigationTitle(note.displayTitle)
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(themeManager.current.secondaryBackground, for: .navigationBar)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Cancel") { dismiss() }
}
ToolbarItem(placement: .confirmationAction) {
if isSaving {
ProgressView()
} else {
Button("Save") { Task { await save() } }
}
}
}
.alert("Save failed", isPresented: Binding(
get: { saveError != nil },
set: { if !$0 { saveError = nil } }
)) {
Button("OK") { saveError = nil }
} message: {
Text(saveError ?? "")
}
}
.preferredColorScheme(themeManager.current.colorScheme)
.tint(themeManager.current.accent)
}
private func save() async {
isSaving = true
do {
try await client.saveContent(editedContent, for: note)
dismiss()
} catch {
saveError = error.localizedDescription
}
isSaving = false
}
}