Note Sharing, distributing updates
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// SharedNoteEditor.swift
|
||||
// Peered
|
||||
//
|
||||
// Created by Oskar Chybowski on 07/10/2025.
|
||||
//
|
||||
import SwiftUI
|
||||
|
||||
struct SharedNoteEditor: View {
|
||||
@State var note: String?
|
||||
@State var sendTask: Task<Void, Never>?
|
||||
@State var invitation: NoteInvitation
|
||||
@Bindable var noteClient: NoteEditingSessionClient
|
||||
|
||||
init(
|
||||
invitation: NoteInvitation,
|
||||
noteClient: NoteEditingSessionClient
|
||||
) {
|
||||
self._invitation = .init(initialValue: invitation)
|
||||
self._noteClient = .init(noteClient)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
if let note = Binding($note) {
|
||||
TextEditor(text: note)
|
||||
} else {
|
||||
ProgressView {
|
||||
Text("Fetching note...")
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: note) { _, newValue in
|
||||
sendTask?.cancel()
|
||||
sendTask = Task {
|
||||
try? await Task.sleep(nanoseconds: 500000000)
|
||||
guard let note else { return }
|
||||
DispatchQueue.main.async {
|
||||
noteClient.send(note: note, to: invitation.invitatorID)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
invitation.accept()
|
||||
note = invitation.note.noteSnapshot
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user