content-explorer/ui/lib/sort-rows.ts
tegwick a6e360aaa5 Port the explorer shell: tokens, header, hero, and a generic table.
CONTENT-WP-0002-T01 adapts the pinned OnCo visual system under ui/ without the corpus, mark, or kind routes.

Assistant: grok
Assistant-Session: 01a1346c-fdff-7741-b1af-b7283661554b
2026-10-13 22:51:00 +02:00

13 lines
518 B
TypeScript

import type { SortState } from "./types";
export function sortRows<T>(rows: readonly T[], sort: SortState | undefined, value: (row: T, key: string) => string): T[] {
if (!sort) return [...rows];
const copy = [...rows];
copy.sort((a, b) => value(a, sort.key).localeCompare(value(b, sort.key)) * sort.dir);
return copy;
}
export function nextSort(current: SortState | undefined, key: string): SortState {
if (current?.key === key) return { key, dir: current.dir === 1 ? -1 : 1 };
return { key, dir: 1 };
}