format code

This commit is contained in:
2026-05-24 20:40:56 +02:00
parent 2346ca1b49
commit 40e840ee50
12 changed files with 526 additions and 497 deletions
+63 -63
View File
@@ -8,70 +8,70 @@
import SwiftUI
struct AllNotesScreen: View {
@AppStorage("peered_username") private var username: String?
@State private var notes = [Note]()
@State private var notesClient: NoteEditingSessionClient?
@State private var ownPeer: OwnPeer?
var isUsernameValid: Bool {
!(username.map(\.isEmpty) ?? true)
}
var body: some View {
NavigationStack {
List {
Section("Your notes") {
ForEach(notes) { note in
NavigationLink(note.name) {
if let ownPeer {
NoteEditorScreen(note: note, peer: ownPeer)
}
}
}
}
if let notesClient {
Section("External notes") {
ForEach(notesClient.invitations) { invitation in
NavigationLink(invitation.noteName) {
SharedNoteEditor(invitation: invitation, noteClient: notesClient)
}
}
}
}
}
.navigationTitle("Peered")
.toolbar {
Button("Create note") {
NotesStorage().createNote(name: "New Note")
notes = NotesStorage().loadNotes()
}
}
}
.onAppear {
notes = NotesStorage().loadNotes()
if let username, isUsernameValid {
setupSession(username: username)
}
}
.onChange(of: username) { _, newUsername in
guard let newUsername, isUsernameValid else { return }
setupSession(username: newUsername)
}
.sheet(isPresented: .constant(!isUsernameValid)) {
SetUserNameBottomSheetView(username: $username)
}
}
private func setupSession(username: String) {
notesClient?.stopBrowsingForNotes()
let peer = OwnPeer(peer: .init(displayName: username))
ownPeer = peer
notesClient = .init(peer: peer.peer)
notesClient?.startBrowsingForNotes()
}
@AppStorage("peered_username") private var username: String?
@State private var notes = [Note]()
@State private var notesClient: NoteEditingSessionClient?
@State private var ownPeer: OwnPeer?
var isUsernameValid: Bool {
!(username.map(\.isEmpty) ?? true)
}
var body: some View {
NavigationStack {
List {
Section("Your notes") {
ForEach(notes) { note in
NavigationLink(note.name) {
if let ownPeer {
NoteEditorScreen(note: note, peer: ownPeer)
}
}
}
}
if let notesClient {
Section("External notes") {
ForEach(notesClient.invitations) { invitation in
NavigationLink(invitation.noteName) {
SharedNoteEditor(invitation: invitation, noteClient: notesClient)
}
}
}
}
}
.navigationTitle("Peered")
.toolbar {
Button("Create note") {
NotesStorage().createNote(name: "New Note")
notes = NotesStorage().loadNotes()
}
}
}
.onAppear {
notes = NotesStorage().loadNotes()
if let username, isUsernameValid {
setupSession(username: username)
}
}
.onChange(of: username) { _, newUsername in
guard let newUsername, isUsernameValid else { return }
setupSession(username: newUsername)
}
.sheet(isPresented: .constant(!isUsernameValid)) {
SetUserNameBottomSheetView(username: $username)
}
}
private func setupSession(username: String) {
notesClient?.stopBrowsingForNotes()
let peer = OwnPeer(peer: .init(displayName: username))
ownPeer = peer
notesClient = .init(peer: peer.peer)
notesClient?.startBrowsingForNotes()
}
}
#Preview {
AllNotesScreen()
AllNotesScreen()
}