gitscope
← marzneshin / v0.1.4 / app/dashboard/src/components/table/handle-sort.ts
https://dev.kronoz.win/r/marzneshin.git
app/dashboard/src/components/table/handle-sort.ts · TypeScript
Blame Raw
 1
 2import { FilterType } from 'types';
 3
 4export const handleSort = (
 5  filters: FilterType,
 6  column: string,
 7  onFilterChange: (filters: Partial<FilterType>) => void
 8) => {
 9  let newSort = filters.sort;
10  if (newSort.includes(column)) {
11    if (newSort.startsWith('-')) {
12      newSort = '-created_at';
13    } else {
14      newSort = '-' + column;
15    }
16  } else {
17    newSort = column;
18  }
19  onFilterChange({
20    sort: newSort,
21  });
22};