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
Style selector basic functionality #76
Conversation
Optional chaining is used to avoid errors resulting from lookups on undefined.
Optional chaining is used to avoid errors resulting from lookups on undefined.
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.
Having a hard time understanding what this is going to be used for. Screenshots / screen caps could be helpful
|
||
return ( | ||
<div> | ||
{ stylesArray } |
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.
Put this directly in here for easier readability. But seems this component is maybe not even needed as it's essentially a map function over the <Style>
component. Is this <StyleSelector>
going into a lot of places?
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.
No, StyleSelector is only used once. I did it like this to try to compartmentalize things and keep Overview
simple by just including StyleSelector
. Would you recommend replacing <StyleSelector />
by the map in Overview
?
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.
Actually, I realize now that's not even what I'm doing. Taking your other comment into account, I'll move <StyleSelector />
to <Overview />
.
{/*TODO: show Product Overview*/} | ||
{/*TODO: add Share buttons*/} | ||
{selectedStyle?.original_price} | ||
{selectedStyle?.sale_price !== 0 ? selectedStyle?.sale_price : null} |
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.
Seems this is specific to one product, so maybe <StyleSelector>
shouldn't be inside of it. Would help with not having to pass down so many props to so many descendants
|
||
setProduct(productResponse.data); | ||
setStyles(sortedStyles); | ||
setSelectedStyleId(sortedStyles.find((style) => style['default?']).style_id); | ||
setSelectedStyleId( |
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.
You can initialize state lazily: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
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.
Does this provide an advantage over useEffect
without subscribers? I also need to set product
and styles
from data that I pull from an API. But the data is fetched only on the initial render since the subscribers array is empty. I'm now realizing that the useEffect hook should run when productId
changes though, since the data should be refetched whenever a new product is being displayed.
Actually I don't want to close those issues yet, since they're still works in progress, but I'll link the relevant issues in the top message of the PR. |
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.
Looks good, looks like you have some other changes you are making as well so ill check back in later today or tmrw. Great job with the tests also
|
||
function StyleSelector({ styles, selectedStyleId, handleStyleSelect }) { | ||
// TODO: use color-thief to extract average color of thumbnails server-side | ||
const stylesArray = styles.map((style) => ( |
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.
You can just directly return this and skip setting to a var then calling it later
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.
Yes good point. I think I had separated it in case I had more complicated logic in the return statement, but that ended up not being the case.
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.
Looks good great job
Also makes changes for accessibility.
Red:
StyleSelector
ProductInformation
StyleSelector
<-- (this PR is for this component)AddToCart
ImageGallery
ProductDetail
(this may go inProductInformation
ultimately)Relevant to: