Skip to content

Conversation

@BarYosef212
Copy link

No description provided.

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.

Added some comments, the comments apply to everywhere in your code

For example - if i asked you do extract hardcoded strings into constants this apply to all of your strings etc...

const getAllCountries = async function () {
const response = await fetch('CountriesData.json')
return await response.json()
}
Copy link
Member

Choose a reason for hiding this comment

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

Save 'CountriesData.json' into constant file
This apply to every hardcoded string that you have

const displayCountries = function (data) {
const countriesGrid = $('.countries-grid');
countriesGrid.innerHTML = ''

Copy link
Member

Choose a reason for hiding this comment

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

Please avoid using innerHTMl, it is a dangarous method.

This apply to every place in your code using innerHTMl


const openDropDown = async function () {
$('.dropdown-body').classList.toggle("on")

Copy link
Member

Choose a reason for hiding this comment

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

The name of the function indicate that this function should inly open the drop down.

Then you toggle some class, maybe it will make more sense to call this function something like toggleDropDown ?

Correct me if im wrong about what this function is doing


$$('.li-drop').forEach(countryLi => {
countryLi.addEventListener("click", async () => {
$('.dropdown-header span').textContent = countryLi.textContent
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure that you want to add event listeners to all of the ul items for every menu click? Why not add them just once at the beginning?

Also, I don't see that you're cleaning up those listeners. It's very important to remove any unnecessary event listeners later.

const openDetailsPage = function (countryName) {
const countryData = currentCountries.filter(country => country.name == countryName)
localStorage.setItem("country", JSON.stringify(countryData))
window.location.href = 'details.html';
Copy link
Member

Choose a reason for hiding this comment

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

This could be extracted into storageService so that you will not repeat yourself again and again

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