From d7f7fc5a5127257f2214a09edd774ccabae221be Mon Sep 17 00:00:00 2001
From: Ignacio Peluaga
Date: Sun, 7 Mar 2021 22:55:35 +0100
Subject: [PATCH] Redux ok
---
src/App.tsx | 31 ++++++++++---
src/actions/FilterFormActions.ts | 21 +++++++++
src/components/FilterForm.tsx | 73 ++++++++++---------------------
src/components/UniversityList.tsx | 3 +-
src/components/db.json | 2 -
src/containers/FilterForm.tsx | 29 ++++++++++--
src/states/globalState.ts | 7 +--
7 files changed, 99 insertions(+), 67 deletions(-)
create mode 100644 src/actions/FilterFormActions.ts
diff --git a/src/App.tsx b/src/App.tsx
index f6f0cd0..9996178 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -3,14 +3,34 @@ import Menu from './components/Menu'
import TopHeader from './components/TopHeader'
import MainNav from './components/MainNav'
import Introduction from './components/Introduction'
-import UniversityList from './styledComponents/UniversityList'// no necesitan estado global de redux
+import UniversityList from './styledComponents/UniversityList'// hasta este no necesitan estado global de redux
import FilterForm from './containers/FilterForm' //utiliza store de redux
import { Action, createStore } from 'redux';
import IGlobalState, { initialState } from './states/globalState'
import { Provider } from 'react-redux'
+import { IAreaChangeAction, IResultsChangeAction, ITipoChangeAction, IUniChangeAction } from './actions/FilterFormActions';
+import { FilterFormActions } from './actions/FilterFormActions'
//recibe un estado y una acción. Devuelve el resultado de aplicar al estado la acción
-const reducer = (state: IGlobalState = initialState, action: Action) => {
+const reducer = (state: IGlobalState = initialState, action: Action) => {
+ switch (action.type) {
+ case FilterFormActions.CHANGE_UNI: // aquí iria 'uni' pq está cambiando esa propiedad # TODO: usar enum # TODO: debe haber un case por cada una de las 4 acciones
+ const uniAction = action as IUniChangeAction;
+ return {...state, uni: uniAction.payload}
+
+ case FilterFormActions.CHANGE_AREA:
+ const areaAction = action as IAreaChangeAction;
+ return {...state, area: areaAction.payload}
+
+ case FilterFormActions.CHANGE_TIPO:
+ const tipoAction = action as ITipoChangeAction;
+ console.log(tipoAction.payload)
+ return {...state, tipo: tipoAction.payload}
+
+ case FilterFormActions.CHANGE_RESULTS:
+ const resultsAction = action as IResultsChangeAction;
+ return {...state, results: resultsAction.payload}
+ }
return state;
}
@@ -28,7 +48,7 @@ function App() {
- {/*REMOVED 1 FROM HERE*/}
+
@@ -62,7 +82,7 @@ function App() {
pueden elegir todas las opciones académicas que ofrecen los siguientes
Establecimientos Universitarios Públicos de la Comunidad:
- {/* REFACTORING SHOULD START HERE # TODO: use redux and jss */}
+ {/* REFACTORING STARTS HERE */}
@@ -70,9 +90,8 @@ function App() {
- {/* REFACTORING SHOULD END HERE */}
+ {/* REFACTORING ENDS HERE */}
-