Feature: Notes creation
This commit is contained in:
@@ -266,8 +266,19 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEAD_CODE_STRIPPING = YES;
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEVELOPMENT_TEAM = LTFJ368N25;
|
DEVELOPMENT_TEAM = LTFJ368N25;
|
||||||
|
ENABLE_APP_SANDBOX = YES;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
|
ENABLE_INCOMING_NETWORK_CONNECTIONS = NO;
|
||||||
|
ENABLE_OUTGOING_NETWORK_CONNECTIONS = NO;
|
||||||
ENABLE_PREVIEWS = YES;
|
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;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = Peered/Info.plist;
|
INFOPLIST_FILE = Peered/Info.plist;
|
||||||
INFOPLIST_KEY_NSLocalNetworkUsageDescription = "";
|
INFOPLIST_KEY_NSLocalNetworkUsageDescription = "";
|
||||||
@@ -309,8 +320,19 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEAD_CODE_STRIPPING = YES;
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEVELOPMENT_TEAM = LTFJ368N25;
|
DEVELOPMENT_TEAM = LTFJ368N25;
|
||||||
|
ENABLE_APP_SANDBOX = YES;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
|
ENABLE_INCOMING_NETWORK_CONNECTIONS = NO;
|
||||||
|
ENABLE_OUTGOING_NETWORK_CONNECTIONS = NO;
|
||||||
ENABLE_PREVIEWS = YES;
|
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;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = Peered/Info.plist;
|
INFOPLIST_FILE = Peered/Info.plist;
|
||||||
INFOPLIST_KEY_NSLocalNetworkUsageDescription = "";
|
INFOPLIST_KEY_NSLocalNetworkUsageDescription = "";
|
||||||
|
|||||||
+19
-14
@@ -9,24 +9,29 @@ import SwiftUI
|
|||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@AppStorage("peered_username") private var username: String = ""
|
@AppStorage("peered_username") private var username: String = ""
|
||||||
@State var browser: CommunicationProvider? = nil
|
@State private var notes = [Note]()
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
NavigationView {
|
||||||
if let browser {
|
List(notes) { note in
|
||||||
ForEach(browser.availablePeers, id: \.displayName) { peer in
|
NavigationLink(note.name) {
|
||||||
Text(peer.displayName)
|
NoteEditorScreen(note: note)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
.navigationTitle("Peered")
|
||||||
.padding()
|
.toolbar {
|
||||||
|
Button("Create note") {
|
||||||
|
NotesStorage().createNote(name: "New Note")
|
||||||
|
notes = NotesStorage().loadNotes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onAppear {
|
||||||
|
notes = NotesStorage().loadNotes()
|
||||||
|
}
|
||||||
.sheet(isPresented: .constant(username.isEmpty)) {
|
.sheet(isPresented: .constant(username.isEmpty)) {
|
||||||
SetUserNameBottomSheetView(username: $username)
|
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