This commit is contained in:
douboer
2025-09-07 12:39:28 +08:00
parent 1ba01e3c64
commit 4d033257fe
5714 changed files with 15866 additions and 1032 deletions

View File

@@ -0,0 +1,19 @@
import Foundation
import Combine
@available(macOS 10.15, iOS 13.0, *)
@MainActor
final class LibraryViewModel: ObservableObject {
@Published var bundleIndex: BundleIndex?
@Published var searchText: String = ""
var filteredBooks: [BookMeta] {
guard let books = bundleIndex?.books else { return [] }
let q = searchText.trimmingCharacters(in: .whitespacesAndNewlines)
if q.isEmpty { return books.sorted { ($0.last_open ?? 0) > ($1.last_open ?? 0) } }
return books.filter { $0.title.localizedCaseInsensitiveContains(q) || $0.author.localizedCaseInsensitiveContains(q) }
.sorted { ($0.last_open ?? 0) > ($1.last_open ?? 0) }
}
func attach(index: BundleIndex) { self.bundleIndex = index }
}