@@ -28,10 +28,12 @@ struct ZimFilesNew: View {
28
28
NSSortDescriptor ( keyPath: \ZimFile . name, ascending: true ) ,
29
29
NSSortDescriptor ( keyPath: \ZimFile . size, ascending: false )
30
30
] ,
31
- predicate: ZimFilesNew . buildPredicate ( searchText: " " ) ,
32
31
animation: . easeInOut
33
32
) private var zimFiles : FetchedResults < ZimFile >
34
33
@State private var searchText = " "
34
+ private var filterPredicate : NSPredicate {
35
+ ZimFilesNew . buildPredicate ( searchText: searchText)
36
+ }
35
37
let dismiss : ( ( ) -> Void ) ? // iOS only
36
38
37
39
var body : some View {
@@ -40,7 +42,7 @@ struct ZimFilesNew: View {
40
42
alignment: . leading,
41
43
spacing: 12
42
44
) {
43
- ForEach ( zimFiles) { zimFile in
45
+ ForEach ( zimFiles. filter { filterPredicate . evaluate ( with : $0 ) } ) { zimFile in
44
46
ZimFileCell ( zimFile, prominent: . name)
45
47
. modifier ( LibraryZimFileContext ( zimFile: zimFile, dismiss: dismiss) )
46
48
}
@@ -52,12 +54,6 @@ struct ZimFilesNew: View {
52
54
. onAppear {
53
55
viewModel. start ( isUserInitiated: false )
54
56
}
55
- . onChange ( of: languageCodes) { _ in
56
- zimFiles. nsPredicate = ZimFilesNew . buildPredicate ( searchText: searchText)
57
- }
58
- . onChange ( of: searchText) { searchText in
59
- zimFiles. nsPredicate = ZimFilesNew . buildPredicate ( searchText: searchText)
60
- }
61
57
. overlay {
62
58
if zimFiles. isEmpty {
63
59
switch viewModel. state {
0 commit comments