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

Ofek/api+modal #23

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

OfekSagiv
Copy link
Contributor

added modal and api fetch

- Removed Hebrew comments and unused code.
- Defined CSS colors as variables.
- Extracted magic numbers into named variables.
- Refactored theme logic and localStorage into reusable functions.
- Used map for regions list and applied shorter syntax where applicable.
- Applied destructuring to props for better readability.
Copy link
Member

@Tamir198 Tamir198 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall good work, I left you some comments


if (savedTheme) {
document.body.classList.toggle("dark-theme", savedTheme === "dark");
return savedTheme;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user does not have any theme why not give default theme?

This way you will not have to check the value of saved theme


useEffect(() => {
fetch("https://restcountries.com/v3.1/all")
.then((response) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded strings like this should be placed inside constants folder.

Another thing - it is recommended to take all of the logic that handles something and extract it to service/ under the api folder.


const handleDataError = (message) => {
console.error("Error fetching countries:", message);
setError("Failed to load countries. Please try again later.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the console here

<section className="filters">
<div className="container">
{countries.length === 1 && (
<button className="button-all-countries" onClick={() => setCountries(allCountries)}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save this magic number (1) into a constant variable

@@ -1,3 +1,24 @@
:root {
--color-black: #111517;
--color-dark-gray: #202c37;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work on variables

<ul className="country-brief">
<li><strong>Population:</strong> {population.toLocaleString()}</li>
<li><strong>Region:</strong> {region}</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to style your tags via css and not with strong tag

<p><strong>Population:</strong> {population.toLocaleString()}</p>
<p><strong>Region:</strong> {region}</p>
<p><strong>Subregion:</strong> {subregion}</p>
<p><strong>Capital:</strong> {capital ? capital[0] : "N/A"}</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment in here about the strong tag

<p><strong>Capital:</strong> {capital ? capital[0] : "N/A"}</p>
<p><strong>Area:</strong> {area.toLocaleString()} km²</p>
<p><strong>Currencies:</strong> {currencies ? Object.values(currencies).map(c => c.name).join(", ") : "N/A"}</p>
<p><strong>Languages:</strong> {languages ? Object.values(languages).join(", ") : "N/A"}</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, extract the logic function into a variable and call it

}

const regions = ["All", "Africa", "Americas", "Asia", "Europe", "Oceania"];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good practice to save those inside a variable

<ul onClick={(e) => action(e.target.getAttribute("data-region"))}>
{regions.map((region) => (
<li key={region} data-region={region}>{region}</li>
))}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for 2 countries to be in the same region?

If yes then think about different key for the li ( we don`t want to have 2 of the same key)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants