From b1f05fa57c862ce8219e5ca464e794353261f842 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Sun, 21 Feb 2021 07:35:29 +0200 Subject: Migrate from public state map to Redux --- src/App.tsx | 4 +- src/components/InputTypes/Checkbox.tsx | 7 +- src/components/InputTypes/Select.tsx | 40 +++++++-- src/components/InputTypes/index.tsx | 13 +-- src/components/Question.tsx | 153 ++++++++++++++++++++------------- src/pages/FormPage.tsx | 38 +++++--- src/store/form/actions.ts | 79 +++++++++++++++++ src/store/form/reducers.ts | 29 +++++++ src/store/form/store.ts | 4 + src/store/form/types.ts | 5 ++ 10 files changed, 285 insertions(+), 87 deletions(-) create mode 100644 src/store/form/actions.ts create mode 100644 src/store/form/reducers.ts create mode 100644 src/store/form/store.ts create mode 100644 src/store/form/types.ts diff --git a/src/App.tsx b/src/App.tsx index 523e583..14e5329 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,6 +3,7 @@ import React, { Suspense } from "react"; import { jsx, css, Global } from "@emotion/react"; +import { Provider } from "react-redux"; import { BrowserRouter as Router, Route, @@ -14,6 +15,7 @@ import { PropagateLoader } from "react-spinners"; import { CSSTransition, TransitionGroup } from "react-transition-group"; import globalStyles from "./globalStyles"; +import { store } from "./store/form/store"; const LandingPage = React.lazy(() => import("./pages/LandingPage")); const FormPage = React.lazy(() => import("./pages/FormPage")); @@ -51,7 +53,7 @@ function App(): JSX.Element { {routes.map(({path, Component}) => ( }> - + {path == "/form/:id" ? : } ))} diff --git a/src/components/InputTypes/Checkbox.tsx b/src/components/InputTypes/Checkbox.tsx index 3093caf..b3130c6 100644 --- a/src/components/InputTypes/Checkbox.tsx +++ b/src/components/InputTypes/Checkbox.tsx @@ -3,6 +3,8 @@ import { jsx, css } from "@emotion/react"; import React, { ChangeEvent } from "react"; import colors from "../../colors"; import { multiSelectInput, hiddenInput } from "../../commonStyles"; +import {useSelector} from "react-redux"; +import {FormState} from "../../store/form/types"; interface CheckboxProps { index: number, @@ -53,10 +55,13 @@ const activeStyles = css` `; export default function Checkbox(props: CheckboxProps): JSX.Element { + const values = useSelector( + state => state.values + ); return (