diff --git a/src/actions/task.js b/src/actions/task.js new file mode 100644 index 0000000..a100cd2 --- /dev/null +++ b/src/actions/task.js @@ -0,0 +1,7 @@ +// action types +export const SET_DATA = 'SET_DATA'; + +export const setTaskData = (data) => ({ + type: SET_DATA, + payload: data +}); diff --git a/src/pages/TaskListPage/TodoListContainer/index.jsx b/src/pages/TaskListPage/TodoListContainer/index.jsx index dc77789..8349e93 100644 --- a/src/pages/TaskListPage/TodoListContainer/index.jsx +++ b/src/pages/TaskListPage/TodoListContainer/index.jsx @@ -2,15 +2,11 @@ import React, { Component } from "react"; import TodoList from "../TodoList"; import { connect } from "react-redux"; import { setLoader } from "../../../actions/ui"; +import { setTaskData } from "../../../actions/task"; class TodoListContainer extends Component { constructor(props) { super(props); - this.state = { - list: [], - filterApplied: false, - hideTimer: false - }; this.toggleTimer = this.toggleTimer.bind(this); this.toggleListItem = this.toggleListItem.bind(this); this.performAddTask = this.performAddTask.bind(this); @@ -23,12 +19,10 @@ class TodoListContainer extends Component { fetch("http://localhost:3000/data/tasks.json") .then(response => response.json()) .then(data => { - this.setState({ - list: data.list - }); - setTimeout(function() { - __this.props.setLoaderProp(false); - }, 5000) + this.props.setTaskDataProp(data.list); + setTimeout(function() { + __this.props.setLoaderProp(false); + }, 5000) }) .catch(function(error) { console.error(error); @@ -63,8 +57,7 @@ class TodoListContainer extends Component { } render() { - const { filterApplied } = this.state; - const { list, loading } = this.props; + const { list, loading, filterApplied } = this.props; return ( { return { loading: state.ui.loading, - list: state.tasks.data + list: state.tasks.data, + filterApplied: state.tasks.filterApplied, + hideTimer: state.tasks.hideTimer } } const mapDispacthToProps = dispatch => { return { - setLoaderProp: (show) => dispatch(setLoader(show)) + setLoaderProp: (show) => dispatch(setLoader(show)), + setTaskDataProp: (data) => dispatch(setTaskData(data)) } } diff --git a/src/reducers/initialState.js b/src/reducers/initialState.js index 5e7c237..38ac03f 100644 --- a/src/reducers/initialState.js +++ b/src/reducers/initialState.js @@ -4,7 +4,9 @@ const initialState = { notifcations: [] }, tasks:{ - data: [] + data: [], + filterApplied: false, + hideTimer: false }, dashboard: { data: [] diff --git a/src/reducers/tasks.js b/src/reducers/tasks.js index 8010294..f012068 100644 --- a/src/reducers/tasks.js +++ b/src/reducers/tasks.js @@ -1,8 +1,17 @@ // reducer for UI +import { SET_DATA } from '../actions/task'; import initialState from './initialState'; const tasksReducer = (state=initialState.tasks, action) => { - return state; + switch(action.type) { + case SET_DATA: + return { + ...state, + data: action.payload + }; + default: + return state; + } }; export default tasksReducer;