Refactor country name highlighting logic in CountryMap component for improved readability and maintainability

This commit is contained in:
sHa
2025-08-14 01:15:44 +03:00
parent 6c2aa6acef
commit 6c7ac29f62

View File

@@ -22,14 +22,17 @@
}
});
// Highlight by country name (name attribute)
const names = Array.isArray(countryNames) ? countryNames : countryNames ? [countryNames] : [];
const names = Array.isArray(countryNames)
? countryNames
: countryNames
? [countryNames]
: [];
names.forEach((name) => {
// Find all elements with matching name attribute or class name
console.log(`Highlighting country: ${name}`);
const pathsByName = svgEl.querySelectorAll(`[name='${name}']`);
const pathsByClass = svgEl.querySelectorAll(`.${name.replace(/ /g, '.')}`);
const pathsByClass = svgEl.querySelectorAll(
`.${name.replace(/ /g, ".")}`,
);
const allPaths = [...pathsByName, ...pathsByClass];
console.log(`Found paths for ${name}:`, allPaths, `(${allPaths.length})`);
allPaths.forEach((countryPath) => {
countryPath.setAttribute("fill", "#4f8cff");
countryPath.setAttribute("stroke", "#222");