diff --git a/src/App.js b/src/App.js
index d944a7f..7fd9da1 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,7 +1,7 @@
import React from 'react'
import axios from 'axios'
-import { About, Tasks, Profile, Projects, Project, Navbar } from './components'
+import { About, Tasks, Task, Profile, Projects, Project, Navbar } from './components'
const api = process.env.REACT_APP_API || 'http://localhost:1337'
//console.log(process.env)
@@ -31,6 +31,8 @@ class App extends React.Component {
this.completeTask = this.completeTask.bind(this)
this.createProject = this.createProject.bind(this)
this.selectProject = this.selectProject.bind(this)
+ this.selectTask = this.selectTask.bind(this)
+ this.updateTask = this.updateTask.bind(this)
this.deleteProject = this.deleteProject.bind(this)
}
@@ -108,6 +110,28 @@ class App extends React.Component {
alert(`Failed to add task: ${e}`)
}
}
+
+ async updateTask(e) {
+ e.preventDefault()
+ const task = this.state.tasks.find(t => t.id === this.state.selectedTaskId)
+ // TODO update properties from form
+ console.log(e.target)
+ try {
+ const { data, error } = await axios.put(api + `/api/tasks/${task.id}`, task)
+ console.log('Tried to update task.')
+ if (error) {
+ alert('Received error when updating task: ', error)
+ } else if (data.desc && data.projectId) {
+ console.log('Successfully updated task:', data)
+ // TODO this.setState({ tasks: this.state.tasks.concat(data), newTask: '' })
+ } else {
+ console.log('Received malformed data when updating task: ', data)
+ }
+ } catch (e) {
+ alert(`Updating task failed: ${e}`)
+ }
+ }
+
async deleteTask(id) {
this.setState({ tasks: this.state.tasks.filter(t => t.id !== id) })
try {
@@ -144,6 +168,10 @@ class App extends React.Component {
alert(`Failed to complete task ${task.desc}: ${e}`)
}
}
+ selectTask(id) {
+ this.setState({ selectedTaskId: id })
+ this.navigate('task')
+ }
async createProject(e) {
e.preventDefault()
@@ -228,6 +256,7 @@ class App extends React.Component {
handleChange={this.handleChange}
createProject={this.createProject}
selectProject={this.selectProject}
+ selectTask={this.selectTask}
deleteProject={this.deleteProject}
addTask={this.addTask}
completeTask={this.completeTask}
@@ -250,11 +279,22 @@ class App extends React.Component {
deleteTask={this.deleteTask}
filtered={filtered}
completed={completed}
+ selectTask={this.selectTask}
selectProject={this.selectProject}
{...this.state}
/>
)
}
+ renderTask() {
+ return (
+