summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-07-19 02:27:52 +0200
committerJules Laplace <julescarbon@gmail.com>2017-07-19 02:27:52 +0200
commit9c5b96aec109f7b37cb2c861525a084a65a817ea (patch)
tree3aa2f97b5134892a9f227c6c8fdc8cd778679771 /client
parent2f2c1ef4029dee17be0d16acdd60b7d1718d519f (diff)
adding tasks
Diffstat (limited to 'client')
-rw-r--r--client/actions/index.js3
-rw-r--r--client/containers/taskForm.js20
-rw-r--r--client/reducers/currentTask.js8
-rw-r--r--client/reducers/tasks.js3
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) {