mirror of
https://github.com/Hackdex-App/hackdex-website.git
synced 2026-12-06 09:25:42 -06:00
Allow hack tags to be reordered
This commit is contained in:
@@ -3,6 +3,21 @@ export function formatCompactNumber(value: number): string {
|
||||
return new Intl.NumberFormat("en", { notation: "compact", maximumFractionDigits: 1 }).format(value);
|
||||
}
|
||||
|
||||
export type OrderedTag = { name: string; order: number };
|
||||
|
||||
export function sortOrderedTags<T extends OrderedTag>(rows: T[]): T[] {
|
||||
return [...rows]
|
||||
.filter((t) => !!t.name)
|
||||
.sort((a, b) => {
|
||||
const aHasOrder = a.order > 0;
|
||||
const bHasOrder = b.order > 0;
|
||||
if (aHasOrder && !bHasOrder) return -1;
|
||||
if (!aHasOrder && bHasOrder) return 1;
|
||||
if (aHasOrder && bHasOrder && a.order !== b.order) return a.order - b.order;
|
||||
return 0; // fallback to original array order
|
||||
});
|
||||
}
|
||||
|
||||
export function slugify(text: string) {
|
||||
return text
|
||||
.normalize("NFD")
|
||||
|
||||
Reference in New Issue
Block a user