Prettier 3 (pinned), printWidth 100, double quotes — chosen to match the existing hand-formatting and minimise reflow. This commit is ONLY the mechanical format pass (`prettier --write`) plus the config/ignore/scripts, isolated so it never pollutes a feature diff. Verified behaviour-neutral: typecheck, eslint (0 errors), and vitest all green before and after. See .git-blame-ignore-revs — `git blame` skips this sha.
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
// The feed's sort vocabulary. `FeedFilters.sort` is a single wire string ("newest", "views_asc",
|
|
// …); the UI thinks in a key + direction. Kept here rather than inside Feed so the active-filter
|
|
// chips can label a sort without re-deriving the mapping.
|
|
|
|
export type SortKey =
|
|
| "date"
|
|
| "popular"
|
|
| "duration"
|
|
| "title"
|
|
| "subscribers"
|
|
| "priority"
|
|
| "shuffle"
|
|
| "relevance";
|
|
|
|
export const SORT_KEYS: SortKey[] = [
|
|
"date",
|
|
"popular",
|
|
"duration",
|
|
"title",
|
|
"subscribers",
|
|
"priority",
|
|
"shuffle",
|
|
];
|
|
|
|
/** Sorts with no meaningful asc/desc flip. */
|
|
export const DIRECTIONLESS: SortKey[] = ["shuffle", "relevance"];
|
|
|
|
const SORT_MAP: Record<Exclude<SortKey, "shuffle" | "relevance">, { asc: string; desc: string }> = {
|
|
date: { desc: "newest", asc: "oldest" },
|
|
popular: { desc: "views", asc: "views_asc" },
|
|
duration: { desc: "duration_desc", asc: "duration_asc" },
|
|
title: { asc: "title", desc: "title_desc" },
|
|
subscribers: { desc: "subscribers", asc: "subscribers_asc" },
|
|
priority: { desc: "priority", asc: "priority_asc" },
|
|
};
|
|
|
|
export const SORT_DEFAULT_DIR: Record<Exclude<SortKey, "shuffle" | "relevance">, "asc" | "desc"> = {
|
|
date: "desc",
|
|
popular: "desc",
|
|
duration: "desc",
|
|
title: "asc",
|
|
subscribers: "desc",
|
|
priority: "desc",
|
|
};
|
|
|
|
export function parseSort(s: string): { key: SortKey; dir: "asc" | "desc" } {
|
|
if (s === "shuffle" || s === "relevance") return { key: s, dir: "desc" };
|
|
for (const k of Object.keys(SORT_MAP) as (keyof typeof SORT_MAP)[]) {
|
|
if (SORT_MAP[k].asc === s) return { key: k, dir: "asc" };
|
|
if (SORT_MAP[k].desc === s) return { key: k, dir: "desc" };
|
|
}
|
|
return { key: "date", dir: "desc" };
|
|
}
|
|
|
|
export function buildSort(key: SortKey, dir: "asc" | "desc"): string {
|
|
if (key === "shuffle" || key === "relevance") return key;
|
|
return SORT_MAP[key][dir];
|
|
}
|