feat: add sorting button for VOD and series

This commit is contained in:
Serkan committed 2024-09-29 05:12:34 +03:00
1 parent 35d83149eb
commit 81cbc1e5d6
10 files changed
+111 -15

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
import { Injectable, Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'sortBy',
standalone: true,
})
@Injectable()
export class SortPipe implements PipeTransform {
transform(array: any[], sortType: string): any {
if (!array || !sortType) {
return array;
}
return array.sort((a, b) => {
if (sortType === 'date') {
return parseInt(b.added) - parseInt(a.added);
} else if (sortType === 'rating') {
const ratingA = isNaN(parseFloat(a.rating)) ? 0 : parseFloat(a.rating);
const ratingB = isNaN(parseFloat(b.rating)) ? 0 : parseFloat(b.rating);
return ratingB - ratingA;
} else if (sortType === 'alpha') {
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
} else {
return 0;
}
});
}
}