mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
11 lines
443 B
TypeScript
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];
|
|
};
|
|
}
|