diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/actions/index.js | 3 | ||||
| -rw-r--r-- | client/containers/taskForm.js | 20 | ||||
| -rw-r--r-- | client/reducers/currentTask.js | 8 | ||||
| -rw-r--r-- | client/reducers/tasks.js | 3 |
4 files changed, 20 insertions, 14 deletions
diff --git a/client/actions/index.js b/client/actions/index.js index 94d64c8..72df1c4 100644 --- a/client/actions/index.js +++ b/client/actions/index.js @@ -22,8 +22,9 @@ export const setAlpha = (alpha) => ({ type: 'SET_ALPHA', alpha, }) -export const createTask = () => ({ +export const createTask = (cb) => ({ type: 'CREATE_TASK', + cb }) export const addTask = (task) => ({ type: 'ADD_TASK', diff --git a/client/containers/taskForm.js b/client/containers/taskForm.js index 0e8aeac..9280ed3 100644 --- a/client/containers/taskForm.js +++ b/client/containers/taskForm.js @@ -1,15 +1,21 @@ import { connect } from 'react-redux' -import { setContent, setStyle, setAlpha, createTask } from '../actions' +import { setContent, setStyle, setAlpha, createTask, addTask } from '../actions' import TaskFormView from '../components/Tasks/TaskFormView.jsx' +import client from '../client' const mapStateToProps = (state) => state.currentTask -const mapDispatchToProps = { - clearContent: () => setContent(null), - clearStyle: () => setStyle(null), - setAlpha: (alpha) => setAlpha(alpha), - createTask: () => createTask(), -} +const mapDispatchToProps = (dispatch, ownProps) => ({ + clearContent: () => dispatch(setContent(null)), + clearStyle: () => dispatch(setStyle(null)), + setAlpha: (alpha) => dispatch(setAlpha(alpha)), + createTask: () => dispatch(createTask( (t) => { + console.log(client.task) + client.task.show(t.id).then( (task) => { + dispatch(addTask(task)) + }) + })), +}) const TaskForm = connect( mapStateToProps, diff --git a/client/reducers/currentTask.js b/client/reducers/currentTask.js index 126c35d..5f5fe52 100644 --- a/client/reducers/currentTask.js +++ b/client/reducers/currentTask.js @@ -26,10 +26,10 @@ const currentTask = (state = {}, action) => { tool: 'nsatf', completed: false, } - client.task.create( record ).then( (data) => { - data.content_file = state.content - data.style_file = state.file - // store.dispatch( addTask( data ) ) + client.task.create( record ).then( (task) => { + task.content_file = state.content + task.style_file = state.file + action.cb && action.cb(task) }) return state default: diff --git a/client/reducers/tasks.js b/client/reducers/tasks.js index 9edd82a..470c7a7 100644 --- a/client/reducers/tasks.js +++ b/client/reducers/tasks.js @@ -6,8 +6,7 @@ const tasks = (state = [], action) => { case 'LOAD_TASKS': return action.tasks case 'ADD_TASK': - console.log(action) - return state.concat([action.task]) + return [action.task].concat(state) case 'TASK_UPDATED': const updated_tasks = state.map(task => { if (task.id == id) { |
