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

done #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

done #65

Show file tree
Hide file tree
Changes from all commits
Commits
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
141 changes: 125 additions & 16 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"axios": "^1.4.0",
"axios": "^1.7.3",
"bootstrap": "^5.3.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-router-dom": "^6.26.0"
},
"scripts": {
"dev": "vite",
Expand Down
11 changes: 9 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import "./App.css";
import { Routes, Route } from "react-router-dom";
import Navbar from "./components/Navbar";
import HomePage from "./pages/HomePage";
import CountryDetailsPage from "./pages/CountryDetailsPage";

function App() {
return (
<div className="App">
<h1>LAB | React WikiCountries</h1>
<Navbar />
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/:countryId" element={<CountryDetailsPage />} />
</Routes>
</div>
);
}
Expand Down
12 changes: 11 additions & 1 deletion src/components/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function Navbar() {}
import React from "react";

function Navbar() {
return (
<nav className="navbar navbar-light bg-light">
<div className="container">
<span className="navbar-brand mb-0 h1">WikiCountries</span>
</div>
</nav>
);
}

export default Navbar;
13 changes: 8 additions & 5 deletions src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import "bootstrap/dist/css/bootstrap.css";
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.jsx";
import "./index.css";
import App from "./App";
import { BrowserRouter as Router } from "react-router-dom";

ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
const root = ReactDOM.createRoot(document.getElementById("root"));

root.render(
<Router>
<App />
</React.StrictMode>
</Router>
);
41 changes: 39 additions & 2 deletions src/pages/CountryDetailsPage.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
function CountryDetails() {}
import { useState, useEffect } from "react";
import { useParams, Link } from "react-router-dom";
import axios from "axios";

export default CountryDetails;
function CountryDetailsPage() {
const { countryId } = useParams();
const [country, setCountry] = useState(null);

useEffect(() => {
axios
.get(`https://ih-countries-api.herokuapp.com/countries/${countryId}`)
.then((response) => {
setCountry(response.data);
})
.catch((error) => console.error(error));
}, [countryId]);

if (!country) {
return <div>Loading...</div>;
}

return (
<div className="container">
<h1>Country Details</h1>
<h2>{country.name.common}</h2>
<p>Capital: {country.capital}</p>
<p>Area: {country.area} km²</p>
<p>Borders:</p>
<ul>
{country.borders.map((border) => (
<li key={border}>
<Link to={`/${border}`}>{border}</Link>
</li>
))}
</ul>
</div>
);
}

export default CountryDetailsPage;
39 changes: 38 additions & 1 deletion src/pages/HomePage.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
function HomePage() {}
import { useState, useEffect } from "react";
import axios from "axios";
import { Link } from "react-router-dom";

function HomePage() {
const [countries, setCountries] = useState([]);

useEffect(() => {
axios
.get("https://ih-countries-api.herokuapp.com/countries")
.then((response) => {
setCountries(response.data);
})
.catch((error) => console.error(error));
}, []);

return (
<div className="container">
<h1>WikiCountries: Your Guide to the World</h1>
<div className="list-group">
{countries.map((country) => (
<Link
key={country.alpha3Code}
to={`/${country.alpha3Code}`}
className="list-group-item list-group-item-action"
>
<img
src={`https://flagcdn.com/16x12/${country.alpha2Code.toLowerCase()}.png`}
alt={`${country.name.common} flag`}
style={{ marginRight: "10px" }}
/>
{country.name.common}
</Link>
))}
</div>
</div>
);
}

export default HomePage;
Loading