mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-11-18 18:40:31 +00:00
- Harden default sort preference use + fix series ordering use - Update readme with contribution and project scope disclaimers
28 lines
626 B
TypeScript
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;
|
|
};
|