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

isolate some graphql queries

This commit is contained in:
Matthias Kretschmann 2018-06-21 22:32:56 +02:00
parent 2706eb77c7
commit f88f01d285
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 67 additions and 38 deletions

View File

@ -61,12 +61,9 @@ const TemplateWrapper = ({ children, location }) => {
}
availability {
status
available
unavailable
}
gpg
addressbook
typekitID
}
# the package.json file

View File

@ -5,7 +5,7 @@ import SEO from './SEO'
import Typekit from './Typekit'
const Head = ({ meta }) => {
const { title, tagline, typekitID } = meta
const { title, tagline } = meta
return (
<Fragment>
@ -16,7 +16,7 @@ const Head = ({ meta }) => {
<meta name="apple-mobile-web-app-title" content={title.toLowerCase()} />
</Helmet>
{typekitID && <Typekit id={typekitID} />}
<Typekit />
<SEO meta={meta} />
</Fragment>

View File

@ -1,13 +1,14 @@
import React from 'react'
import PropTypes from 'prop-types'
import { StaticQuery, graphql } from 'gatsby'
import Helmet from 'react-helmet'
const TypekitScript = props => (
const TypekitScript = typekitID => (
<script>
{`
(function(d) {
var config = {
kitId: '${props.id}',
kitId: '${typekitID}',
scriptTimeout: 3000,
async: true
},
@ -17,13 +18,30 @@ const TypekitScript = props => (
</script>
)
const Typekit = props => (
<Helmet>
<link rel="dns-prefetch" href="https://use.typekit.net/" />
<link rel="dns-prefetch" href="https://p.typekit.net/" />
const Typekit = () => (
<StaticQuery
query={graphql`
query TypekitQuery {
dataYaml {
typekitID
}
}
`}
render={data => {
const { typekitID } = data.dataYaml
{TypekitScript(props)}
</Helmet>
return (
typekitID && (
<Helmet>
<link rel="dns-prefetch" href="https://use.typekit.net/" />
<link rel="dns-prefetch" href="https://p.typekit.net/" />
{TypekitScript(typekitID)}
</Helmet>
)
)
}}
/>
)
export default Typekit

View File

@ -1,5 +1,6 @@
import React, { Fragment, PureComponent } from 'react'
import PropTypes from 'prop-types'
import { StaticQuery, graphql } from 'gatsby'
import { MoveIn } from '../atoms/Animations'
import styles from './Availability.module.scss'
@ -9,35 +10,51 @@ class Availability extends PureComponent {
}
render() {
const { availability } = this.props.meta
const { status, available, unavailable } = availability
return (
<Fragment>
{!this.props.hide && (
<MoveIn>
<aside
className={
<StaticQuery
query={graphql`
query AvailabilityQuery {
dataYaml {
availability {
status
? `${styles.availability} ${styles.available}`
: `${styles.availability} ${styles.unavailable}`
available
unavailable
}
>
<p
dangerouslySetInnerHTML={{
__html: status ? available : unavailable
}}
/>
</aside>
</MoveIn>
)}
</Fragment>
}
}
`}
render={data => {
const { availability } = data.dataYaml
const { status, available, unavailable } = availability
return (
<Fragment>
{!this.props.hide && (
<MoveIn>
<aside
className={
status
? `${styles.availability} ${styles.available}`
: `${styles.availability} ${styles.unavailable}`
}
>
<p
dangerouslySetInnerHTML={{
__html: status ? available : unavailable
}}
/>
</aside>
</MoveIn>
)}
</Fragment>
)
}}
/>
)
}
}
Availability.propTypes = {
meta: PropTypes.object,
hide: PropTypes.bool
}

View File

@ -46,10 +46,7 @@ class Header extends PureComponent {
<Networks meta={meta} hide={!isHomepage} />
<Availability
meta={meta}
hide={!isHomepage && !meta.availability.status}
/>
<Availability hide={!isHomepage && !meta.availability.status} />
</header>
)
}