1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-12-23 01:29:41 +01:00

Merge pull request #93 from kremalicious/fix/duplication

fix some code duplication
This commit is contained in:
Matthias Kretschmann 2019-02-12 12:35:31 +01:00 committed by GitHub
commit 29272ccaba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 36 deletions

View File

@ -13,36 +13,25 @@ import icons from '../atoms/Icons.module.scss'
import styles from './ProjectLinks.module.scss' import styles from './ProjectLinks.module.scss'
const LinkIcon = ({ title, type, ...props }) => { const LinkIcon = ({ title, type, ...props }) => {
if (type) { let typeOrTitle = type ? type : title
switch (type) {
case 'website':
return <Link {...props} />
case 'github':
return <GitHub {...props} />
case 'dribbble':
return <Dribbble {...props} />
case 'info':
return <Info {...props} />
case 'download':
return <Download {...props} />
case 'styleguide':
return <Styleguide {...props} />
default:
return null
}
}
switch (title) { switch (typeOrTitle) {
case 'website':
case 'Link': case 'Link':
return <Link {...props} /> return <Link {...props} />
case 'github':
case 'GitHub': case 'GitHub':
return <GitHub {...props} /> return <GitHub {...props} />
case 'dribbble':
case 'Dribbble': case 'Dribbble':
return <Dribbble {...props} /> return <Dribbble {...props} />
case 'info':
case 'Info': case 'Info':
return <Info {...props} /> return <Info {...props} />
case 'download':
case 'Download': case 'Download':
return <Download {...props} /> return <Download {...props} />
case 'styleguide':
case 'Styleguide': case 'Styleguide':
return <Styleguide {...props} /> return <Styleguide {...props} />
default: default:

View File

@ -41,6 +41,10 @@ class ProjectLink extends PureComponent {
} }
} }
ProjectLink.propTypes = {
node: PropTypes.object
}
export default class ProjectNav extends PureComponent { export default class ProjectNav extends PureComponent {
state = { state = {
scrolledToCurrent: false scrolledToCurrent: false
@ -68,6 +72,20 @@ export default class ProjectNav extends PureComponent {
this.scrollContainer.scrollLeft += finalPosition this.scrollContainer.scrollLeft += finalPosition
} }
Project({ node, slug }) {
const current = node.slug === slug
return (
<div
className={styles.item}
key={node.slug}
ref={node => current && (this.currentItem = node)}
>
<ProjectLink node={node} />
</div>
)
}
render() { render() {
const { slug } = this.props const { slug } = this.props
@ -82,19 +100,9 @@ export default class ProjectNav extends PureComponent {
className={styles.projectNav} className={styles.projectNav}
ref={node => (this.scrollContainer = node)} ref={node => (this.scrollContainer = node)}
> >
{projects.map(({ node }) => { {projects.map(({ node }) => (
const current = node.slug === slug <this.Project key={node.id} node={node} slug={slug} />
))}
return (
<div
className={styles.item}
key={node.slug}
ref={node => current && (this.currentItem = node)}
>
<ProjectLink node={node} />
</div>
)
})}
</nav> </nav>
) )
}} }}
@ -103,10 +111,6 @@ export default class ProjectNav extends PureComponent {
} }
} }
ProjectLink.propTypes = {
node: PropTypes.object
}
ProjectNav.propTypes = { ProjectNav.propTypes = {
slug: PropTypes.string slug: PropTypes.string
} }