feat(filters): sort facet chips by count, then name
Order topic/language chips by their (contextual) count descending, name as the tiebreaker, so the most-populated tags sit at the top and the smallest counts fall to the bottom as you scan down.
This commit is contained in:
parent
d910bca5cf
commit
6e42e010dd
1 changed files with 8 additions and 3 deletions
|
|
@ -135,11 +135,16 @@ export default function Sidebar({
|
|||
const chipCount = (tag: Tag): number =>
|
||||
facetsReady ? facetCounts[String(tag.id)] ?? 0 : tag.channel_count;
|
||||
// Visible chips: hide zero-count ones once facets are in, but always keep selected ones
|
||||
// so an active filter can still be cleared.
|
||||
const visibleChips = (list: Tag[]): Tag[] =>
|
||||
facetsReady
|
||||
// so an active filter can still be cleared. Sorted by count (largest first), then name —
|
||||
// so scanning top→bottom the smallest counts end up at the very bottom.
|
||||
const visibleChips = (list: Tag[]): Tag[] => {
|
||||
const shown = facetsReady
|
||||
? list.filter((tg) => chipCount(tg) > 0 || filters.tags.includes(tg.id))
|
||||
: list;
|
||||
return [...shown].sort(
|
||||
(a, b) => chipCount(b) - chipCount(a) || a.name.localeCompare(b.name)
|
||||
);
|
||||
};
|
||||
|
||||
// After a page refresh the channel name isn't in the URL (only the id is), so
|
||||
// filters.channelName is undefined and the chip would fall back to "This channel".
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue