Fix: Date filter doesn't work very well (#1715)

This commit is contained in:
Aditya Chandel
2025-12-01 19:25:17 -07:00
committed by GitHub
parent d4121b241a
commit b5460a5e90
4 changed files with 8 additions and 10 deletions
@@ -89,11 +89,11 @@ function getRatingRangeFilters10(rating?: number): { id: string; name: string; s
return idx ? [{id: idx.id, name: idx.label, sortIndex: idx.sortIndex}] : [];
}
function extractPublishedYearFilter(book: Book): { id: number; name: string }[] {
function extractPublishedYearFilter(book: Book): { id: string; name: string }[] {
const date = book.metadata?.publishedDate;
if (!date) return [];
const year = new Date(date).getFullYear();
return [{id: year, name: year.toString()}];
return [{id: year.toString(), name: year.toString()}];
}
function getShelfStatusFilter(book: Book): { id: string; name: string }[] {
@@ -14,7 +14,7 @@ export class FilterLabelHelper {
publisher: 'Publisher',
readStatus: 'Read Status',
personalRating: 'Personal Rating',
publishedYear: 'Year Published',
publishedDate: 'Year Published',
matchScore: 'Metadata Match Score',
language: 'Language',
bookType: 'Book Type',
@@ -93,13 +93,11 @@ export class SideBarFilter implements BookFilter {
return filterValues.some(range => isRatingInRange(book.metadata?.hardcoverRating, range));
case 'personalRating':
return filterValues.some(range => isRatingInRange10(book.metadata?.personalRating, range));
case 'publishedYear':
const bookYear = book.metadata?.publishedDate
? new Date(book.metadata.publishedDate).getFullYear().toString()
: null;
return bookYear ? filterValues.includes(bookYear) : false;
case 'publishedDate':
return filterValues.includes(new Date(book.metadata?.publishedDate || '').getFullYear());
const bookYear = book.metadata?.publishedDate
? new Date(book.metadata.publishedDate).getFullYear()
: null;
return bookYear ? filterValues.some(val => val == bookYear || val == bookYear.toString()) : false;
case 'fileSize':
return filterValues.some(range => isFileSizeInRange(book.fileSizeKb, range));
case 'shelfStatus':
@@ -587,7 +587,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
goToPublishedYear(publishedDate: string): void {
const year = this.extractYear(publishedDate);
if (year) {
this.handleMetadataClick('publishedYear', year);
this.handleMetadataClick('publishedDate', year);
}
}