Sorting Error in Book Series with More Than 9 Volumes
This commit is contained in:
committed by
Aditya Chandel
parent
2ee0b4cc2c
commit
9a2e131a42
+1
-1
@@ -62,7 +62,7 @@
|
||||
<td class="min-w-[10rem] max-w-[15rem] overflow-hidden truncate" [title]="getAuthorNames(metadata.authors)">{{ getAuthorNames(metadata.authors) }}</td>
|
||||
<td class="min-w-[9rem] max-w-[13rem] overflow-hidden truncate" [title]="metadata.publisher">{{ metadata.publisher }}</td>
|
||||
<td class="min-w-[9rem] max-w-[13rem] overflow-hidden truncate" [title]="metadata.seriesName">{{ metadata.seriesName }}</td>
|
||||
<td class="min-w-[1rem] max-w-[1rem] overflow-hidden truncate" [title]="metadata.seriesNumber">{{ metadata.seriesNumber }}</td>
|
||||
<td class="min-w-[1rem] max-w-[4rem] overflow-hidden truncate" [title]="metadata.seriesNumber">{{ metadata.seriesNumber }}</td>
|
||||
<td class="min-w-[12rem] max-w-[18rem] overflow-hidden truncate" [title]="getGenres(metadata.categories)">{{ getGenres(metadata.categories) }}</td>
|
||||
<td class="min-w-[9rem] max-w-[9rem] overflow-hidden truncate">
|
||||
{{ metadata.publishedDate ? (metadata.publishedDate | date: 'dd-MMM-yyyy') : '' }}
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
</div>
|
||||
<p class="text-xl">
|
||||
<p class="text-lg">
|
||||
@for (author of metadata?.authors; track author; let isLast = $last) {
|
||||
<a
|
||||
class="underline hover:opacity-80"
|
||||
|
||||
@@ -45,20 +45,32 @@ export class SortService {
|
||||
const {field, direction} = selectedSort;
|
||||
const extractor = this.fieldExtractors[field];
|
||||
|
||||
if (!extractor) return books;
|
||||
if (!extractor) {
|
||||
console.warn(`[SortService] No extractor for field: ${field}`);
|
||||
return books;
|
||||
}
|
||||
|
||||
return books.sort((a, b) => {
|
||||
const valueA = extractor(a);
|
||||
const valueB = extractor(b);
|
||||
return books.slice().sort((a, b) => {
|
||||
const aValue = extractor(a);
|
||||
const bValue = extractor(b);
|
||||
|
||||
if (valueA === null || valueA === undefined) return 1;
|
||||
if (valueB === null || valueB === undefined) return -1;
|
||||
let result: number;
|
||||
|
||||
if (direction === SortDirection.ASCENDING) {
|
||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
||||
if (Array.isArray(aValue) && Array.isArray(bValue)) {
|
||||
const nameCompare = aValue[0]?.localeCompare?.(bValue[0]) ?? 0;
|
||||
result = nameCompare !== 0 ? nameCompare : (aValue[1] - bValue[1]);
|
||||
} else if (typeof aValue === 'string' && typeof bValue === 'string') {
|
||||
result = aValue.localeCompare(bValue);
|
||||
} else if (typeof aValue === 'number' && typeof bValue === 'number') {
|
||||
result = aValue - bValue;
|
||||
} else {
|
||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
||||
// Handle nulls or mismatches
|
||||
if (aValue == null && bValue != null) return 1;
|
||||
if (aValue != null && bValue == null) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return direction === SortDirection.ASCENDING ? result : -result;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user