@@ -60,17 +60,19 @@ export function doesBookMatchFilter(
6060 return mode === 'or' ;
6161 }
6262
63+ const effectiveMode = mode === 'not' ? 'or' : mode ;
64+
6365 switch ( filterType ) {
6466 case 'author' :
65- return mode === 'or'
67+ return effectiveMode === 'or'
6668 ? filterValues . some ( val => book . metadata ?. authors ?. includes ( val as string ) )
6769 : filterValues . every ( val => book . metadata ?. authors ?. includes ( val as string ) ) ;
6870 case 'category' :
69- return mode === 'or'
71+ return effectiveMode === 'or'
7072 ? filterValues . some ( val => book . metadata ?. categories ?. includes ( val as string ) )
7173 : filterValues . every ( val => book . metadata ?. categories ?. includes ( val as string ) ) ;
7274 case 'series' :
73- return mode === 'or'
75+ return effectiveMode === 'or'
7476 ? filterValues . some ( val => book . metadata ?. seriesName ?. trim ( ) === val )
7577 : filterValues . every ( val => book . metadata ?. seriesName ?. trim ( ) === val ) ;
7678 case 'bookType' :
@@ -80,24 +82,24 @@ export function doesBookMatchFilter(
8082 case 'personalRating' :
8183 return filterValues . some ( range => isRatingInRange10 ( book . personalRating , range as string | number ) ) ;
8284 case 'publisher' :
83- return mode === 'or'
85+ return effectiveMode === 'or'
8486 ? filterValues . some ( val => book . metadata ?. publisher === val )
8587 : filterValues . every ( val => book . metadata ?. publisher === val ) ;
8688 case 'matchScore' :
8789 return filterValues . some ( range => isMatchScoreInRange ( book . metadataMatchScore , range as string | number ) ) ;
8890 case 'library' :
89- return mode === 'or'
91+ return effectiveMode === 'or'
9092 ? filterValues . some ( val => val == book . libraryId )
9193 : filterValues . every ( val => val == book . libraryId ) ;
9294 case 'shelf' :
93- return mode === 'or'
95+ return effectiveMode === 'or'
9496 ? filterValues . some ( val => book . shelves ?. some ( s => s . id == val ) )
9597 : filterValues . every ( val => book . shelves ?. some ( s => s . id == val ) ) ;
9698 case 'shelfStatus' :
9799 const shelved = book . shelves && book . shelves . length > 0 ? 'shelved' : 'unshelved' ;
98100 return filterValues . includes ( shelved ) ;
99101 case 'tag' :
100- return mode === 'or'
102+ return effectiveMode === 'or'
101103 ? filterValues . some ( val => book . metadata ?. tags ?. includes ( val as string ) )
102104 : filterValues . every ( val => book . metadata ?. tags ?. includes ( val as string ) ) ;
103105 case 'publishedDate' :
@@ -118,7 +120,7 @@ export function doesBookMatchFilter(
118120 case 'pageCount' :
119121 return filterValues . some ( range => isPageCountInRange ( book . metadata ?. pageCount ! , range as string | number ) ) ;
120122 case 'mood' :
121- return mode === 'or'
123+ return effectiveMode === 'or'
122124 ? filterValues . some ( val => book . metadata ?. moods ?. includes ( val as string ) )
123125 : filterValues . every ( val => book . metadata ?. moods ?. includes ( val as string ) ) ;
124126 case 'ageRating' :
@@ -131,15 +133,15 @@ export function doesBookMatchFilter(
131133 case 'narrator' :
132134 return filterValues . includes ( book . metadata ?. narrator ) ;
133135 case 'comicCharacter' :
134- return mode === 'or'
136+ return effectiveMode === 'or'
135137 ? filterValues . some ( val => book . metadata ?. comicMetadata ?. characters ?. includes ( val as string ) )
136138 : filterValues . every ( val => book . metadata ?. comicMetadata ?. characters ?. includes ( val as string ) ) ;
137139 case 'comicTeam' :
138- return mode === 'or'
140+ return effectiveMode === 'or'
139141 ? filterValues . some ( val => book . metadata ?. comicMetadata ?. teams ?. includes ( val as string ) )
140142 : filterValues . every ( val => book . metadata ?. comicMetadata ?. teams ?. includes ( val as string ) ) ;
141143 case 'comicLocation' :
142- return mode === 'or'
144+ return effectiveMode === 'or'
143145 ? filterValues . some ( val => book . metadata ?. comicMetadata ?. locations ?. includes ( val as string ) )
144146 : filterValues . every ( val => book . metadata ?. comicMetadata ?. locations ?. includes ( val as string ) ) ;
145147 case 'comicCreator' : {
@@ -161,7 +163,7 @@ export function doesBookMatchFilter(
161163 }
162164 }
163165 }
164- return mode === 'or'
166+ return effectiveMode === 'or'
165167 ? filterValues . some ( val => allCreators . includes ( val as string ) )
166168 : filterValues . every ( val => allCreators . includes ( val as string ) ) ;
167169 }
@@ -187,6 +189,7 @@ export function filterBooksByFilters(
187189 const matches = filterEntries . map ( ( [ filterType , filterValues ] ) =>
188190 doesBookMatchFilter ( book , filterType , filterValues , mode )
189191 ) ;
192+ if ( mode === 'not' ) return matches . every ( m => ! m ) ;
190193 return mode === 'or' ? matches . some ( m => m ) : matches . every ( m => m ) ;
191194 } ) ;
192195}
0 commit comments