Feature: Notes creation
This commit is contained in:
@@ -266,8 +266,19 @@
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEVELOPMENT_TEAM = LTFJ368N25;
|
||||
ENABLE_APP_SANDBOX = YES;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
ENABLE_INCOMING_NETWORK_CONNECTIONS = NO;
|
||||
ENABLE_OUTGOING_NETWORK_CONNECTIONS = NO;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
ENABLE_RESOURCE_ACCESS_AUDIO_INPUT = NO;
|
||||
ENABLE_RESOURCE_ACCESS_BLUETOOTH = NO;
|
||||
ENABLE_RESOURCE_ACCESS_CALENDARS = NO;
|
||||
ENABLE_RESOURCE_ACCESS_CAMERA = NO;
|
||||
ENABLE_RESOURCE_ACCESS_CONTACTS = NO;
|
||||
ENABLE_RESOURCE_ACCESS_LOCATION = NO;
|
||||
ENABLE_RESOURCE_ACCESS_PRINTING = NO;
|
||||
ENABLE_RESOURCE_ACCESS_USB = NO;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = Peered/Info.plist;
|
||||
INFOPLIST_KEY_NSLocalNetworkUsageDescription = "";
|
||||
@@ -309,8 +320,19 @@
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEVELOPMENT_TEAM = LTFJ368N25;
|
||||
ENABLE_APP_SANDBOX = YES;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
ENABLE_INCOMING_NETWORK_CONNECTIONS = NO;
|
||||
ENABLE_OUTGOING_NETWORK_CONNECTIONS = NO;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
ENABLE_RESOURCE_ACCESS_AUDIO_INPUT = NO;
|
||||
ENABLE_RESOURCE_ACCESS_BLUETOOTH = NO;
|
||||
ENABLE_RESOURCE_ACCESS_CALENDARS = NO;
|
||||
ENABLE_RESOURCE_ACCESS_CAMERA = NO;
|
||||
ENABLE_RESOURCE_ACCESS_CONTACTS = NO;
|
||||
ENABLE_RESOURCE_ACCESS_LOCATION = NO;
|
||||
ENABLE_RESOURCE_ACCESS_PRINTING = NO;
|
||||
ENABLE_RESOURCE_ACCESS_USB = NO;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = Peered/Info.plist;
|
||||
INFOPLIST_KEY_NSLocalNetworkUsageDescription = "";
|
||||
|
||||
+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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// NoteEditorScreen.swift
|
||||
// Peered
|
||||
//
|
||||
// Created by Oskar Chybowski on 25/09/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct NoteEditorScreen: View {
|
||||
let note: Note
|
||||
|
||||
var body: some View {
|
||||
TextEditor(text: .constant("eee"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// Note.swift
|
||||
// Peered
|
||||
//
|
||||
// Created by Oskar Chybowski on 25/09/2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct Note: Identifiable {
|
||||
var id: URL { path }
|
||||
|
||||
let name: String
|
||||
let path: URL
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// NotesStorage.swift
|
||||
// Peered
|
||||
//
|
||||
// Created by Oskar Chybowski on 25/09/2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct NotesStorage {
|
||||
let storageProvider: FileManager = FileManager.default
|
||||
|
||||
func loadNotes() -> [Note] {
|
||||
let files = try! storageProvider.contentsOfDirectory(atPath: URL.documentsDirectory.path)
|
||||
var notes = [Note]()
|
||||
|
||||
for file in files.compactMap(URL.init) {
|
||||
let name = file.lastPathComponent
|
||||
let note = Note(
|
||||
name: name,
|
||||
path: file
|
||||
)
|
||||
|
||||
notes.append(note)
|
||||
}
|
||||
|
||||
return notes
|
||||
}
|
||||
|
||||
func createNote(name: String) {
|
||||
let currentNotes = loadNotes()
|
||||
var proposedName = name
|
||||
var index: Int? = nil
|
||||
|
||||
while currentNotes.contains(where: { $0.name == proposedName }) {
|
||||
if let _index = index {
|
||||
index = _index + 1
|
||||
} else {
|
||||
index = 1
|
||||
}
|
||||
}
|
||||
|
||||
proposedName = if let index {
|
||||
"\(proposedName) \(index)"
|
||||
} else {
|
||||
proposedName
|
||||
}
|
||||
let pathToWrite = URL.documentsDirectory.appendingPathComponent(proposedName).appendingPathExtension(for: .text)
|
||||
try! String().write(to: pathToWrite, atomically: true, encoding: .utf8)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user