From 4fd90fd81c3335bcf8bbb7d05871bd3b38f6bc4c Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Fri, 26 Jun 2026 21:56:26 -0400 Subject: [PATCH] Enhance category sorting and filtering in dropdown components - Updated CategoryDropdown and CategoryFilterDropdown to sort categories by number of locations and display name. - Improved CategoryModal to filter categories based on a search term and sort them accordingly. - Refactored CollectionMap to build category options based on location counts, enhancing user experience in filtering. --- .../lib/components/CategoryDropdown.svelte | 8 +- .../components/CategoryFilterDropdown.svelte | 8 +- .../src/lib/components/CategoryModal.svelte | 618 +++++++++++++----- .../collections/CollectionMap.svelte | 15 +- 4 files changed, 464 insertions(+), 185 deletions(-) diff --git a/frontend/src/lib/components/CategoryDropdown.svelte b/frontend/src/lib/components/CategoryDropdown.svelte index 5b817bdd..4534383f 100644 --- a/frontend/src/lib/components/CategoryDropdown.svelte +++ b/frontend/src/lib/components/CategoryDropdown.svelte @@ -23,9 +23,11 @@ let mobileSearchInputRef: HTMLInputElement; let desktopSearchInputRef: HTMLInputElement; - $: sortedCategories = [...categories].sort( - (a, b) => (b.num_locations || 0) - (a.num_locations || 0) - ); + $: sortedCategories = [...categories].sort((a, b) => { + const usageDiff = (b.num_locations || 0) - (a.num_locations || 0); + if (usageDiff !== 0) return usageDiff; + return a.display_name.localeCompare(b.display_name); + }); $: filteredCategories = sortedCategories.filter((category) => { if (!searchTerm) return true; diff --git a/frontend/src/lib/components/CategoryFilterDropdown.svelte b/frontend/src/lib/components/CategoryFilterDropdown.svelte index e155ba46..355e08ae 100644 --- a/frontend/src/lib/components/CategoryFilterDropdown.svelte +++ b/frontend/src/lib/components/CategoryFilterDropdown.svelte @@ -9,6 +9,12 @@ let adventure_types: Category[] = []; const dispatch = createEventDispatcher<{ change: { types: string } }>(); + $: sortedAdventureTypes = [...adventure_types].sort((a, b) => { + const usageDiff = (b.num_locations || 0) - (a.num_locations || 0); + if (usageDiff !== 0) return usageDiff; + return a.display_name.localeCompare(b.display_name); + }); + onMount(async () => { const categoryFetch = await fetch('/api/categories'); const categoryData = await categoryFetch.json(); @@ -52,7 +58,7 @@

{:else}
- {#each adventure_types as type (type.id)} + {#each sortedAdventureTypes as type (type.id)}