move Peered to implementation directory

This commit is contained in:
2026-03-12 11:01:05 +01:00
parent d7497e2614
commit 9ab7e0bdd0
24 changed files with 22 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
//
// ContentView.swift
// Peered
//
// Created by Oskar Chybowski on 11/05/2025.
//
import SwiftUI
extension EnvironmentValues {
@Entry var ownPeer: OwnPeer = .fallback
}
struct ContentView: View {
@AppStorage("peered_username") private var username: String = "fallback_user"
@State private var notes = [Note]()
@State private var notesClient: NoteEditingSessionClient?
@State private var ownPeer: OwnPeer?
var body: some View {
NavigationStack {
List {
Section("Your notes") {
ForEach(notes) { note in
NavigationLink(note.name) {
let peer = ownPeer ?? .init(peer: .init(displayName: username))
if ownPeer == nil {
ownPeer = peer
}
return NoteEditorScreen(note: note, peer: peer)
}
}
}
if let notesClient {
Section("External notes") {
ForEach(notesClient.invitations) { invitation in
NavigationLink(invitation.noteName) {
SharedNoteEditor(invitation: invitation, noteClient: notesClient)
}
}
}
}
}
.environment(\.ownPeer, ownPeer ?? .fallback)
.navigationTitle("Peered")
.toolbar {
Button("Create note") {
NotesStorage().createNote(name: "New Note")
notes = NotesStorage().loadNotes()
}
}
}
.onAppear {
notes = NotesStorage().loadNotes()
if notesClient == nil {
notesClient = .init(peer: .init(displayName: username))
}
notesClient?.startBrowsingForNotes()
}
.sheet(isPresented: .constant(username == "fallback_user" || username.isEmpty)) {
SetUserNameBottomSheetView(username: $username)
}
}
}
#Preview {
ContentView()
}