Files
explore/ui/shared/sort/getNextSortValue.ts
T
2023-07-18 15:27:42 -03:00

11 lines
443 B
TypeScript

export default function getNextSortValue<SortField extends string, Sort extends string>(
sortSequence: Record<SortField, Array<Sort| undefined>>, field: SortField,
) {
return (prevValue: Sort | undefined) => {
const sequence = sortSequence[field];
const curIndex = sequence.findIndex((sort) => sort === prevValue);
const nextIndex = curIndex + 1 > sequence.length - 1 ? 0 : curIndex + 1;
return sequence[nextIndex];
};
}