From 72ef2a3213f7573211b072e59637a5a0aa473470 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 11 Feb 2026 19:24:46 +0100 Subject: [PATCH] feat: sort countries alphabetically by translated name with CH pinned first --- js/components/search-box.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/js/components/search-box.js b/js/components/search-box.js index 447df2e..2f67b0b 100644 --- a/js/components/search-box.js +++ b/js/components/search-box.js @@ -3,21 +3,23 @@ import { escapeHTML } from '../utils/helpers.js' import { categoriesService } from '../services/categories.js' const COUNTRIES = [ - // German-speaking 'ch', 'de', 'at', 'li', 'lu', - // French-speaking 'fr', 'be', - // English-speaking 'gb', 'us', 'ca', 'au', 'nz', 'ie', 'za', - // Italian 'it', - // Spanish-speaking 'es', 'mx', 'ar', 'co', 'cl', - // Portuguese-speaking 'pt', 'br', - // Russian-speaking 'ru', 'by', 'kz' ] + +// Sort alphabetically by translated name, but pin CH first +function getSortedCountries() { + return [...COUNTRIES].sort((a, b) => { + if (a === 'ch') return -1 + if (b === 'ch') return 1 + return t(`countries.${a}`).localeCompare(t(`countries.${b}`)) + }) +} const RADIUS_OPTIONS = [5, 10, 20, 50, 100, 200] class SearchBox extends HTMLElement { @@ -321,7 +323,7 @@ class SearchBox extends HTMLElement { - ${COUNTRIES.map(c => ` + ${getSortedCountries().map(c => ` @@ -356,7 +358,7 @@ class SearchBox extends HTMLElement { - ${COUNTRIES.map(c => ` + ${getSortedCountries().map(c => ` @@ -1205,4 +1207,4 @@ style.textContent = /* css */` ` document.head.appendChild(style) -export { SearchBox, COUNTRIES, RADIUS_OPTIONS } +export { SearchBox, COUNTRIES, getSortedCountries, RADIUS_OPTIONS }