improvements on the ui

This commit is contained in:
2026-11-25 07:14:49 +01:00
parent 3afdb6d67f
commit b7c72b9e16
249 changed files with 19702 additions and 17358 deletions
+15 -3
View File
@@ -20,7 +20,7 @@ public final class PageStore {
.appendingPathComponent("page.md")
}
/// The page file as read at launch; the first page when there was no file.
/// The page file as read at launch, after the pruning; the first page when there was no file.
public let loaded: PageFile
/// Makes the page file text when a save runs, so a keystroke costs no conversion; nil writes nothing.
@@ -36,12 +36,15 @@ public final class PageStore {
@ObservationIgnored private var isDirty = false
/// Reads the page file; a missing file gives `firstPage`, which the next flush writes unless it is empty.
///
/// With `pruneAt`, the old and undated blocks are left out and the page file is written at once when one was.
/// - Throws: `PageStoreError.unreadable` when the file exists but cannot be read.
public init(
url: URL = PageStore.defaultURL,
debounce: Duration = .milliseconds(500),
write: @escaping @Sendable (Data, URL) throws -> Void = PageStore.writeAtomically,
firstPage: @autoclosure () -> PageFile = WelcomeText.page(createdAt: Date())
firstPage: @autoclosure () -> PageFile = WelcomeText.page(createdAt: Date()),
pruneAt now: Date? = nil
) throws {
self.url = url
self.debounce = debounce
@@ -50,7 +53,16 @@ public final class PageStore {
guard let data = try? Data(contentsOf: url), let text = String(data: data, encoding: .utf8) else {
throw PageStoreError.unreadable(path: url.path)
}
loaded = PageFile(text: text)
let read = PageFile(text: text)
loaded = now.map { read.pruned(now: $0) } ?? read
if loaded != read {
do {
try write(Data(loaded.text().utf8), url)
} catch {
saveError = error.localizedDescription
isDirty = true
}
}
} else {
loaded = firstPage()
isDirty = !loaded.lines.isEmpty