mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-03-12 00:17:32 +08:00
feat: update year order, make unknown year last
This commit is contained in:
@@ -160,13 +160,19 @@ function SearchPageClient() {
|
|||||||
return { categoriesAll, categoriesAgg };
|
return { categoriesAll, categoriesAgg };
|
||||||
}, [searchResults]);
|
}, [searchResults]);
|
||||||
|
|
||||||
// 年份排序辅助
|
// 年份排序辅助:无年份/unknown/非数字 一律视为未知,始终排在最后
|
||||||
const compareYear = (aYear: string, bYear: string, order: 'asc' | 'desc') => {
|
const compareYear = (aYear: string, bYear: string, order: 'asc' | 'desc') => {
|
||||||
if (aYear === bYear) return 0;
|
const normalize = (y?: string) => {
|
||||||
if (aYear === 'unknown') return 1;
|
if (!y || y === 'unknown') return null;
|
||||||
if (bYear === 'unknown') return -1;
|
const n = parseInt(y, 10);
|
||||||
const diff = parseInt(aYear) - parseInt(bYear);
|
return Number.isNaN(n) ? null : n;
|
||||||
return order === 'asc' ? diff : -diff;
|
};
|
||||||
|
const aN = normalize(aYear);
|
||||||
|
const bN = normalize(bYear);
|
||||||
|
if (aN === null && bN === null) return 0;
|
||||||
|
if (aN === null) return 1; // a 无效,放后
|
||||||
|
if (bN === null) return -1; // b 无效,放后
|
||||||
|
return order === 'asc' ? aN - bN : bN - aN;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 非聚合:应用筛选与排序
|
// 非聚合:应用筛选与排序
|
||||||
|
|||||||
Reference in New Issue
Block a user