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)}