move Peered to implementation directory
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// NoteEditorScreen.swift
|
||||
// Peered
|
||||
//
|
||||
// Created by Oskar Chybowski on 25/09/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import MultipeerConnectivity
|
||||
|
||||
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()
|
||||
@State private var showManageMembers = false
|
||||
|
||||
init(note: Note, peer: OwnPeer) {
|
||||
self.note = note
|
||||
self._noteAdvertiser = .init(initialValue: .init(peer: peer))
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
TextEditor(text: $noteContent)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .primaryAction) {
|
||||
Button("Manage members") {
|
||||
showManageMembers = true
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showManageMembers) {
|
||||
NavigationStack {
|
||||
ManageMembersView(
|
||||
noteAdvertiser: noteAdvertiser,
|
||||
noteTitle: note.name,
|
||||
noteContent: $noteContent
|
||||
)
|
||||
}
|
||||
}
|
||||
.onReceive(noteAdvertiser.noteChangesEmitter) { updatedNote in
|
||||
self.noteContent = updatedNote
|
||||
}
|
||||
.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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user