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

Carrot store fetch challenge #3

Open
wants to merge 2 commits into
base: nicoleta-tuturuga
Choose a base branch
from

Conversation

nicoleta-tuturuga
Copy link

  • I made the site responsive
  • I fetched the resources from the given server and rendered the data dynamic in the list page and details page
  • I used query params to send the value of the product id in the url from list page to details page
  • I used html template with fetch to reuse the header and footer

@alexonaci alexonaci self-requested a review March 9, 2020 09:13
Copy link
Member

@alexonaci alexonaci left a comment

Choose a reason for hiding this comment

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

Imi place ca e foarte clean si ordonat codul, imi place ca ai folosit media queries si imi place cum ti-ai organizat javascript-ul si faptul ca ai folosit Promise.then pentru fetch
Imi place ca te-ai folosit de url params pentru product details

GG 😄

name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
Copy link
Member

Choose a reason for hiding this comment

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

stiu ca nu am discutat inca despre asta dar ar fi o buna practica sa folosim tot timpul block-uri in expresii conditionale ca si if-urile:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else#Description

function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
Copy link
Member

Choose a reason for hiding this comment

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

Sa incerci sa pastrezi consistenta - daca ai folosit let, sa folosesti doar let sau daca e var doar var. Dar e o practica buna sa folosesti doar let si const



// logic to get de id from query param
function getParameterByName(name, url) {
Copy link
Member

Choose a reason for hiding this comment

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

niste sugestii la aceasta functie:

Copy link
Member

Choose a reason for hiding this comment

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

"poti sa te folosesti de window.location.search ca sa iti dea direct ce vine dupa '?' in url:
https://developer.mozilla.org/en-US/docs/Web/API/Location
https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search
si asa mai scapi putin de regex-uri"

Nevermind 😄 am vazut dupa cum ai folosit si si ca te-ai folosit si de window.location.search e oki


}

function getUsersData(user) {
Copy link
Member

Choose a reason for hiding this comment

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

Legat de naming-ul functiilor, parerea mea e ca s-ar potrivi mai bine displayUserData(user) sau chiar displayComments(user) deoarece get reprezinta actiunea de a lua ceva de undeva si altfel poate introduce confuzie. In cazul getDataFromServer se potriveste pentru ca iei datele de pe server.
La fel si pentru getProductDetails

justify-content: center;
}

.carrot-svg{
Copy link
Member

Choose a reason for hiding this comment

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

ar trebui un spatiu pus inainte de acolada:D ( si pentru restul) autoindent din vs code

if (productId === null) {
productId = "0"
}

Copy link
Contributor

Choose a reason for hiding this comment

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

It is possible to assign a default value to productId by using the || (OR) operator, e.g.

productId = getParameterByName("id", window.location.search) || "0"

This would filter out any "falsy" value ("", 0, null, undefined, etc...)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_OR_2

for (let i = 0; i < data.comments.length; i++) {
let user = data.comments[i];
getUsersData(user);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It is good practice to extract a deeply nested value in a variable if we need to access it many times (e.g. for loop)

const deeplyNestedVariable = a.b.c.d.e.f
for (let i = 0; i < deeplyNestedVariable ; i++) {...}

That way we do not have to look through the object chain every loop.

We could also inline the user variable, e.g. :

getUsersData(data.comments[i]);

@CBalan1648
Copy link
Contributor

Good job 👍

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.

3 participants