-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Update Collection View #3270
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
Merged
Merged
Update Collection View #3270
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
There is definitely room to clean this up further.
The
user != null
check is unnecessary becauseuser
isstate.user
which is always an object even when there is no one logged in.You are now passing
username
as a prop, which is the username of the collection owner, so you can use that instead ofcollection?.owner?.username
. Usingusername
has a few advantages, including that it won't beundefined
while the collection is fetching so you get an accurate boolean during loading.Additionally,
username
is neverundefined
. So there is no possibility thatusername === user.username
when there is no logged in user (anduser.username
isundefined
). So you don't need to explicitly check that there is auser.username
. Ifusername === user.username
istrue
then there is a user logged in who is the the owner of this collection. If it isfalse
then either there is no user logged in or the logged in user is not the owner.So you can write
const isOwner = () => username === user.username
and it will have the same effect.When I converted this component I wrote it as:
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.
IMO it's important to use descriptive variable names like
currentUsername
andownerUsername
to avoid bugs like the one that you fixed here.I know that I can be rude sometimes but I think you can understand my frustrations. Because I already converted this component over a year ago and it was cleanly written and did not have that sort of mistake.
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.
Thanks for catching these, there's probably still a lot of other areas this component could be improved here!
Since I wasn't able to get through all of your work and made some changes to these files that differed from yours, I do get your frustrations on how it probably feels like this could've been preventable. Although it'll be a lot of work since I didn't keep up with the PRs from back then, if you'd like to, we can get still try to get them in. I could be wrong, but I think most of them could probably be merged with some minimal changes except for a few (like the Common Table Components and the CodeMirror one, esp since it's part of the fellowship). I was also planning to upgrade the Node.js minor version in the near future, which I think might conflict with this one.
This is a bit of a tangent and definitely depends on the context, but I also personally feel that it's okay for code to end up a little messy and have mistakes sometimes! While I do think it's important to try not to make them, I don't want to view them negatively because I feel like they're a really normal part of any process, and in most cases, can usually be fixed.
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.
Wanted to add that I meant the latter more as a point of conversation, rather than disagreeing!