add new projects and tasks via websocket only

This commit is contained in:
data 2019-10-05 16:18:27 +01:00
parent d128262c31
commit a53d397ac1
4 changed files with 2 additions and 6 deletions

View File

@ -49,7 +49,6 @@ const defaultState = {
tasks: [], tasks: [],
projects: [], projects: [],
component: 'projects', component: 'projects',
// TODO try to get rid of:
search: '', search: '',
newArticle: '', newArticle: '',
newTask: '', newTask: '',

View File

@ -14,6 +14,7 @@ function Project(props) {
return ( return (
<div> <div>
<span className="btn btn-primary" onClick={() => props.navigate('projects')}>Back</span>
<h2>{project.name}</h2> <h2>{project.name}</h2>
<Tasks filtered={filtered} completed={completed} {...props} /> <Tasks filtered={filtered} completed={completed} {...props} />
</div> </div>

View File

@ -14,7 +14,7 @@ export async function createProject(e) {
alert(`Received error when creating project ${project.name}: ${error}`) alert(`Received error when creating project ${project.name}: ${error}`)
} else if (data.id) { } else if (data.id) {
this.setState({ this.setState({
projects: this.state.projects.concat(data), // projects: this.state.projects.concat(data),
newProject: '', newProject: '',
}) })
console.log(`Added project: `, data) console.log(`Added project: `, data)

View File

@ -7,7 +7,6 @@ export async function createTask(e) {
alert("Why don't you enter a name for this task?") alert("Why don't you enter a name for this task?")
return return
} }
const newTask = { const newTask = {
desc: this.state.newTask, desc: this.state.newTask,
projectId: this.state.selectedProjectId, projectId: this.state.selectedProjectId,
@ -16,7 +15,6 @@ export async function createTask(e) {
alert('Task description is empty.') alert('Task description is empty.')
return return
} }
try { try {
console.log('Adding task: ', newTask) console.log('Adding task: ', newTask)
const { data, error } = await axios.post(API + '/api/tasks', newTask) const { data, error } = await axios.post(API + '/api/tasks', newTask)
@ -47,8 +45,6 @@ export async function updateTask(e, updatedTask) {
if (error) { if (error) {
alert('Received error when updating task: ', error) alert('Received error when updating task: ', error)
} else if (data.desc && data.projectId) { } else if (data.desc && data.projectId) {
const oldTasks = this.state.tasks.filter(t => t.id !== updatedTask.id)
this.setState({ tasks: oldTasks.concat(updatedTask) })
console.log('Successfully updated task:', data) console.log('Successfully updated task:', data)
} else { } else {
console.log('Received malformed data when updating task: ', data) console.log('Received malformed data when updating task: ', data)