-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced Context API with Redux + Redux Toolkit
- Loading branch information
Showing
21 changed files
with
21,506 additions
and
61 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Go Back button | ||
#go-back__btn { | ||
padding : 10px 20px; | ||
background-color: white; | ||
border : none; | ||
box-shadow : 0 0 10px -0px rgba(160, 159, 159, 0.404); | ||
|
||
.arrow-back { | ||
margin-right: 7px; | ||
color : rgb(36, 36, 36); | ||
|
||
svg { | ||
font-size: 15px; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.border-list { | ||
@include flexItem(flex-start, center, row); | ||
.border { | ||
margin-right: 10px; | ||
padding: 10px 15px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#country { | ||
margin-top: 16vh; | ||
margin-bottom: 5vh; | ||
padding : 30px 25px; | ||
|
||
.country-data__container { | ||
margin-top: 60px; | ||
|
||
img { | ||
width: 100%; | ||
} | ||
|
||
.country-data { | ||
margin-top: 15px; | ||
|
||
h1 { | ||
font-size : 28px; | ||
font-weight: 800; | ||
line-height: 2.5; | ||
} | ||
|
||
p { | ||
margin-bottom: 10px; | ||
font-size : 15px; | ||
font-weight : 600; | ||
|
||
span { | ||
font-weight: normal; | ||
} | ||
} | ||
|
||
.sub-data { | ||
margin: 40px 0 30px; | ||
} | ||
|
||
h3 { | ||
font-size: 18px; | ||
font-weight: 600; | ||
line-height: 3; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 23 additions & 12 deletions
35
src/pages/components/CountriesComponents/Countries/CountriesList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import axios from 'axios'; | ||
// import { Link } from 'react-router-dom'; | ||
|
||
import React, { useEffect } from 'react' | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { countriesActions } from '../../../../recuders/countriesReducer'; | ||
|
||
import { Link } from 'react-router-dom'; | ||
import CountryCard from '../../../components/CountriesComponents/Countries/CountryCard'; | ||
|
||
const Countries = () => { | ||
const [allCountries, setAllCountries] = useState([]); | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
const countriesUrl = 'https://restcountries.eu/rest/v2/all'; | ||
// Get a slice of the store. Retrieve the part of the store that you need | ||
// useSelector automatically subscribes the component | ||
const countries = useSelector(state => state.countries.countries) | ||
const error = useSelector(state => state.countries.error) | ||
|
||
const countriesUrl = 'https://restcountries.eu/rest/v2/all'; | ||
|
||
useEffect(() => { | ||
axios.get(countriesUrl).then((countries) => { | ||
setAllCountries(countries.data); | ||
console.log(allCountries); | ||
}) | ||
}, [setAllCountries]); | ||
console.log(countries.data); | ||
dispatch(countriesActions.setCountries(countries.data)); | ||
}); | ||
}, []); | ||
|
||
console.log(countries.countries); | ||
|
||
return ( | ||
<section id="country-list"> | ||
<div className="country-grid"> | ||
{allCountries.map((country) => { | ||
{countries.map((country) => { | ||
return ( | ||
<CountryCard name={country.name} population={country.population} region={country.region} capital={country.capital} flag={country.flag} /> | ||
<Link to={"/" + country.name} key={country.alpha3Code}><CountryCard name={country.name} population={country.population} region={country.region} capital={country.capital} flag={country.flag} /></Link> | ||
) | ||
})} | ||
</div> | ||
</section> | ||
) | ||
} | ||
|
||
export default Countries | ||
export default Countries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { useHistory } from "react-router-dom"; | ||
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; | ||
import { faReply } from '@fortawesome/free-solid-svg-icons'; | ||
|
||
const BackBtn = () => { | ||
let history = useHistory(); | ||
|
||
const goBackHandler = () => { | ||
history.push('/'); | ||
} | ||
return ( | ||
<button type="button" onClick={goBackHandler} id="go-back__btn"> | ||
<FontAwesomeIcon className="arrow-back" icon={faReply}/> Go Back | ||
</button> | ||
) | ||
} | ||
|
||
export default BackBtn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
|
||
const Border = (props) => { | ||
console.log('work'); | ||
return ( | ||
<div className="border"> | ||
{props.country} | ||
</div> | ||
) | ||
} | ||
|
||
export default Border; |
83 changes: 83 additions & 0 deletions
83
src/pages/components/SingleCountryComponents/SingleCountry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import axios from 'axios'; | ||
|
||
import React, { useEffect } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import { countryActions } from '../../../recuders/countryReducer'; | ||
|
||
const SingleCountry = () => { | ||
const dispatch = useDispatch(); | ||
|
||
const { country: countryID } = useParams(); | ||
|
||
const country = useSelector(state => state.country.country); | ||
|
||
const error = useSelector(state => state.country.error); | ||
|
||
const countryUrl = 'https://restcountries.eu/rest/v2/name/' + countryID; | ||
|
||
const fetchCountry = async () => { | ||
try { | ||
await axios.get(countryUrl).then(ctry => { | ||
console.log('Fetching borders'); | ||
dispatch(countryActions.setCountry(ctry.data[0])); | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
dispatch(countryActions.setError(err)); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
fetchCountry(); | ||
}, []); | ||
|
||
return ( | ||
<div className="country-data__container"> | ||
{country ? | ||
( | ||
<> | ||
<img src={country.flag} alt="" /> | ||
|
||
<div className="country-data"> | ||
<h1>{country.name}</h1> | ||
|
||
<div className="main-data"> | ||
<p>Native name: <span>{country.nativeName}</span></p> | ||
<p>Population: <span>{country.population}</span></p> | ||
<p>Region: <span>{country.region}</span></p> | ||
<p>Sub Region: <span>{country.subRegion}</span></p> | ||
<p>Capital: <span>{country.capital}</span></p> | ||
</div> | ||
|
||
<div className="sub-data"> | ||
|
||
<p>Top Level Domain: <span>{country.topLevelDomain}</span></p> | ||
<p>Currencies: <span> | ||
{country.currencies.map(currency => { | ||
return <span className="currency" key={currency.name}>{currency.name}</span> | ||
})} | ||
</span></p> | ||
<p>Languages: <span> | ||
{country.languages.map(language => { | ||
return <span key={language.name} className="language">{language.name}</span> | ||
})} | ||
</span></p> | ||
</div> | ||
|
||
<h3>Border Countries:</h3> | ||
{country ? ( | ||
<p>{country.borders}</p> | ||
) : ''} | ||
<div className="border-list"> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
: ''} | ||
</div> | ||
) | ||
} | ||
|
||
export default SingleCountry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.