-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global State, although doesn't solve issue. Will change location direct
- Loading branch information
Showing
9 changed files
with
103 additions
and
224 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
/** | ||
* Implement Gatsby's Browser APIs in this file. | ||
* | ||
* See: https://www.gatsbyjs.org/docs/browser-apis/ | ||
*/ | ||
import React from "react" | ||
import GlobalContextProvider from "./src/context/GlobalContextProvider" | ||
|
||
// You can delete this file if you're not using it | ||
export const wrapRootElement = ({ element }) => { | ||
return <GlobalContextProvider>{element}</GlobalContextProvider> | ||
} |
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,7 +1,7 @@ | ||
/** | ||
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file. | ||
* | ||
* See: https://www.gatsbyjs.org/docs/ssr-apis/ | ||
*/ | ||
const React = require("react") | ||
const GlobalContextProvider = require("./src/context/GlobalContextProvider") | ||
.default | ||
|
||
// You can delete this file if you're not using it | ||
exports.wrapRootElement = ({ element }) => { | ||
return <GlobalContextProvider>{element}</GlobalContextProvider> | ||
} |
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 |
---|---|---|
|
@@ -21,5 +21,6 @@ const Footer = () => ( | |
</p> | ||
</div> | ||
</section> | ||
) | ||
) | ||
|
||
export default Footer |
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
Empty file.
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,63 @@ | ||
import React from "react" | ||
import { graphql, useStaticQuery } from 'gatsby' | ||
|
||
export const GlobalStateContext = React.createContext() | ||
export const GlobalDispatchContext = React.createContext() | ||
|
||
|
||
function reducer(state, action) { | ||
switch (action.type) { | ||
case "TOGGLE_THEME": { | ||
return { | ||
...state, | ||
theme: state.theme === "light" ? "dark" : "light", | ||
} | ||
} | ||
default: | ||
throw new Error("Bad Action Type") | ||
} | ||
} | ||
|
||
const GlobalContextProvider = ({ children }) => { | ||
const globalData = useStaticQuery(graphql`query { | ||
countries: allCountriesJson(sort: {order: DESC, fields: highest_confirmed}, filter: {highest_confirmed: {gte: 10}, population: {gte: 1000000}}) { | ||
nodes { | ||
country_name | ||
id | ||
time_series { | ||
date | ||
confirmed | ||
confirmed_per_mil | ||
deaths | ||
deaths_per_mil | ||
recovered | ||
recovered_per_mil | ||
} | ||
highest_confirmed | ||
population | ||
} | ||
} | ||
select_countries: allCountriesJson(sort: {order: ASC, fields: country_name}, filter: {highest_confirmed: {gte: 10}, population: {gte: 1000000}}) { | ||
nodes { | ||
country_name | ||
highest_confirmed | ||
} | ||
} | ||
}`) | ||
|
||
|
||
const [state, dispatch] = React.useReducer(reducer, { | ||
countries: globalData.countries.nodes, | ||
select_countries: globalData.select_countries.nodes | ||
}); | ||
|
||
return ( | ||
<GlobalStateContext.Provider value={state}> | ||
<GlobalDispatchContext.Provider value={dispatch}> | ||
{children} | ||
</GlobalDispatchContext.Provider> | ||
</GlobalStateContext.Provider> | ||
) | ||
} | ||
|
||
export default GlobalContextProvider |
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
Oops, something went wrong.