Declared-but-empty projects persist locally (UserDefaults) until a note carries the name, at which point the project syncs via notes as usual. Empty declared projects can be swipe-deleted. Claude-Session: https://claude.ai/code/session_014esDWi42URLEC6Cj17hGQ3
39 lines
1.2 KiB
Swift
39 lines
1.2 KiB
Swift
import SwiftUI
|
|
|
|
/// Device-local Projects-tab preferences: the sort order and the names the
|
|
/// user has declared via "+" before any note was filed into them. Declared
|
|
/// names are deliberately NOT synced — a project becomes part of the synced
|
|
/// data the moment a note carries it; until then it is scaffolding that only
|
|
/// this device knows about.
|
|
enum ProjectsPrefs {
|
|
static let declaredKey = "declaredProjects"
|
|
static let sortKey = "projectsSort"
|
|
|
|
/// Newline-joined storage — names are single-line (the creation alert's
|
|
/// text field can't produce newlines) so this stays trivially inspectable.
|
|
static func decodeDeclared(_ raw: String) -> [String] {
|
|
raw.split(separator: "\n").map(String.init)
|
|
}
|
|
|
|
static func encodeDeclared(_ names: [String]) -> String {
|
|
names.joined(separator: "\n")
|
|
}
|
|
}
|
|
|
|
/// Sort orders for the project list.
|
|
enum ProjectsSort: String, CaseIterable, Identifiable {
|
|
case activity
|
|
case name
|
|
case count
|
|
|
|
var id: String { rawValue }
|
|
|
|
var label: String {
|
|
switch self {
|
|
case .activity: "Recent Activity"
|
|
case .name: "Name"
|
|
case .count: "Note Count"
|
|
}
|
|
}
|
|
}
|