diff --git a/components/ideas/idea-list.tsx b/components/ideas/idea-list.tsx index e4a8dfe..d052fd1 100644 --- a/components/ideas/idea-list.tsx +++ b/components/ideas/idea-list.tsx @@ -154,6 +154,26 @@ export function IdeaList({ ideas, products, isDemo }: IdeaListProps) { }) }, [ideas, search, productFilter, statusFilter, sortKey, sortDir]) + const sorted = useMemo(() => { + return [...filtered].sort((a, b) => { + let cmp = 0 + if (sortKey === 'code') { + cmp = (a.code ?? '').localeCompare(b.code ?? '', 'nl', { numeric: true }) + } else if (sortKey === 'title') { + cmp = a.title.localeCompare(b.title, 'nl') + } else if (sortKey === 'product') { + const aN = a.product?.name ?? '' + const bN = b.product?.name ?? '' + if (!aN && bN) return sortDir === 'asc' ? 1 : -1 + if (aN && !bN) return sortDir === 'asc' ? -1 : 1 + cmp = aN.localeCompare(bN, 'nl') + } else { + cmp = (STATUS_SORT_ORDER[a.status] ?? 99) - (STATUS_SORT_ORDER[b.status] ?? 99) + } + return sortDir === 'asc' ? cmp : -cmp + }) + }, [filtered, sortKey, sortDir]) + function handleSort(col: SortKey) { if (sortKey === col) { setSortDir((d) => (d === 'asc' ? 'desc' : 'asc')) @@ -316,7 +336,7 @@ export function IdeaList({ ideas, products, isDemo }: IdeaListProps) { )} {/* Tabel */} - {filtered.length === 0 ? ( + {sorted.length === 0 ? (
{ideas.length === 0
? 'Nog geen ideeën — start hierboven met "Nieuw idee".'
@@ -334,7 +354,7 @@ export function IdeaList({ ideas, products, isDemo }: IdeaListProps) {