aboutsummaryrefslogtreecommitdiff
path: root/src/components/GithubAvatar
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-03-21 17:38:44 +0300
committereug-vs <eug-vs@keemail.me>2020-03-21 17:38:44 +0300
commit295c6e179ec0f14a10303e01fb6e5b5ef969db79 (patch)
treec3a1ff2849fae554af71849ee33ee3dea2146061 /src/components/GithubAvatar
parent7f8ab6802c68c46f988ef012fdc88b09e43a9e54 (diff)
downloadchrono-cube-ui-295c6e179ec0f14a10303e01fb6e5b5ef969db79.tar.gz
feat: add github avatars to users
Diffstat (limited to 'src/components/GithubAvatar')
-rw-r--r--src/components/GithubAvatar/GithubAvatar.tsx35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/components/GithubAvatar/GithubAvatar.tsx b/src/components/GithubAvatar/GithubAvatar.tsx
new file mode 100644
index 0000000..6aab28e
--- /dev/null
+++ b/src/components/GithubAvatar/GithubAvatar.tsx
@@ -0,0 +1,35 @@
+import React from 'react';
+
+import {
+ Avatar,
+ Link,
+} from '@material-ui/core';
+
+interface PropTypes {
+ username: string;
+}
+
+const GithubAvatar: React.FC<PropTypes> = ({ username }) => {
+ if (username === 'anonymous') return <Avatar/>;
+
+ const githubUrl = `https://github.com/${username}`;
+ const avatarUrl = githubUrl + '.png';
+ const usernameTokens = username.split(/[ ,.\-_#@;]/g);
+ const altText = (
+ (usernameTokens.length > 1)?
+ (usernameTokens[0][0] + usernameTokens[1][0])
+ :
+ usernameTokens[0][0]
+ ).toUpperCase()
+
+ return (
+ <Link href={githubUrl}>
+ <Avatar>
+ <img src={avatarUrl} alt={altText} />
+ </Avatar>
+ </Link>
+ )
+};
+
+export default GithubAvatar;
+