From 295c6e179ec0f14a10303e01fb6e5b5ef969db79 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 21 Mar 2020 17:38:44 +0300 Subject: feat: add github avatars to users --- src/components/GithubAvatar/GithubAvatar.tsx | 35 ++++++++++++++++++++++++++++ src/components/SolutionCard/SolutionCard.tsx | 9 ++----- 2 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 src/components/GithubAvatar/GithubAvatar.tsx (limited to 'src/components') 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 = ({ username }) => { + if (username === 'anonymous') return ; + + 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 ( + + + {altText} + + + ) +}; + +export default GithubAvatar; + diff --git a/src/components/SolutionCard/SolutionCard.tsx b/src/components/SolutionCard/SolutionCard.tsx index 5adbff9..7ec8888 100644 --- a/src/components/SolutionCard/SolutionCard.tsx +++ b/src/components/SolutionCard/SolutionCard.tsx @@ -6,7 +6,6 @@ import { CardHeader, CardContent, IconButton, - Avatar, Grid, Menu, MenuItem, @@ -18,6 +17,7 @@ import TimerIcon from '@material-ui/icons/Timer'; import MoreVertIcon from '@material-ui/icons/MoreVert'; import DeleteIcon from '@material-ui/icons/Delete'; +import GithubAvatar from '../GithubAvatar/GithubAvatar'; import { del } from '../../requests'; @@ -77,12 +77,7 @@ const SolutionCard: React.FC = ({ data, removeThisCard }) => { return ( ) - : - ({author[0].toUpperCase()}) - } + avatar={} title={author} subheader={date.toLocaleString('default', DATE_FORMAT)} action={ -- cgit v1.2.3