diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-03-21 18:00:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-21 18:00:45 +0300 |
commit | 8e48a481be6fdcb6c4ff926165379f79a045fe00 (patch) | |
tree | 3e7c1abb50ab4b6f0ee8d08146cae8bd5475e985 /src | |
parent | e89a7a79622d25561dc80a8489ae1f6022aebd73 (diff) | |
parent | c708ed105c580ed23bf27b6b5ed1e312ed139f57 (diff) | |
download | chrono-cube-ui-8e48a481be6fdcb6c4ff926165379f79a045fe00.tar.gz |
Merge pull request #49 from eug-vs/githubAvatars
Add fancy avatars from GitHub
Diffstat (limited to 'src')
-rw-r--r-- | src/components/GithubAvatar/GithubAvatar.tsx | 39 | ||||
-rw-r--r-- | src/components/SolutionCard/SolutionCard.tsx | 9 | ||||
-rw-r--r-- | src/pages/Contribute/Contribute.tsx | 40 |
3 files changed, 57 insertions, 31 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; + 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<PropTypes> = ({ data, removeThisCard }) => { return ( <Card className={classes.root}> <CardHeader - avatar={ - author === 'anonymous'? - (<Avatar/>) - : - (<Avatar>{author[0].toUpperCase()}</Avatar>) - } + avatar={<GithubAvatar username={author} />} title={author} subheader={date.toLocaleString('default', DATE_FORMAT)} action={ diff --git a/src/pages/Contribute/Contribute.tsx b/src/pages/Contribute/Contribute.tsx index 4c37fb9..67f2b8a 100644 --- a/src/pages/Contribute/Contribute.tsx +++ b/src/pages/Contribute/Contribute.tsx @@ -6,7 +6,6 @@ import { List, ListItem, Link, - Avatar, Divider, makeStyles, } from '@material-ui/core'; @@ -16,6 +15,7 @@ import BugReportIcon from '@material-ui/icons/BugReport'; import NewReleasesIcon from '@material-ui/icons/NewReleases'; import { Window, ContentSection } from 'react-benzin'; +import GithubAvatar, { getUserGithubUrl } from '../../components/GithubAvatar/GithubAvatar'; import developers from '../../developers.json'; @@ -111,31 +111,23 @@ const Contribute: React.FC = () => { <ContentSection sectionName="Developers"> <List> { - developers.map(developer => { - const githubUrl = `https://github.com/${developer.username}`; - - return ( - <div key={developer.username}> - <ListItem> - <Link href={githubUrl}> - <Avatar alt={developer.username} src={`${githubUrl}.png`} /> - </Link> - <div> - <Link href={githubUrl}> - {developer.username} - </Link> - <Typography component="div" color="textSecondary"> - {developer.role} - </Typography> - </div> - </ListItem> - <Divider variant="middle" /> - </div> - ) - }) + developers.map(developer => ( + <div key={developer.username}> + <ListItem> + <GithubAvatar username={developer.username} /> + <div> + <Link href={getUserGithubUrl(developer.username)}>{developer.username}</Link> + <Typography component="div" color="textSecondary"> + {developer.role} + </Typography> + </div> + </ListItem> + <Divider variant="middle" /> + </div> + )) } <ListItem> - <Avatar /> + <GithubAvatar username="anonymous" /> You can be here! </ListItem> </List> |