Files
shelfmark/src/frontend/src/utils/metadataSort.ts
T
Alex edb437e905 Fix sorting + update readme (#715)
- Harden default sort preference use + fix series ordering use
- Update readme with contribution and project scope disclaimers
2026-03-06 17:06:20 +00:00

28 lines
626 B
TypeScript

import { SortOption } from '../types';
const FALLBACK_SORT = 'relevance';
export const getEffectiveMetadataSort = ({
currentSort,
defaultSort,
sortOptions,
}: {
currentSort?: string;
defaultSort?: string;
sortOptions?: SortOption[];
}): string => {
const supportedSorts = sortOptions && sortOptions.length > 0
? sortOptions.map((option) => option.value)
: [FALLBACK_SORT];
if (currentSort && supportedSorts.includes(currentSort)) {
return currentSort;
}
if (defaultSort && supportedSorts.includes(defaultSort)) {
return defaultSort;
}
return supportedSorts[0] || FALLBACK_SORT;
};