From 6c7ac29f62323b9e45414a21c7dc3536420784c2 Mon Sep 17 00:00:00 2001 From: sHa Date: Thu, 14 Aug 2025 01:15:44 +0300 Subject: [PATCH] Refactor country name highlighting logic in CountryMap component for improved readability and maintainability --- src/components/CountryMap.svelte | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/components/CountryMap.svelte b/src/components/CountryMap.svelte index 760f7a0..be93f5f 100644 --- a/src/components/CountryMap.svelte +++ b/src/components/CountryMap.svelte @@ -22,19 +22,22 @@ } }); // Highlight by country name (name attribute) - 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 allPaths = [...pathsByName, ...pathsByClass]; - console.log(`Found paths for ${name}:`, allPaths, `(${allPaths.length})`); - allPaths.forEach((countryPath) => { - countryPath.setAttribute("fill", "#4f8cff"); - countryPath.setAttribute("stroke", "#222"); - countryPath.style.filter = "drop-shadow(0 0 4px #4f8cff44)"; - }); + const names = Array.isArray(countryNames) + ? countryNames + : countryNames + ? [countryNames] + : []; + names.forEach((name) => { + const pathsByName = svgEl.querySelectorAll(`[name='${name}']`); + const pathsByClass = svgEl.querySelectorAll( + `.${name.replace(/ /g, ".")}`, + ); + const allPaths = [...pathsByName, ...pathsByClass]; + allPaths.forEach((countryPath) => { + countryPath.setAttribute("fill", "#4f8cff"); + countryPath.setAttribute("stroke", "#222"); + countryPath.style.filter = "drop-shadow(0 0 4px #4f8cff44)"; + }); }); }