From a0505368140076d6626647993a41a5f4ef9db019 Mon Sep 17 00:00:00 2001 From: towfiqi Date: Fri, 8 Nov 2024 10:14:12 +0600 Subject: [PATCH] feat: Keywords Country filter now only shows relevant countries. --- components/keywords/KeywordFilter.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/components/keywords/KeywordFilter.tsx b/components/keywords/KeywordFilter.tsx index 966f39f..029efe1 100644 --- a/components/keywords/KeywordFilter.tsx +++ b/components/keywords/KeywordFilter.tsx @@ -60,14 +60,19 @@ const KeywordFilters = (props: KeywordFilterProps) => { const countryOptions = useMemo(() => { const optionObject:{label:string, value:string}[] = []; - Object.keys(countries).forEach((countryISO:string) => { - if (!isConsole || (isConsole && SCcountries.includes(countryISO))) { - optionObject.push({ label: countries[countryISO][0], value: countryISO }); - } - }); + if (!isConsole) { + const allCountries = keywords.reduce((acc: string[], keyword) => [...acc, keyword.country], []).filter((t) => t && t.trim() !== ''); + [...new Set(allCountries)].forEach((c) => optionObject.push({ label: countries[c][0], value: c })); + } else { + Object.keys(countries).forEach((countryISO:string) => { + if ((SCcountries.includes(countryISO))) { + optionObject.push({ label: countries[countryISO][0], value: countryISO }); + } + }); + } return optionObject; - }, [SCcountries, isConsole]); + }, [SCcountries, isConsole, keywords]); const sortOptionChoices: SelectionOption[] = [ { value: 'pos_asc', label: 'Top Position' },