diff --git a/gatsby-browser.ts b/gatsby-browser.ts new file mode 100644 index 000000000..553d5b0ff --- /dev/null +++ b/gatsby-browser.ts @@ -0,0 +1,3 @@ +import wrapWithProvider from "./wrap-with-provider"; + +export const wrapRootElement = wrapWithProvider; diff --git a/gatsby-ssr.ts b/gatsby-ssr.ts new file mode 100644 index 000000000..553d5b0ff --- /dev/null +++ b/gatsby-ssr.ts @@ -0,0 +1,3 @@ +import wrapWithProvider from "./wrap-with-provider"; + +export const wrapRootElement = wrapWithProvider; diff --git a/src/state/creators.ts b/src/state/creators.ts new file mode 100644 index 000000000..a958b1c01 --- /dev/null +++ b/src/state/creators.ts @@ -0,0 +1,10 @@ +import { SET_SCENARIO } from "./types"; +import { ScenarioType } from "../types/scenario"; +import { SetScenarioActionType } from "../types/actions"; + +export const setScenario = (scenario: ScenarioType): SetScenarioActionType => { + return { + type: SET_SCENARIO, + payload: scenario, + }; +}; diff --git a/src/state/index.ts b/src/state/index.ts new file mode 100644 index 000000000..986ab0a72 --- /dev/null +++ b/src/state/index.ts @@ -0,0 +1,20 @@ +import { legacy_createStore as createStore, applyMiddleware } from "redux"; +import thunk from "redux-thunk"; +import { SET_SCENARIO } from "./types"; +import { ScenarioType } from "../types/scenario"; +import { ScenarioActionTypes } from "../types/actions"; + +const scenarioReducer = ( + state = {}, + action: ScenarioActionTypes, +): ScenarioType => { + switch (action.type) { + case SET_SCENARIO: + return { ...state, ...action.payload }; + + default: + return state; + } +}; + +export default createStore(scenarioReducer, applyMiddleware(thunk)); diff --git a/src/state/types.ts b/src/state/types.ts new file mode 100644 index 000000000..18c64a0b8 --- /dev/null +++ b/src/state/types.ts @@ -0,0 +1,5 @@ +export const SET_SCENARIO = "SET_SCENARIO"; +export const MODIFY_SCENARIO_PROPERTY = "MODIFY_SCENARIO_PROPERTY"; +export const MODIFY_MASS_PROPERTY = "MODIFY_MASS_PROPERTY"; +export const ADD_MASS = "ADD_MASS"; +export const DELETE_MASS = "DELETE_MASS"; diff --git a/src/types/actions.ts b/src/types/actions.ts new file mode 100644 index 000000000..ff51b736c --- /dev/null +++ b/src/types/actions.ts @@ -0,0 +1,8 @@ +import { ScenarioType } from "./scenario"; + +export type SetScenarioActionType = { + type: string; + payload: ScenarioType; +}; + +export type ScenarioActionTypes = SetScenarioActionType; diff --git a/wrap-with-provider.tsx b/wrap-with-provider.tsx new file mode 100644 index 000000000..760f56305 --- /dev/null +++ b/wrap-with-provider.tsx @@ -0,0 +1,11 @@ +import React, { ReactElement, ReactNode } from "react"; +import { Provider } from "react-redux"; +import store from "./src/state"; + +type Props = { + element: ReactNode; +}; + +export default ({ element }: Props): ReactElement => ( + {element} +);