From e49aea0c7e63877931e66bd5876bb155e5917dc4 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 19 Dec 2020 03:38:04 +0200 Subject: [PATCH] application state --- src/App.js | 12 --------- src/components/{layout/Main.js => App.js} | 13 +++++---- src/index.js | 8 +++--- src/state/initialState.js | 3 +++ src/state/reducer.js | 33 +++++++++++++++++++++++ 5 files changed, 49 insertions(+), 20 deletions(-) delete mode 100644 src/App.js rename src/components/{layout/Main.js => App.js} (64%) create mode 100644 src/state/initialState.js create mode 100644 src/state/reducer.js diff --git a/src/App.js b/src/App.js deleted file mode 100644 index fb7c4f0..0000000 --- a/src/App.js +++ /dev/null @@ -1,12 +0,0 @@ -import React, { Suspense } from "react"; -import Main from "./components/layout/Main"; - -function App() { - return ( - Loading...}> -
- - ); -} - -export default App; diff --git a/src/components/layout/Main.js b/src/components/App.js similarity index 64% rename from src/components/layout/Main.js rename to src/components/App.js index 2303946..4e0bfa2 100644 --- a/src/components/layout/Main.js +++ b/src/components/App.js @@ -1,7 +1,9 @@ -import React from "react"; -import ApplicationStepper from "./stepper/ApplicationStepper"; -import Switcher from "./Switcher"; +import React, { useReducer } from "react"; +import ApplicationStepper from "./layout/stepper/ApplicationStepper"; +import Switcher from "./layout/Switcher"; import { makeStyles } from "@material-ui/core/styles"; +import { initialState } from "../state/initialState"; +import { reducer } from "../state/reducer"; const useStyles = makeStyles(() => ({ app: { @@ -22,8 +24,9 @@ const useStyles = makeStyles(() => ({ } })); -const Main = () => { +const App = () => { const classes = useStyles(); + const [state, dispatch] = useReducer(reducer, initialState); return (
@@ -35,4 +38,4 @@ const Main = () => { ); }; -export default Main; +export default App; diff --git a/src/index.js b/src/index.js index 67f7ebb..a2bfdab 100644 --- a/src/index.js +++ b/src/index.js @@ -1,13 +1,15 @@ -import React from "react"; +import React, { Suspense } from "react"; import ReactDOM from "react-dom"; import "./index.css"; -import App from "./App"; +import App from "./components/App"; import { BrowserRouter as Router } from "react-router-dom"; ReactDOM.render( - + Loading...
}> + + , document.getElementById("root") diff --git a/src/state/initialState.js b/src/state/initialState.js new file mode 100644 index 0000000..f7d5d33 --- /dev/null +++ b/src/state/initialState.js @@ -0,0 +1,3 @@ +export const initialState = { + credentials: {} +}; diff --git a/src/state/reducer.js b/src/state/reducer.js new file mode 100644 index 0000000..69c8911 --- /dev/null +++ b/src/state/reducer.js @@ -0,0 +1,33 @@ +export function reducer(state, action) { + switch (action.type) { + case "OnPagerChange": { + return { + ...state, + pager: { + ...state.pager, + ...action.payload + } + }; + } + case "OnExportRequest": { + return { + ...state, + export: action.value + }; + } + default: { + return state; + } + } +} + +export const dispatchActions = dispatch => ({ + onFilterPropertyValueChange: (prop, value) => + dispatch({ type: "OnFilterPropertyValueChange", payload: { prop, value } }), + + onPagerChange: pager => + dispatch({ type: "OnPagerChange", payload: { ...pager } }), + onSetCachedFilters: cachedFilters => + dispatch({ type: "OnSetCachedFilters", payload: cachedFilters }), + onExportRequest: value => dispatch({ type: "OnExportRequest", value: value }) +});