-
Notifications
You must be signed in to change notification settings - Fork 28
creating files and functionality #4
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
base: main
Are you sure you want to change the base?
Conversation
Tamir198
left a comment
There was a problem hiding this 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() | ||
| } |
There was a problem hiding this comment.
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 = '' | ||
|
|
There was a problem hiding this comment.
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") | ||
|
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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
No description provided.