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

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

Closed
humphd opened this issue Apr 17, 2021 · 0 comments · Fixed by #2176
Closed

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

humphd opened this issue Apr 17, 2021 · 0 comments · Fixed by #2176
Assignees
Labels

Comments

@humphd
Copy link
Contributor

humphd commented Apr 17, 2021

We use blog for the link's href in the PostAvatar:

const PostAvatar = ({ name, img, blog = '' }: AvatarProps) => {
  const classes = useStyles();

  if (img) {
    return <Avatar className={classes.avatar} src={img} />;
  }

  if (name.length > 0) {
    const initials = name
      .split(' ')
      // splitName represents the current value, i represents its index, and arr represent the whole splitted name-word array
      // if the index is 0, means it's the first word in the name
      // if the index+1 equals to the array length, it means the current value is the last word in the name
      // anything rather than first word or last word will not be included in initials
      .map((splitName, i, arr) =>
        i === 0 || i + 1 === arr.length ? splitName[0].toUpperCase() : null
      )
      .join('');
    return (
      <a href={blog} className={classes.link}>
        <Avatar className={classes.avatar}>
          <p className={classes.text}>{initials}</p>
        </Avatar>
      </a>
    );
  }

  return <Avatar className={classes.avatar} />;
};

In the new signup code we're re-using this component to show the GitHub avatar in the signup form, and it's odd to name the URL we pass blog (it isn't a blog).

Let's rename blog to the more generic url, and update all callers to do the same.

Also, blog is an optional prop, but we always use it. We should be returning an <Avatar> without a parent <a> if we don't get passed a url.

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 a pull request may close this issue.

2 participants