From c3014a77c57cc6a2bc1f9f6c48ac3b4228823e9b Mon Sep 17 00:00:00 2001 From: Ochieng Paul Date: Fri, 23 Feb 2024 01:29:58 +0300 Subject: [PATCH] Update index.jsx --- platform/src/pages/map/index.jsx | 141 ++++++++++++++++++------------- 1 file changed, 80 insertions(+), 61 deletions(-) diff --git a/platform/src/pages/map/index.jsx b/platform/src/pages/map/index.jsx index a9b5dc439d..090ae8f886 100644 --- a/platform/src/pages/map/index.jsx +++ b/platform/src/pages/map/index.jsx @@ -1,5 +1,6 @@ import React, { useState, useEffect } from 'react'; import Layout from '@/components/Layout'; +import CloseIcon from '@/icons/close_icon'; import LocationIcon from '@/icons/LocationIcon'; import MenuIcon from '@/icons/map/menuIcon'; import AirQoMap from '@/components/Map/AirQoMap'; @@ -8,9 +9,41 @@ import HomeIcon from '@/icons/map/homeIcon'; import { useRouter } from 'next/router'; import { AirQualityLegend } from '@/components/Map/components/Legend'; import allCountries from '@/components/Map/components/countries'; -import SearchField from '@/components/search/SearchField'; +import SearchField from '@/components/Search/SearchField'; import { getSitesSummary } from '@/lib/store/services/deviceRegistry/GridsSlice'; +const countries = [ + { + id: 1, + name: 'Uganda', + flag: 'UG', + }, + { + id: 2, + name: 'Kenya', + flag: 'KE', + }, + { + id: 3, + name: 'Nigeria', + flag: 'NG', + }, + { + id: 4, + name: 'Rwanda', + flag: 'RW', + }, + { + id: 5, + name: 'Tanzania', + flag: 'TZ', + }, +]; + +const filteredCountries = allCountries.filter((country) => + countries.find((c) => c.name === country.country), +); + const TabSelector = ({ selectedTab, setSelectedTab }) => { return (
@@ -37,28 +70,40 @@ const TabSelector = ({ selectedTab, setSelectedTab }) => { const CountryList = ({ data, selectedCountry, setSelectedCountry }) => { const dispatch = useDispatch(); + // Check if data is not null or undefined + if (!data) { + return
No data available
; + } + + // Sort data const sortedData = [...data].sort((a, b) => a.country.localeCompare(b.country)); + // Handle click event + const handleClick = (country) => { + setSelectedCountry(country); + dispatch(setLocation({ country: country.country })); + }; + return (
- {sortedData.map((country, index) => ( -
{ - setSelectedCountry(country); - dispatch( - setLocation({ - country: country.country, - }), - ); - }}> - {country.country} - {country.country} -
- ))} + {sortedData.map((country, index) => { + // Check if country and flag properties exist + if (!country || !country.flag) { + return
Country data is incomplete
; + } + + return ( +
handleClick(country)}> + {country.country} + {country.country} +
+ ); + })}
); }; @@ -125,49 +170,23 @@ const index = () => { setSearchResults(results); }; - const locations = [ - { - id: 1, - name: 'Kampala', - country: 'Central, Uganda', - }, - { - id: 2, - name: 'Nairobi', - country: 'Central, Kenya', - }, - { - id: 3, - name: 'kiambu', - country: 'Eastern, Kenya', - }, - { - id: 4, - name: 'Kitgum', - country: 'Northern, Uganda', - }, - { - id: 5, - name: 'Kigaali', - country: 'Central, Rwanda', - }, - ]; - // Assuming siteDetails and allCountries are defined - let uniqueCountries = []; - let result = []; + // let uniqueCountries = []; + // let result = []; - siteDetails.forEach((site) => { - if (!uniqueCountries.includes(site.country)) { - uniqueCountries.push(site.country); - let countryDetails = allCountries.find((data) => data.country === site.country); - if (countryDetails) { - result.push({ ...site, ...countryDetails }); - } else { - return; - } - } - }); + // siteDetails.forEach((site) => { + // if (!uniqueCountries.includes(site.country)) { + // uniqueCountries.push(site.country); + // let countryDetails = allCountries.find((data) => data.country === site.country); + // if (countryDetails) { + // result.push({ ...site, ...countryDetails }); + // } else { + // result.push(site); + // } + // } + // }); + + // console.log(result); return ( @@ -208,7 +227,7 @@ const index = () => { All