aboutsummaryrefslogtreecommitdiff
path: root/src/components/GithubAvatar/GithubAvatar.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/GithubAvatar/GithubAvatar.tsx')
-rw-r--r--src/components/GithubAvatar/GithubAvatar.tsx39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/components/GithubAvatar/GithubAvatar.tsx b/src/components/GithubAvatar/GithubAvatar.tsx
new file mode 100644
index 0000000..32ac553
--- /dev/null
+++ b/src/components/GithubAvatar/GithubAvatar.tsx
@@ -0,0 +1,39 @@
+import React from 'react';
+
+import {
+ Avatar,
+ Link,
+} from '@material-ui/core';
+
+interface PropTypes {
+ username: string;
+}
+
+const githubUrl = 'https://github.com/';
+const getUserGithubUrl = (username: string): string => githubUrl + username;
+
+const GithubAvatar: React.FC<PropTypes> = ({ username }) => {
+ if (username === 'anonymous') return <Avatar/>;
+
+ const userGithubUrl = getUserGithubUrl(username);
+ const avatarUrl = userGithubUrl + '.png';
+ const usernameTokens = username.split(/[ ,.\-_#@;]/g);
+ const altText = (
+ (usernameTokens.length > 1)?
+ (usernameTokens[0][0] + usernameTokens[1][0])
+ :
+ usernameTokens[0][0]
+ ).toUpperCase()
+
+ return (
+ <Link href={userGithubUrl}>
+ <Avatar>
+ <img src={avatarUrl} alt={altText} />
+ </Avatar>
+ </Link>
+ )
+};
+
+export { getUserGithubUrl };
+export default GithubAvatar;
+