Skip to content

Commit

Permalink
Updates to site showcase (#6095)
Browse files Browse the repository at this point in the history
* refactor: general cleanup

* add: support deep linking to filters

* add: make categories on showcase detail link to filtered list

* refactor: filtering is now cumulative

* refactor: remove core-js dep
  • Loading branch information
kkemple authored and KyleAMathews committed Jul 3, 2018
1 parent ad76e04 commit 020ef8a
Show file tree
Hide file tree
Showing 11 changed files with 1,187 additions and 943 deletions.
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)

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

0 comments on commit 020ef8a

Please sign in to comment.