Feature: Notes creation
This commit is contained in:
+19
-14
@@ -9,24 +9,29 @@ import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
@AppStorage("peered_username") private var username: String = ""
|
||||
@State var browser: CommunicationProvider? = nil
|
||||
|
||||
@State private var notes = [Note]()
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if let browser {
|
||||
ForEach(browser.availablePeers, id: \.displayName) { peer in
|
||||
Text(peer.displayName)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
NavigationView {
|
||||
List(notes) { note in
|
||||
NavigationLink(note.name) {
|
||||
NoteEditorScreen(note: note)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Peered")
|
||||
.toolbar {
|
||||
Button("Create note") {
|
||||
NotesStorage().createNote(name: "New Note")
|
||||
notes = NotesStorage().loadNotes()
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
notes = NotesStorage().loadNotes()
|
||||
}
|
||||
.sheet(isPresented: .constant(username.isEmpty)) {
|
||||
SetUserNameBottomSheetView(username: $username)
|
||||
}
|
||||
.onChange(of: username) { _, newValue in
|
||||
guard !newValue.isEmpty else { return }
|
||||
browser = .init(id: newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user