1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2025-01-03 10:25:00 +01:00

refactor project nav

This commit is contained in:
Matthias Kretschmann 2018-06-22 18:54:29 +02:00
parent f88f01d285
commit ca348a3534
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 59 additions and 45 deletions

View File

@ -21,7 +21,7 @@
}, },
"dependencies": { "dependencies": {
"file-saver": "^1.3.8", "file-saver": "^1.3.8",
"gatsby": "^2.0.0-beta.6", "gatsby": "^2.0.0-beta.9",
"gatsby-image": "^2.0.0-beta.2", "gatsby-image": "^2.0.0-beta.2",
"gatsby-plugin-favicon": "^2.1.1", "gatsby-plugin-favicon": "^2.1.1",
"gatsby-plugin-matomo": "^0.4.0", "gatsby-plugin-matomo": "^0.4.0",

View File

@ -1,6 +1,6 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { Link } from 'gatsby' import { Link, graphql, StaticQuery } from 'gatsby'
import Img from 'gatsby-image' import Img from 'gatsby-image'
import styles from './ProjectNav.module.scss' import styles from './ProjectNav.module.scss'
@ -15,6 +15,31 @@ const ProjectLink = ({ node }) => (
</Link> </Link>
) )
const ProjectNavQuery = ({ render }) => (
<StaticQuery
query={graphql`
query ProjectsNavQuery {
allProjectsYaml {
edges {
node {
title
slug
img {
childImageSharp {
fluid(maxWidth: 500, quality: 85) {
...GatsbyImageSharpFluid_noBase64
}
}
}
}
}
}
}
`}
render={render}
/>
)
class ProjectNav extends Component { class ProjectNav extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
@ -40,31 +65,39 @@ class ProjectNav extends Component {
} }
render() { render() {
const { projects, project } = this.props const { slug } = this.props
return ( return (
<nav <ProjectNavQuery
className={styles.projectNav} render={data => {
ref={node => { const projects = data.allProjectsYaml.edges
this.scrollContainer = node
}}
>
{projects.map(({ node }) => {
const current = node.slug === project.slug
return ( return (
<div <nav
className={styles.item} className={styles.projectNav}
key={node.slug}
ref={node => { ref={node => {
if (current) this.currentItem = node this.scrollContainer = node
}} }}
> >
<ProjectLink node={node} /> {projects.map(({ node }) => {
</div> const current = node.slug === slug
return (
<div
className={styles.item}
key={node.slug}
ref={node => {
if (current) this.currentItem = node
}}
>
<ProjectLink node={node} />
</div>
)
})}
</nav>
) )
})} }}
</nav> />
) )
} }
} }
@ -74,8 +107,11 @@ ProjectLink.propTypes = {
} }
ProjectNav.propTypes = { ProjectNav.propTypes = {
projects: PropTypes.array, slug: PropTypes.string
project: PropTypes.object }
ProjectNavQuery.propTypes = {
render: PropTypes.any
} }
export default ProjectNav export default ProjectNav

View File

@ -1,5 +1,5 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import Link from 'gatsby' import { Link } from 'gatsby'
import giphyAPI from 'giphy-js-sdk-core' import giphyAPI from 'giphy-js-sdk-core'
import Layout from '../components/Layout' import Layout from '../components/Layout'
import Content from '../components/atoms/Content' import Content from '../components/atoms/Content'

View File

@ -45,7 +45,6 @@ class Project extends Component {
render() { render() {
const meta = this.props.data.dataYaml const meta = this.props.data.dataYaml
const projects = this.props.data.allProjectsYaml.edges
const project = this.props.data.projectsYaml const project = this.props.data.projectsYaml
const projectImages = this.props.data.projectImages.edges const projectImages = this.props.data.projectImages.edges
const { title, links, techstack } = project const { title, links, techstack } = project
@ -68,7 +67,7 @@ class Project extends Component {
</Content> </Content>
</article> </article>
<ProjectNav projects={projects} project={project} /> <ProjectNav slug={project.slug} />
</Layout> </Layout>
) )
} }
@ -123,11 +122,6 @@ export const projectAndProjectsQuery = graphql`
GitHub GitHub
Dribbble Dribbble
} }
availability {
status
available
unavailable
}
img { img {
childImageSharp { childImageSharp {
resize(width: 980) { resize(width: 980) {
@ -148,21 +142,5 @@ export const projectAndProjectsQuery = graphql`
} }
} }
} }
allProjectsYaml {
edges {
node {
title
slug
img {
childImageSharp {
fluid(maxWidth: 500, quality: 85) {
...GatsbyImageSharpFluid_noBase64
}
}
}
}
}
}
} }
` `