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

Fixes #2169: Rename blog prop to url in PostAvatar, deal with optional value #2176

Merged
merged 1 commit into from
Apr 21, 2021

Conversation

rjayroso
Copy link
Contributor

Issue This PR Addresses

Fixes #2169

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

Changes the PostAvatar blog prop to be named url.
Changes how the PostAvatar is rendered: if there is no url, then PostAvatar is rendered without an <a> element wrapped around it.

How to Test

Pull this branch for testing, go to components/Posts/Post.tsx in VSCode (or your editor of choice) and scroll to the bottom - put a <PostAvatar name="FirstName LastName" /> element somewhere that it can be rendered and seen.

You should see an Avatar with the initials "FL" and it should also be unclickable (since their is no url prop)

Now add the prop url="Test" to the PostAvatar (e.g. <PostAvatar name="FirstName LastName" url="Test"/>

You should see that same Avatar now be clickable (if clicked it will give you Telescope's 404 because it is an invalid url).

Checklist

  • Quality: This PR builds and passes our npm test and works locally
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not (if applicable)
  • Documentation: This PR includes updated/added documentation to user exposed functionality or configuration variables are added/changed or an explanation of why it does not(if applicable)

</Avatar>
</a>
<div>
{url.length > 0 ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this, but shouldn't we also be checking if url is not null as well, basically if it exists as well as if the length is greater than 0

Copy link
Contributor Author

@rjayroso rjayroso Apr 19, 2021

Choose a reason for hiding this comment

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

So, I think from what I understand after reading the PostAvatar.tsx component is that, if no url is given in the props, then the url is assigned to a "" empty string. Either way, I can add it quickly it's no problem

Edit: check the latest commit

Edit2: I just realized there are a lot of ways to check if url is undefined, if you have a better conditional let me know and I can quickly update it

@@ -59,7 +59,7 @@ const PostAvatar = ({ name, img, url = '' }: AvatarProps) => {
.join('');
return (
<div>
{url.length > 0 ? (
{url.length > 0 && url != undefined ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

Think just url.length > 0 && url is fine enough

Copy link
Contributor

Choose a reason for hiding this comment

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

url?.length && (...)

@humphd
Copy link
Contributor

humphd commented Apr 19, 2021

Please update the title of this PR to give info about what it is, in addition to what it fixes.

@@ -39,7 +39,7 @@ const useStyles = makeStyles((theme: Theme) =>
})
);

const PostAvatar = ({ name, img, blog = '' }: AvatarProps) => {
const PostAvatar = ({ name, img, url = '' }: AvatarProps) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use = '' as a default. If it's not there, we need to know that.

@@ -59,7 +59,7 @@ const PostAvatar = ({ name, img, url = '' }: AvatarProps) => {
.join('');
return (
<div>
{url.length > 0 ? (
{url.length > 0 && url != undefined ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

url?.length && (...)

@manekenpix manekenpix changed the title Fixes #2169: Fixes #2169: Rename blog prop to url in PostAvatar, deal with optional value Apr 19, 2021
</Avatar>
</a>
<div>
{url != undefined && url?.length > 0 ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

This is really gonna sound nit-picky, but should be !== instead of !=

Copy link
Contributor

Choose a reason for hiding this comment

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

Doing url? is the same as checking if url exists, so you don't need this. However, @HyperTHD is right: you never want to use != or == in JS, since they both allow implicit type casting to happen, whereas !== and === will also check the types.

</Avatar>
</a>
<div>
{url != undefined && url?.length > 0 ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

Doing url? is the same as checking if url exists, so you don't need this. However, @HyperTHD is right: you never want to use != or == in JS, since they both allow implicit type casting to happen, whereas !== and === will also check the types.

yuanLeeMidori
yuanLeeMidori previously approved these changes Apr 20, 2021
Copy link
Contributor

@yuanLeeMidori yuanLeeMidori left a comment

Choose a reason for hiding this comment

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

Just do squash and merge, otherwise looks good for me :)

@rjayroso
Copy link
Contributor Author

Squashed and rebased

humphd
humphd previously approved these changes Apr 20, 2021
yuanLeeMidori
yuanLeeMidori previously approved these changes Apr 20, 2021
deal with optional value
* Changed blog prop to url
* Changed prop name to url in other files using PostAvatar
* Changed PostAvatar to no longer wrapped by an <a> by default
* Searched for instances of PostAvatar and changed blog prop to url
* Added extra conditional to check if url is not undefined
* Removed url defaulting to empty string. Changed the conditional
* 'url != undefined' changed to 'url !=== undefined'
* Changed 'url !== undefined && url?.length > 0' to 'url?.length'
@humphd
Copy link
Contributor

humphd commented Apr 20, 2021

@rjayroso you can rebase and merge this from GitHub, you don't have to keep rebasing manually.

@humphd
Copy link
Contributor

humphd commented Apr 21, 2021

@rjayroso wait to merge this til we fix CI, which is failing atm

@rjayroso
Copy link
Contributor Author

@rjayroso wait to merge this til we fix CI, which is failing atm

Yeah no worries, now that I know I can rebase and merge from GitHub I'm ready whenever 😅

@humphd humphd merged commit bc0f2b7 into Seneca-CDOT:master Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename blog prop to url in PostAvatar, deal with optional value
5 participants