Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fetch api #2

Merged
merged 45 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
af9beea
Creates the src/components/Countries.js empty file
ClaudiaRojasSoto Jul 30, 2023
19140c1
Creates the file src/flagData.js with the routes of the flags images …
ClaudiaRojasSoto Jul 30, 2023
13a40c0
Delete the images folder from the public folder and add the folder im…
ClaudiaRojasSoto Jul 30, 2023
af3583b
Add the images of the countries flag to images on public folder
ClaudiaRojasSoto Jul 31, 2023
aad4f97
Create the src/imagesContinents/ folder to add the continents images
ClaudiaRojasSoto Jul 31, 2023
d0550f7
Statrt with the object flagsData on src/flagData.js file
ClaudiaRojasSoto Jul 31, 2023
e4f326c
Upload the routes on src/App.js file
ClaudiaRojasSoto Jul 31, 2023
c2443f9
upload the json packages
ClaudiaRojasSoto Jul 31, 2023
bfc34a5
Delete from the src the folder image to add the images on public fold…
ClaudiaRojasSoto Jul 31, 2023
3a6a56c
Add all the routes to the flags by continent on src/flagData.js file
ClaudiaRojasSoto Jul 31, 2023
97f65ad
Add the flags to folder public and inside ir images folder
ClaudiaRojasSoto Jul 31, 2023
d90dc54
Add the image world.png on src/imagesContinents/continents/world.png …
ClaudiaRojasSoto Jul 31, 2023
c0bcfe4
Modify the stules on src/styles/HomePage.css to show the world upside…
ClaudiaRojasSoto Jul 31, 2023
b6d4fb8
Add a div tag and the img tag to use the world.png file
ClaudiaRojasSoto Jul 31, 2023
1d26243
Add the src/styles/Countries.css file to add styles to the flags depl…
ClaudiaRojasSoto Jul 31, 2023
33a9e88
Upload the src/components/Countries.js file to use the right continen…
ClaudiaRojasSoto Jul 31, 2023
153b8fe
Add the getContinentImage funtion and the capitalizeFirstLetter to sh…
ClaudiaRojasSoto Jul 31, 2023
ea671c9
Create the folder reducer and wrap the countriesreducer.js file on it
ClaudiaRojasSoto Jul 31, 2023
478631b
Creates the folder actions on redux and wrap the countries actions.js…
ClaudiaRojasSoto Jul 31, 2023
57b3f53
Add the logic of the reducer for countries on store.js file
ClaudiaRojasSoto Jul 31, 2023
50ff33a
Traslate the src/redux/airQualityReducer.js file to the reducers fold…
ClaudiaRojasSoto Jul 31, 2023
3e5b985
Delete from redux folder the src/redux/airQualityActions.js file to t…
ClaudiaRojasSoto Jul 31, 2023
1230a1e
Change the route to sudafrica flag on the src/flagData.js file
ClaudiaRojasSoto Jul 31, 2023
2f12f27
Upload the src/components/HomePage.js file with the route to the images
ClaudiaRojasSoto Jul 31, 2023
816fef3
Add UseEffect and dispatch to use reducer and add the handleCountruCl…
ClaudiaRojasSoto Jul 31, 2023
2d044b5
Add the provider store wraping the router on app.js file
ClaudiaRojasSoto Jul 31, 2023
e8050f6
Upload the json packages adding redux-toolkit
ClaudiaRojasSoto Jul 31, 2023
39b874e
Delete a duplicated element china on src/flagData.js file
ClaudiaRojasSoto Jul 31, 2023
a5cea1b
Fix the name activeclassname instead acctiveClassname on src/componen…
ClaudiaRojasSoto Jul 31, 2023
1b27273
Start the implementation of the necesary logic to handle the api. On …
ClaudiaRojasSoto Jul 31, 2023
e7a3657
Upload the json packages adding axios
ClaudiaRojasSoto Jul 31, 2023
bf8d0b2
Change the api call to another api
ClaudiaRojasSoto Jul 31, 2023
dc7853b
Add the countries code
ClaudiaRojasSoto Jul 31, 2023
9f79b85
Add some logic to deploy the Details page
ClaudiaRojasSoto Jul 31, 2023
9d1c314
Add styles for Details component
ClaudiaRojasSoto Jul 31, 2023
e9a3855
Delete actions and reducers to the pollution api
ClaudiaRojasSoto Jul 31, 2023
5eca2fd
Add the route to details page
ClaudiaRojasSoto Jul 31, 2023
56b062d
Change the path name and the name key on src/components/Countries.js …
ClaudiaRojasSoto Jul 31, 2023
1a5871f
Add a verification to be sure about the data it is not null and then …
ClaudiaRojasSoto Jul 31, 2023
7ee4cd7
Upload actions file to fix errors
ClaudiaRojasSoto Jul 31, 2023
0e8a93f
Upload actions file to fix errors
ClaudiaRojasSoto Jul 31, 2023
fc204b9
Change the key value on src/components/Countries.js file to country.c…
ClaudiaRojasSoto Jul 31, 2023
054cbba
Add more details to show on details page
ClaudiaRojasSoto Jul 31, 2023
a9d8bd1
Upload the properties to show on details
ClaudiaRojasSoto Aug 1, 2023
5325502
Fix linter errors
ClaudiaRojasSoto Aug 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@reduxjs/toolkit": "^1.9.5",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.4.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.1.2",
"react-router-dom": "^6.14.2",
"react-scripts": "5.0.1",
"redux": "^4.2.1",
"redux-thunk": "^2.4.2",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
Binary file added public/images/africa/angola.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/argelia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/benin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/botsuana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/burkina_faso.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/burundi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/cabo_verde.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/camerun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/chad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/comores.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/congo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/costa_de_marfil.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/egipto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/eritrea.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/esuati.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/esuatini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/etiopia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/gabon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/gambia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/ghana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/guinea.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/guinea_bissau.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/guinea_ecuatorial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/isla_mauricio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/kenia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/africa/lesotho.png
Binary file added public/images/africa/liberia.png
Binary file added public/images/africa/libia.png
Binary file added public/images/africa/madagascar.png
Binary file added public/images/africa/malawi.png
Binary file added public/images/africa/mali.png
Binary file added public/images/africa/marruecos.png
Binary file added public/images/africa/mauritania.png
Binary file added public/images/africa/mozambique.png
Binary file added public/images/africa/namibia.png
Binary file added public/images/africa/nigeria.png
Binary file added public/images/africa/niguer.png
Binary file added public/images/africa/republica_centroafricana.png
Binary file added public/images/africa/republica_del_congo.png
Binary file added public/images/africa/ruanda.png
Binary file added public/images/africa/sahara_occidental.png
Binary file added public/images/africa/santa_elena.png
Binary file added public/images/africa/santo_tome.png
Binary file added public/images/africa/seicheles.png
Binary file added public/images/africa/senegal.png
Binary file added public/images/africa/sierra_leona.png
Binary file added public/images/africa/somalia.png
Binary file added public/images/africa/sudafrica.png
Binary file added public/images/africa/sudan.png
Binary file added public/images/africa/sudan_del_sur.png
Binary file added public/images/africa/tanzania.png
Binary file added public/images/africa/togo.png
Binary file added public/images/africa/tunez.png
Binary file added public/images/africa/uganda.png
Binary file added public/images/africa/yibuti.png
Binary file added public/images/africa/zambia.png
Binary file added public/images/africa/zimbabue.png
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added public/images/america/guayana_francesa.png
Binary file added public/images/america/martinica.png
File renamed without changes
Binary file added public/images/america/san_pedro_miquelon.png
File renamed without changes
Binary file added public/images/asia/afganistan.png
Binary file added public/images/asia/armenia.png
Binary file added public/images/asia/azerbaiyan.png
Binary file added public/images/asia/bahrain.png
Binary file added public/images/asia/bangladesh.png
Binary file added public/images/asia/brunei.png
Binary file added public/images/asia/butan.png
Binary file added public/images/asia/camboya.png
Binary file added public/images/asia/catar.png
Binary file added public/images/asia/china.png
Binary file added public/images/asia/chipre.png
Binary file added public/images/asia/corea_del_norte.png
Binary file added public/images/asia/corea_del_sur.png
Binary file added public/images/asia/emiratos_arabes_unidos.png
Binary file added public/images/asia/filipinas.png
Binary file added public/images/asia/georgia.png
Binary file added public/images/asia/hong_kong.png
Binary file added public/images/asia/india.png
Binary file added public/images/asia/indonesia.png
Binary file added public/images/asia/iran.png
Binary file added public/images/asia/iraq.png
Binary file added public/images/asia/israel.png
Binary file added public/images/asia/japon.png
Binary file added public/images/asia/jordania.png
Binary file added public/images/asia/kazajistan.png
Binary file added public/images/asia/kirguistan.png
Binary file added public/images/asia/kuwait.png
Binary file added public/images/asia/laos.png
Binary file added public/images/asia/libano.png
Binary file added public/images/asia/macao.png
Binary file added public/images/asia/malasia.png
Binary file added public/images/asia/maldivas.png
Binary file added public/images/asia/mongolia.png
Binary file added public/images/asia/mynmar.png
Binary file added public/images/asia/nepal.png
Binary file added public/images/asia/oman.png
Binary file added public/images/asia/pakistan.png
Binary file added public/images/asia/palestina.png
Binary file added public/images/asia/saudi_arabia.png
Binary file added public/images/asia/singapur.png
Binary file added public/images/asia/siria.png
Binary file added public/images/asia/sri_lanka.png
Binary file added public/images/asia/tailandia.png
Binary file added public/images/asia/taiwan.png
Binary file added public/images/asia/tayikistan.png
Binary file added public/images/asia/timor_oriental.png
Binary file added public/images/asia/turkmenistan.png
Binary file added public/images/asia/turquia.png
Binary file added public/images/asia/uzbekistan.png
Binary file added public/images/asia/vietnam.png
Binary file added public/images/asia/yemen.png
Binary file added public/images/australia/australia.png
Binary file added public/images/australia/isla_cocos.png
Binary file added public/images/australia/isla_navidad.png
Binary file added public/images/australia/isla_norfolk.png
Binary file added public/images/australia/islas_hearld.png
Binary file added public/images/australia/nueva_zelandia.png
Binary file added public/images/europe/albania.png
Binary file added public/images/europe/alemania.png
Binary file added public/images/europe/andorra.png
Binary file added public/images/europe/austria.png
Binary file added public/images/europe/belarus.png
Binary file added public/images/europe/belgica.png
Binary file added public/images/europe/bosnia.png
Binary file added public/images/europe/bulgaria.png
Binary file added public/images/europe/chequia.png
Binary file added public/images/europe/ciudad_del_vaticano.png
Binary file added public/images/europe/croacia.png
Binary file added public/images/europe/dinamarca.png
Binary file added public/images/europe/eslovaquia.png
Binary file added public/images/europe/eslovenia.png
Binary file added public/images/europe/espana.png
Binary file added public/images/europe/estonia.png
Binary file added public/images/europe/finlandia.png
Binary file added public/images/europe/francia.png
Binary file added public/images/europe/gibraltar.png
Binary file added public/images/europe/grecia.png
Binary file added public/images/europe/guernsey.png
Binary file added public/images/europe/hungria.png
Binary file added public/images/europe/irlanda.png
Binary file added public/images/europe/isla_man.png
Binary file added public/images/europe/isla_san_martin.png
File renamed without changes
Binary file added public/images/europe/islas_aland.png
Binary file added public/images/europe/islas_feroe.png
Binary file added public/images/europe/italia.png
Binary file added public/images/europe/jersey.png
Binary file added public/images/europe/kosovo.png
Binary file added public/images/europe/letonia.png
Binary file added public/images/europe/liechtenstein.png
Binary file added public/images/europe/lituania.png
Binary file added public/images/europe/luxemburgo.png
Binary file added public/images/europe/macedonia_del_norte.png
Binary file added public/images/europe/malta.png
Binary file added public/images/europe/moldavia.png
Binary file added public/images/europe/montenegro.png
Binary file added public/images/europe/noruega.png
Binary file added public/images/europe/paises_bajos.png
Binary file added public/images/europe/polonia.png
Binary file added public/images/europe/portugal.png
Binary file added public/images/europe/principado_de_monaco.png
Binary file added public/images/europe/reino_unido.png
Binary file added public/images/europe/rumania.png
Binary file added public/images/europe/rusia.png
Binary file added public/images/europe/san_marino.png
Binary file added public/images/europe/serbia.png
Binary file added public/images/europe/suecia.png
Binary file added public/images/europe/suiza.png
Binary file added public/images/europe/svalbard_jan_mayen.png
Binary file added public/images/europe/ukrania.png
Binary file added public/images/oceania/american_samoa.png
Binary file added public/images/oceania/antarctica.png
Binary file added public/images/oceania/cook_island.png
Binary file added public/images/oceania/fiji.png
Binary file added public/images/oceania/french_polynesia.png
Binary file added public/images/oceania/guam.png
Binary file added public/images/oceania/kiribati.png
Binary file added public/images/oceania/marshall_islands.png
Binary file added public/images/oceania/micronesia.png
Binary file added public/images/oceania/nauru.png
Binary file added public/images/oceania/new_caledonia.png
Binary file added public/images/oceania/niue.png
Binary file added public/images/oceania/palaos.png
Binary file added public/images/oceania/papua_new_guinea.png
Binary file added public/images/oceania/pitcairn_islands.png
Binary file added public/images/oceania/samoa.png
Binary file added public/images/oceania/solomon_islands.png
Binary file added public/images/oceania/tokelau.png
Binary file added public/images/oceania/tonga.png
Binary file added public/images/oceania/tuvalu.png
Binary file added public/images/oceania/vanuatu.png
Binary file added public/images/oceania/wallis_futuna.png
23 changes: 15 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import React from 'react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import { Provider } from 'react-redux';
import store from './redux/store';
import HomePage from './components/HomePage';
import DetailsPage from './components/DetailsPage';
import Navbar from './components/Navbar';
import Countries from './components/Countries';
import DetailsPage from './components/DetailsPage'; // asegúrate de importar DetailsPage

function App() {
return (
<Router>
<Navbar />
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/details/:id" element={<DetailsPage />} />
</Routes>
</Router>
<Provider store={store}>
<Router>
<Navbar />
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/countries/:continent" element={<Countries />} />
<Route path="/country/:name" element={<DetailsPage />} />
<Route path="/details/1" element={<DetailsPage />} />
</Routes>
</Router>
</Provider>
);
}

Expand Down
104 changes: 104 additions & 0 deletions src/components/Countries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React, { useEffect } from 'react';
import { useParams, Link } from 'react-router-dom';
import { useSelector, useDispatch } from 'react-redux';
import axios from 'axios';
import { updateCountries, updateCountryData } from '../redux/actions/countriesActions';
import flagsData from '../flagData';
import '../styles/Countries.css';

import continent1 from '../imagesContinents/continents/africa.png';
import continent2 from '../imagesContinents/continents/america.png';
import continent3 from '../imagesContinents/continents/asia.png';
import continent4 from '../imagesContinents/continents/australia.png';
import continent5 from '../imagesContinents/continents/europa.png';
import continent6 from '../imagesContinents/continents/oceania.png';

function getContinentImage(continent) {
switch (continent) {
case 'africa':
return continent1;
case 'america':
return continent2;
case 'asia':
return continent3;
case 'australia':
return continent4;
case 'europa':
return continent5;
case 'oceania':
return continent6;
default:
return null;
}
}

const Countries = () => {
const { continent } = useParams();
const countries = useSelector((state) => state.countries.countries);
const dispatch = useDispatch();

useEffect(() => {
const countriesOfContinent = flagsData[continent];
dispatch(updateCountries(countriesOfContinent));
}, [continent, dispatch]);

if (!Array.isArray(countries)) {
return (
<div>
<h1>{`Error: ${continent} It is not a valid continent.`}</h1>
</div>
);
}

const handleCountryClick = async (country) => {
try {
const response = await axios.get(`https://restcountries.com/v3/alpha/${country.countryCode}`);
if (response.data && response.data.length > 0) {
console.log(response.data);
dispatch(updateCountryData(response.data[0]));
} else {
console.log('No se devolvieron datos válidos del país en la API');
}
} catch (error) {
console.log('Error al obtener los datos del país:', error);
}
};

const capitalizeFirstLetter = (
string,
) => string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();

return (
<div>
<img src={getContinentImage(continent)} alt={continent} />
<h1>{capitalizeFirstLetter(continent)}</h1>
<div className="countries-grid">
{countries.map((country) => (
<Link
to={{
pathname: `/country/${country.name.common}`,
state: { countryData: country },
// Pasamos toda la información del país en el estado de la ruta
}}
key={country.countryCode}
>
<div
className="country-item"
onClick={() => handleCountryClick(country)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') handleCountryClick(country);
}}
tabIndex="0"
role="button"
>
<img src={country.imagePath} alt={country.name} />
<p>{country.name}</p>
</div>
</Link>
))}
</div>
</div>
);
};

export default Countries;
Loading