'update'
This commit is contained in:
19
ipad_app/Sources/ViewModels/LibraryViewModel.swift
Normal file
19
ipad_app/Sources/ViewModels/LibraryViewModel.swift
Normal 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 }
|
||||
}
|
||||
Reference in New Issue
Block a user