Pin 'Россия и СНГ' first in city picker direction tabs (TZ §4.1.9.2)

The dictionary API returns regions in arbitrary order. CityPickerPopup
now sorts them alphabetically by localized name and pulls the
Russia-and-CIS direction to the front — matching the TZ Table 14
listing order. Detection is loose (substring match on 'Россия' /
'Russia' / 'СНГ' / 'CIS') so minor backend renames still pin
correctly.
This commit is contained in:
2026-04-22 17:21:58 +03:00
parent 2e05b92e4e
commit f11cb7b15e
+24 -1
View File
@@ -25,7 +25,30 @@ export const CityPickerPopup: FC<CityPickerPopupProps> = ({
onLocate,
onClose,
}) => {
const regions = dictionaries.regions;
// TZ §4.1.9.2: "Россия и СНГ" direction pinned first; other directions
// alphabetical by localized name. `localeCompare` gives locale-aware
// collation; we detect the pinned direction by matching "Россия" /
// "Russia" / "CIS" as substrings so minor name variations still match.
const regions = useMemo(() => {
const sorted = [...dictionaries.regions].sort((a, b) =>
a.name.localeCompare(b.name),
);
const isCisName = (s: string): boolean => {
const lower = s.toLowerCase();
return (
lower.includes("россия") ||
lower.includes("russia") ||
lower.includes("снг") ||
lower.includes("cis")
);
};
const cisIdx = sorted.findIndex((r) => isCisName(r.name));
if (cisIdx > 0) {
const [cis] = sorted.splice(cisIdx, 1);
if (cis) sorted.unshift(cis);
}
return sorted;
}, [dictionaries.regions]);
const [activeRegionId, setActiveRegionId] = useState<number>(
regions[0]?.id ?? 0,
);