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 { availability {
status status
available
unavailable
} }
gpg gpg
addressbook addressbook
typekitID
} }
# the package.json file # the package.json file

View File

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

View File

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

View File

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

View File

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