-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marvin Heilemann
committed
Oct 1, 2019
1 parent
5c7c1b7
commit 4047160
Showing
25 changed files
with
436 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { useContext } from 'react' | ||
import { useStaticQuery, graphql, Link } from 'gatsby' | ||
import { GlobalContext } from '../context' | ||
|
||
const Breadcrumb = ({ location: { pathname } }) => { | ||
const { | ||
site: { siteMetadata }, | ||
} = useStaticQuery(query) | ||
const [state] = useContext(GlobalContext) | ||
|
||
const fragments = pathname.split('/') | ||
fragments.shift() | ||
fragments.pop() | ||
|
||
const menuLinks = siteMetadata.menuLinks | ||
// const menuLinks = [ | ||
// { | ||
// name: 'Projects', | ||
// link: '/projects', | ||
// }, | ||
// { | ||
// name: 'Demo', | ||
// link: '/projects/demo', | ||
// }, | ||
// ] | ||
|
||
console.log(state) | ||
console.log(menuLinks) | ||
console.log(fragments) | ||
|
||
const path = menuLinks.filter(({ name, link }) => { | ||
const menuIndex = fragments.indexOf(name.toLowerCase()) | ||
if (menuIndex > -1) { | ||
const menu = menuLinks[menuIndex] | ||
console.log(menu) | ||
return menu | ||
} | ||
return false | ||
}) | ||
|
||
console.log(path) | ||
console.log(path.length) | ||
|
||
return state.title ? ( | ||
<div id="back"> | ||
<span>/ </span> | ||
{path.map(({ name, link }, index) => ( | ||
<> | ||
<Link to={link}>{name}</Link> | ||
{index < path.length ? <span> / </span> : ''} | ||
</> | ||
))} | ||
<span>{state.title}</span> | ||
</div> | ||
) : null | ||
} | ||
|
||
const query = graphql` | ||
{ | ||
site { | ||
siteMetadata { | ||
menuLinks { | ||
name | ||
link | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
export default Breadcrumb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,16 @@ | ||
import React from 'react' | ||
import React, { useState } from 'react' | ||
|
||
const defaultContextValue = { | ||
data: { | ||
menuOpen: false, | ||
}, | ||
set: () => {}, | ||
const DEFAULT_STATE = { | ||
title: null, | ||
} | ||
|
||
const { Provider, Consumer } = React.createContext(defaultContextValue) | ||
const GlobalContext = React.createContext([DEFAULT_STATE, () => {}]) | ||
const { Consumer, Provider } = GlobalContext | ||
|
||
class ContextProviderComponent extends React.Component { | ||
constructor(props) { | ||
super(props) | ||
const GlobalProvider = props => { | ||
const [state, setState] = useState(DEFAULT_STATE) | ||
|
||
this.setData = this.setData.bind(this) | ||
this.state = { | ||
...defaultContextValue, | ||
set: this.setData, | ||
} | ||
} | ||
|
||
setData(newData) { | ||
this.setState(state => ({ | ||
data: { | ||
...state.data, | ||
...newData, | ||
}, | ||
})) | ||
} | ||
|
||
render() { | ||
return <Provider value={this.state}>{this.props.children}</Provider> | ||
} | ||
return <Provider value={[state, setState]}>{props.children}</Provider> | ||
} | ||
|
||
export { Consumer as ContextConsumer, ContextProviderComponent } | ||
export { Consumer as GlobalConsumer, GlobalProvider, GlobalContext } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import React from 'react' | ||
import { ContextProviderComponent } from '../context' | ||
import { GlobalProvider } from '../context' | ||
import { HelmetProvider } from 'react-helmet-async' | ||
|
||
import Header from './Header' | ||
|
||
const Layout = ({ children }) => ( | ||
<ContextProviderComponent> | ||
const App = ({ children, location }) => ( | ||
<GlobalProvider> | ||
<HelmetProvider> | ||
<Header></Header> | ||
<Header location={location}></Header> | ||
<main>{children}</main> | ||
</HelmetProvider> | ||
</ContextProviderComponent> | ||
</GlobalProvider> | ||
) | ||
|
||
export default Layout | ||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
import React from 'react' | ||
import { Helmet } from 'react-helmet-async' | ||
import { ContextConsumer } from '../context' | ||
import SEO from '../components/SEO' | ||
|
||
const Page = () => ( | ||
<ContextConsumer> | ||
{({ data, set }) => ( | ||
<> | ||
<SEO title="ERROR" /> | ||
<Helmet bodyAttributes={{ page: 'error' }} /> | ||
<> | ||
<SEO title="ERROR" /> | ||
<Helmet bodyAttributes={{ page: 'error' }} /> | ||
|
||
<h1>ERROR</h1> | ||
</> | ||
)} | ||
</ContextConsumer> | ||
<h1>ERROR</h1> | ||
</> | ||
) | ||
|
||
export default Page |
Oops, something went wrong.