Skip to content

Commit

Permalink
fix: race condition on data
Browse files Browse the repository at this point in the history
This is caused by the data loading late waiting for a static query that is in the preview and shouldn't be.
  • Loading branch information
talves committed Mar 26, 2019
1 parent 7e50184 commit b390843
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 79 deletions.
46 changes: 17 additions & 29 deletions src/cms/preview-templates/IndexPagePreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,23 @@ import PropTypes from 'prop-types'
import { IndexPageTemplate } from '../../templates/index-page'

const IndexPagePreview = ({ entry, getAsset }) => {
const entryBlurbs = entry.getIn(['data', 'intro', 'blurbs'])
const blurbs = entryBlurbs ? entryBlurbs.toJS() : []

return (
<IndexPageTemplate
image={entry.getIn(['data', 'image'])}
title={entry.getIn(['data', 'title'])}
heading={entry.getIn(['data', 'heading'])}
subheading={entry.getIn(['data', 'subheading'])}
description={entry.getIn(['data', 'description'])}
intro={{ blurbs }}
main={{
heading: entry.getIn(['data', 'main', 'heading']),
description: entry.getIn(['data', 'main', 'description']),
mainpitch: {
title: entry.getIn(['data', 'mainpitch', 'title']),
description: entry.getIn(['data', 'mainpitch', 'description']),
},
image1: {
image: getAsset(entry.getIn(['data', 'main', 'image1', 'image'])),
alt: entry.getIn(['data', 'main', 'image1', 'alt']),
},
image2: {
image: getAsset(entry.getIn(['data', 'main', 'image2', 'image'])),
alt: entry.getIn(['data', 'main', 'image2', 'alt']),
},
}}
/>
)
const data = entry.getIn(['data']).toJS()

if (data) {
return (
<IndexPageTemplate
image={data.image}
title={data.title}
heading={data.heading}
subheading={data.subheading}
description={data.description}
intro={data.intro || { blurbs: [] }}
mainpitch={data.mainpitch || {}}
/>
)
} else {
return (<div>Loading...</div>)
}
}

IndexPagePreview.propTypes = {
Expand Down
58 changes: 9 additions & 49 deletions src/pages/index.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
---
templateKey: 'index-page'
title: 'Great coffee with a conscience'
templateKey: index-page
title: Great coffee with a conscience
image: /img/home-jumbotron.jpg
heading: Great coffee with a conscience
subheading: Support sustainable farming while enjoying a cup
mainpitch:
title: Why Kaldi
description: >
Kaldi is the coffee store for everyone who believes that great coffee
shouldn't just taste good, it should do good too. We source all of our beans
directly from small scale sustainable farmers and make sure part of the
profits are reinvested in their communities.
description: >-
Kaldi is the ultimate spot for coffee lovers who want to learn about their
java’s origin and support the farmers that grew it. We take coffee production,
roasting and brewing seriously and we’re glad to pass that knowledge to
anyone.
mainpitch:
title: Why Kaldi
description: >
Kaldi is the coffee store for everyone who believes that
great coffee shouldn't just taste good, it should do good
too. We source all of our beans directly from small scale
sustainable farmers and make sure part of the profits are
reinvested in their communities.
intro:
blurbs:
- image: /img/coffee.png
Expand Down Expand Up @@ -68,43 +67,4 @@ main:
image3:
alt: Coffee beans
image: /img/products-grid1.jpg
testimonials:
- author: Elisabeth Kaurismäki
quote: >-
The first time I tried Kaldi’s coffee, I couldn’t even believe that was
the same thing I’ve been drinking every morning.
- author: Philipp Trommler
quote: >-
Kaldi is the place to go if you want the best quality coffee. I love their
stance on empowering farmers and transparency.
full_image: /img/products-full-width.jpg
pricing:
heading: Monthly subscriptions
description: >-
We make it easy to make great coffee a part of your life. Choose one of our
monthly subscription plans to receive great coffee at your doorstep each
month. Contact us about more details and payment info.
plans:
- description: Perfect for the drinker who likes to enjoy 1-2 cups per day.
items:
- 3 lbs of coffee per month
- Green or roasted beans"
- One or two varieties of beans"
plan: Small
price: '50'
- description: 'Great for avid drinkers, java-loving couples and bigger crowds'
items:
- 6 lbs of coffee per month
- Green or roasted beans
- Up to 4 different varieties of beans
plan: Big
price: '80'
- description: Want a few tiny batches from different varieties? Try our custom plan
items:
- Whatever you need
- Green or roasted beans
- Unlimited varieties
plan: Custom
price: '??'
---

1 change: 0 additions & 1 deletion src/templates/index-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const IndexPageTemplate = ({
mainpitch,
description,
intro,
main,
}) => (
<div>
<div
Expand Down

0 comments on commit b390843

Please sign in to comment.