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

Code Review! #7

Open
wants to merge 76 commits into
base: review
Choose a base branch
from
Open

Code Review! #7

wants to merge 76 commits into from

Conversation

matiasgarcia91
Copy link
Collaborator

No description provided.

ewa-mi and others added 30 commits June 15, 2020 20:02
Collections list page | add new collection
Copy link
Collaborator Author

@matiasgarcia91 matiasgarcia91 left a comment

Choose a reason for hiding this comment

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

Really clean and to the point code Ewa, loved it. I left a comment on your reducer structure, let me know if its not clear. Congrats 😄

reviewContent: reviewContent,
collectionId: collectionId,
bookId: bookId,
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no need to repeat the key/value in an object if you're going to call the keys the same as the constants are called. this works:

const newReviewdata = { reviewTitle, reviewContent, collectionId, bookId }

Copy link
Owner

Choose a reason for hiding this comment

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

oh, yes, the same in backend, thanks


for (let index = 0; index < 5; index++) {
stars += index < rating ? "★" : "☆";
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cool! 😎

// eslint-disable-next-line
book.categories?.forEach((item) => {
categories += item;
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

const categories = book.categories.join("") i think works better. Same for authors

{userCollections[0]?.user.name || user.name}'s collections
</h1>
<div className="collectionsContainer">
{userCollections?.map((item) => (
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nice work using the new optional chaining stuff! it looks cool! only so you are aware, this feature isn't supported in every browser yet cause its pretty new, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining. Shouldn't be a problem unless its a really old browser

Copy link
Owner

Choose a reason for hiding this comment

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

ok, good to know that, I didn't suppose optional chaining isn't supported in every browser


useEffect(() => {
dispatch(fetchFullData());
}, [dispatch, setBooksCollections]);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in this case it shouldn't affect in any way, but careful on passing extra stuff to your useEffects because if its a variable you pass and it changes the useEffect will fire again

booksCollections.map((item) => {
if (!item.review) {
return;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

idk if you know but this is called early-returns and its a pretty good practice, I really like it. If you dont have the stuff you need for a function, return. don't chain if and elses forever, 👍


default: {
// do nothing
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

default => return state, always!

@@ -0,0 +1,3 @@
export const selectBookDetails = (state) => {
return state.bookPage;
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

small stuff, but if you open an arrow function and immediately return, its better to write it in automatic return style

export const selectBookDetails = (state) => state.bookPage

}
}

return newState;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like the creativity but i'd stick to the usual way of writing reducers (returning in every case) 😄

}

return newState;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

more thoughts on the reducers as i scroll down hahah.
For example, each time you dispatch an action, all reducers get called. Then one of them matches the action and returns something to change the state.
The way you have it set up, every time an action is dispatch every state changes, because you are building a new state object (with all the stuff the old one had yes, but for JS its still a new object). So every selector gets activated again, everything refreshes essentially.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, I think, I understand what you mean. I remember, Rein advised to write reducers in 'the usual way', but I started to do it differently from the very beginning (just because it was simpler to me). Of course I need to switch to the 'correct' way. Btw. I expected the comment about my reducers...

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