Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to site showcase #6095

Merged
merged 5 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions www/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"globals": {
"graphql": true
},
"rules": {
"react/prop-types": [0]
}
}
4 changes: 3 additions & 1 deletion www/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ exports.createPages = ({ graphql, actions }) => {
edge => {
const slug = _.get(edge, `node.fields.slug`)
const draft = _.get(edge, `node.frontmatter.draft`)
if (!slug) return
if (!slug) return undefined

if (_.includes(slug, `/blog/`) && !draft) {
return edge
}

return undefined
}
)

Expand Down
5 changes: 3 additions & 2 deletions www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@
"mousetrap": "^1.6.1",
"parse-filepath": "^1.0.2",
"prismjs": "^1.14.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"qs": "^6.5.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-helmet": "^5.2.0",
"react-icons": "^2.2.7",
"react-instantsearch": "^4.5.1",
Expand Down
20 changes: 17 additions & 3 deletions www/src/components/showcase-details.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from "react"
import React, { Fragment } from "react"
import { graphql } from "gatsby"
import Helmet from "react-helmet"
import url from "url"
import hex2rgba from "hex2rgba"
import Img from "gatsby-image"
import qs from "qs"

import presets, { colors } from "../utils/presets"
import { options, scale, rhythm } from "../utils/typography"
Expand Down Expand Up @@ -98,7 +99,7 @@ const cleanUrl = mainUrl => {
return parsed.hostname + path
}

export default ({ parent, data, isModal, categories }) => (
const ShowcaseDetails = ({ parent, data, isModal, categories }) => (
<StaticQuery
query={graphql`
query allSitesYamlTemplateShowcase {
Expand Down Expand Up @@ -524,7 +525,18 @@ export default ({ parent, data, isModal, categories }) => (
>
Categories{` `}
</div>
<div> {categories.join(`, `)} </div>
<div>
{categories.map((c, i) => (
<Fragment key={c}>
<Link
to={`/showcase?${qs.stringify({ filters: [c] })}`}
>
{c}
</Link>
{i === categories.length - 1 ? `` : `, `}
</Fragment>
))}
</div>
</div>
</div>
</div>
Expand All @@ -534,3 +546,5 @@ export default ({ parent, data, isModal, categories }) => (
}}
/>
)

export default ShowcaseDetails
50 changes: 50 additions & 0 deletions www/src/components/url-query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Component } from "react"
import { withRouter } from "react-router-dom"
import qs from "qs"

class URLQuery extends Component {
state = {}

componentDidMount = () => {
const {
history,
location: { search },
} = this.props

this.getDerivedStateFromQuery(search)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too much? 😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice... i use a react-router-state-manager utility if you wanna just use that


this.unlisten = history.listen(({ search }) => {
this.getDerivedStateFromQuery(search)
})
}

componentWillUnmount = () => {
this.unlisten()
}

getDerivedStateFromQuery = search => {
const { filters } = qs.parse(search.replace(`?`, ``))

this.setState(() => {
return {
filters: filters || [],
}
})
}

updateQuery = fn => {
const {
history: { push },
location: { pathname },
} = this.props

const newQuery = fn(this.state)
const queryString = qs.stringify(newQuery)

push(`${pathname}?${queryString}`)
}

render = () => this.props.children(this.state, this.updateQuery)
}

export default withRouter(URLQuery)
Loading