Refactor project, add loading/editing/saving notes, add client/server basic logic

This commit is contained in:
2025-10-05 23:23:19 +02:00
parent 209e08754b
commit 58ad4d47fd
5 changed files with 130 additions and 4 deletions
+25 -1
View File
@@ -9,8 +9,32 @@ import SwiftUI
struct NoteEditorScreen: View {
let note: Note
@State private var noteAdvertiser: NoteEditingSessionServer
@State private var noteContent: String = ""
@State private var timer = Timer.publish(every: 5, on: .current, in: .common)
.autoconnect()
init(note: Note, username: String) {
self.note = note
self._noteAdvertiser = .init(wrappedValue: .init(username: username))
}
var body: some View {
TextEditor(text: .constant("eee"))
TextEditor(text: $noteContent)
.onAppear {
noteContent = try! String(contentsOf: note.path, encoding: .utf8)
noteAdvertiser.startServer()
}
.onDisappear {
noteAdvertiser.stopServer()
saveNote()
}
.onReceive(timer) { _ in
saveNote()
}
}
func saveNote() {
try! noteContent.write(to: note.path, atomically: true, encoding: .utf8)
}
}