Browse Source

[FIX] reducers updating

Gogs 7 years ago
parent
commit
b6a6f0916f

+ 2 - 2
src/actions/index.js

@@ -71,7 +71,7 @@ export const spinner = (show, message) => dispatch => {
  * 
  * @param {*} text 
  */
-export const notify = message => dispatch  => {
+export const notify = message => (dispatch, getState)  => {
     dispatch({
         type: message ? 'SHOW_NOTIFICATION' : 'HIDE_NOTIFICATION',
         payload: { message }
@@ -82,7 +82,7 @@ export const notify = message => dispatch  => {
  * 
  * @param {*} resource 
  */
-export const get = resource => async dispatch => {
+export const get = resource => async (dispatch, getState) => {
     dispatch({ type: 'REQUEST_INIT' })
 
     try {

+ 1 - 1
src/components/pages/RequestsList.js

@@ -40,7 +40,7 @@ class RequestsList extends Component {
                                 <TableRow key={item.id}>
                                     <TableCell>{item.create_at}</TableCell>
                                     <TableCell>{item.name}</TableCell>
-                                    <TableCell>{item.user ? item.user.username : 'Anónimo'}</TableCell>
+                                    <TableCell>{item.user ? item.user.username : 'anónimo'}</TableCell>
                                     <TableCell>{item.status[1]}</TableCell>
                                 </TableRow>
                             )}

+ 15 - 2
src/components/pages/TasksList.js

@@ -6,8 +6,8 @@ import Table, { TableHead, TableBody, TableRow, TableCell } from 'material-ui/Ta
 import Dialog, { DialogActions, DialogContent, DialogContentText, DialogTitle } from 'material-ui/Dialog'
 import TextField from 'material-ui/TextField'
 import { isEqual, isEmpty } from 'lodash'
-import { ODOO } from '../../constants/ResourceNames'
-import { post } from '../../actions'
+import { ODOO, REQUEST } from '../../constants/ResourceNames'
+import { post, get } from '../../actions'
 import { connect } from 'react-redux'
 import { withStyles } from 'material-ui/styles'
 
@@ -29,6 +29,13 @@ class TasksList extends Component {
         }
     }
 
+    /**
+     * 
+     */
+    componentDidMount() {
+        this.props.loadData()
+    }
+
     /**
      * 
      */
@@ -175,6 +182,12 @@ class TasksList extends Component {
  * @param {*} props 
  */
 const mapDispatchToProps = (dispatch, props) => ({
+    /**
+     * 
+     */
+    loadData() {
+        dispatch(get(`${REQUEST}?last`))
+    },
     /**
      * 
      */

+ 6 - 10
src/reducers/containers.js

@@ -1,10 +1,6 @@
 import { createReducer } from '../utils/reducer'
 import { has, map, isEqual } from 'lodash'
 
-const initialState = {
-    containers: []
-}
-
 /**
  * 
  * @param {*} containers 
@@ -13,14 +9,14 @@ const initialState = {
 const setContainers = (containers, action) => {
     // single instance
     if (has(action.payload, 'container')) {
-        return map(containers, c => {
+        containers = map(containers, c => {
             return isEqual(c.id, action.payload.container.id) ? action.payload.container : c
         })
     }
 
     // multiple instances
     if (has(action.payload, 'containers')) {
-        return action.payload.containers
+        containers = action.payload.containers
     }
 
     return containers
@@ -29,13 +25,13 @@ const setContainers = (containers, action) => {
 /**
  * 
  */
-const containersReducer = createReducer(initialState.containers, {
+const containersReducer = createReducer([], {
     'REQUEST_OK': setContainers
 })
 
 /**
  * 
  */
-export const containers = (state = initialState, action) => {
-    return containersReducer(state.containers, action)
-}
+export const containers = (state = [], action) => {
+    return containersReducer(state, action)
+}

+ 1 - 1
src/utils/reducer.js

@@ -9,4 +9,4 @@ export const createReducer = (initialState, handlers) => {
     return (state = initialState, action) => {
         return has(handlers, action.type) ? handlers[action.type](state, action) : state
     }
-}
+}