From e43339ccf33dfc99a0095fa8bc57a2ce5ea8ceff Mon Sep 17 00:00:00 2001 From: Tal Sadan Date: Sat, 28 Dec 2024 07:43:43 +0200 Subject: [PATCH 1/2] added the countries cards --- src/components/Country.jsx | 20 +++++++++++++------- src/pages/Home.jsx | 24 ++++++++++++++++-------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/components/Country.jsx b/src/components/Country.jsx index 177580c..3803089 100644 --- a/src/components/Country.jsx +++ b/src/components/Country.jsx @@ -1,10 +1,16 @@ -import React from 'react' - -const Country = () => { +export const Country = ({name,flag, population, region, capital}) => { return ( - // TODO: Country component -
Country
+
+ {`Flag +
+

{name}

+
    +
  • Population: {population}
  • +
  • Region: {region}
  • +
  • Capital: {capital}
  • +
+
+
) } - -export default Country \ No newline at end of file +export default Country diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index 507e0c5..95c4e1a 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -1,12 +1,20 @@ -import React from "react"; +import { useState } from "react"; +import { Country } from "../components/Country"; +import data from "../assets/CountriesData.json"; -const Home = () => { +export const Home = () => { + const [countries, setcountries] = useState(data); return ( - // TODO: Home page - // Render Country component (components/Country.jsx) for each country - // Take data from (assets/CountriesData.json) -
Home
+
+
+ { + countries.map( + (country) => {return + }) + } +
+
); }; - -export default Home; +export default Home From 64720a263a7e636fc5f0a49f2dcf729fc2a0e67b Mon Sep 17 00:00:00 2001 From: Tal Sadan Date: Sat, 28 Dec 2024 18:28:41 +0200 Subject: [PATCH 2/2] added the header and search bar and made filter by region func --- src/components/Header.jsx | 20 ++++++++++++++++++ src/components/SearchBar.jsx | 41 ++++++++++++++++++++++++++++++++++++ src/pages/Home.jsx | 41 ++++++++++++++++++++++++------------ 3 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 src/components/Header.jsx create mode 100644 src/components/SearchBar.jsx diff --git a/src/components/Header.jsx b/src/components/Header.jsx new file mode 100644 index 0000000..8f2a671 --- /dev/null +++ b/src/components/Header.jsx @@ -0,0 +1,20 @@ +export const Header = () => { + return ( +
+
+ +

Where in the world?

+
+
+ +
+ ); +}; +export default Header; diff --git a/src/components/SearchBar.jsx b/src/components/SearchBar.jsx new file mode 100644 index 0000000..f7da26d --- /dev/null +++ b/src/components/SearchBar.jsx @@ -0,0 +1,41 @@ + +import { useState } from 'react'; + +const SearchBar = (props) => { + const regions = ["All", "Africa", "Americas", "Asia", "Europe", "Oceania"]; + const [isOpen, setIsOpen] = useState(false); + + // if the menu is open + const openDropDown = () => { + setIsOpen(!isOpen); + } + + return (<> +
+
+
+ + +
+
+
+ Filter by Region + +
+ {isOpen && ( +
+
    + {regions.map((region, index) => ( +
  • props.filterByRegionFunc(region)}>{region}
  • + ))} +
+
+ )} +
+
+
+ + ) + +} + export default SearchBar; \ No newline at end of file diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index 95c4e1a..5d20a98 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -1,20 +1,35 @@ import { useState } from "react"; import { Country } from "../components/Country"; import data from "../assets/CountriesData.json"; +import Header from "../components/Header"; +import SearchBar from "../components/SearchBar"; export const Home = () => { - const [countries, setcountries] = useState(data); - return ( -
-
- { - countries.map( - (country) => {return - }) - } -
+ const [countries, setCountries] = useState(data); + + const filterByRegionFunc = (region) => { + const filteredCountries = + region === "All" + ? data + : data.filter((country) => country.region === region); + setCountries(filteredCountries); + }; + + return ( + <> +
+ +
+
+ {countries.map((country) => ( + + ))}
- ); +
+ + ); }; -export default Home + +export default Home;