diff --git a/src/App.js b/src/App.js index 2cbe392..7a907b8 100644 --- a/src/App.js +++ b/src/App.js @@ -16,15 +16,16 @@ const api = process.env.REACT_APP_API || 'http://localhost:1337' console.log('Using api at ' + api) const defaultState = { - user: { name: 'Scott' }, loading: true, + user: { name: 'Scott' }, tasks: [], + projects: [], + component: 'projects', + // TODO try to get rid of: search: '', newTask: '', newProject: '', project: {}, - projects: [], - component: 'projects', } class App extends React.Component { @@ -89,6 +90,10 @@ class App extends React.Component { async addTask(e) { e.preventDefault() + if (!this.state.selectedProjectId) { + alert('No project selected, silly!') + return + } const newTask = { desc: this.state.newTask, projectName: this.state.projects.find( @@ -124,11 +129,10 @@ class App extends React.Component { async updateTask(e, updatedTask) { e.preventDefault() - console.log('updatedTask:', updatedTask) - const oldTask = this.state.tasks.find( - t => t.id === this.state.selectedTaskId, - ) + //console.log('updatedTask:', updatedTask) + const oldTask = this.state.tasks.find(t => t.id === updatedTask.id) if (JSON.stringify(oldTask) === JSON.stringify(updatedTask)) return + updatedTask['projectId'] = parseInt(updatedTask.projectId) try { const { data, error } = await axios.put( api + `/api/tasks/${oldTask.id}`, @@ -271,14 +275,9 @@ class App extends React.Component { console.log('Trying to update user profile: ', user) if (error) { alert('Received error when updating user profile: ', error) - } else if (data.desc && data.projectId) { + } else if (data) { + this.setState({ user: data }) console.log('Successfully updated user profile:', data) - // TODO this.setState({ tasks: this.state.tasks.concat(data), newTask: '' }) - } else { - console.log( - 'Received malformed data when updating user profile: ', - data, - ) } } catch (e) { alert(`Updating user profile failed: ${e}`) diff --git a/src/components/task-row.js b/src/components/task-row.js index fe82fd8..4c4685f 100644 --- a/src/components/task-row.js +++ b/src/components/task-row.js @@ -2,8 +2,7 @@ import React from 'react' const TaskRow = props => { const { task } = props - const project = props.projects.find(p => p.id === task.projectId) || 'None' - const projectName = project.name || 'None' + const project = props.projects.find(p => p.id === task.projectId) return (