From 1f3c6cd5ec198fe8959c16190a93f08ad9ebd220 Mon Sep 17 00:00:00 2001 From: notnull Date: Fri, 21 Jun 2019 12:11:42 -0400 Subject: [PATCH] formatting / prettier fix --- src/App.js | 142 ++++++++++++++++++++++++++++--------- src/components/index.js | 5 -- src/components/navbar.js | 46 ++++++++---- src/components/profile.js | 4 +- src/components/project.js | 18 ++--- src/components/projects.js | 36 ++++++---- src/components/tasks.js | 117 +++++++++++++++++++++--------- 7 files changed, 257 insertions(+), 111 deletions(-) diff --git a/src/App.js b/src/App.js index 0498b35..00295d3 100644 --- a/src/App.js +++ b/src/App.js @@ -1,12 +1,27 @@ import React from 'react' import { About, Tasks, Profile, Projects, Project, Navbar } from './components' -const defaultState = { user: {}, loading: true, tasks: [], search: '', newTask: '', newProject: '', project: 0 } +const defaultState = { + user: {}, + loading: true, + tasks: [], + search: '', + newTask: '', + newProject: '', + project: 0, +} // hard-coded for now, but can be passed anything and set on state -const data = { user: { name: 'Scott', role: 'manager' }, component: 'tasks', - tasks: [{ id: 0, desc: 'arf', project: 1}, { id:1, desc: 'bruf', project: 0 }, { id: 2, desc: 'crap', project: 1 }], - projects: [{ id: 0, name: 'mop'}, { id: 1, name: 'biz'}]} +const data = { + user: { name: 'Scott', role: 'manager' }, + component: 'tasks', + tasks: [ + { id: 0, desc: 'arf', project: 1 }, + { id: 1, desc: 'bruf', project: 0 }, + { id: 2, desc: 'crap', project: 1 }, + ], + projects: [{ id: 0, name: 'mop' }, { id: 1, name: 'biz' }], +} class App extends React.Component { constructor() { @@ -35,45 +50,58 @@ class App extends React.Component { } navigate(component) { - this.setState( {component} ) + this.setState({ component }) } handleChange(e) { - this.setState( { [e.target.name]: e.target.value }) + this.setState({ [e.target.name]: e.target.value }) //console.log( this.state ) } handleSubmit(e) { e.preventDefault() - console.log("Search term: ", this.state.search) - this.setState({ search: ''}) + console.log('Search term: ', this.state.search) + this.setState({ search: '' }) } addTask(e) { e.preventDefault() - this.setState( { tasks: this.state.tasks.concat( { id: this.state.tasks.length, desc: this.state.newTask, project: this.state.project } ), newTask: '' }) + this.setState({ + tasks: this.state.tasks.concat({ + id: this.state.tasks.length, + desc: this.state.newTask, + project: this.state.project, + }), + newTask: '', + }) } deleteTask(id) { - this.setState( { tasks: this.state.tasks.filter(t => t.id !== id) }) + this.setState({ tasks: this.state.tasks.filter(t => t.id !== id) }) } completeTask(id) { - const otherTasks = this.state.tasks.filter(t=> t.id !== id) - const completedTask = this.state.tasks.find(t => t.id === id) - completedTask.completed = ! completedTask.completed - console.log(completedTask) - this.setState( { tasks: otherTasks.concat(completedTask) }) + const otherTasks = this.state.tasks.filter(t => t.id !== id) + const completedTask = this.state.tasks.find(t => t.id === id) + completedTask.completed = !completedTask.completed + console.log(completedTask) + this.setState({ tasks: otherTasks.concat(completedTask) }) } createProject(e) { e.preventDefault() - this.setState( { projects: this.state.projects.concat( { id: this.state.projects.length, name: this.state.newProject }), newProject: '' }) + this.setState({ + projects: this.state.projects.concat({ + id: this.state.projects.length, + name: this.state.newProject, + }), + newProject: '', + }) } editProject(id) { - this.setState( { project: id } ) - this.navigate('project') + this.setState({ project: id }) + this.navigate('project') } deleteProject(id) { //e.preventDefault() - this.setState( { projects: this.state.projects.filter(p => p.id !== id)}) + this.setState({ projects: this.state.projects.filter(p => p.id !== id) }) } renderLoading() { @@ -86,35 +114,79 @@ class App extends React.Component { return } renderProjects() { - return + return ( + + ) } renderProject() { - return + return ( + + ) } renderAbout() { return } renderTasks(filtered, completed) { // {...this.state} passes everything on state to the component - return + return ( + + ) } render() { - const completed = this.state.tasks.filter(task => task.completed === true) - const filtered = this.state.tasks.filter(task => task.completed !== true && this.state.search === task.desc.slice(0, this.state.search.length)) + const filtered = this.state.tasks.filter( + task => + task.completed !== true && + this.state.search === task.desc.slice(0, this.state.search.length), + ) - const renderComponent = () => this.state.loading ? this.renderLoading() - : this.state.component === 'tasks' ? this.renderTasks(filtered, completed) - : this.state.component === 'about' ? this.renderAbout() - : this.state.component === 'profile' ? this.renderProfile() - : this.state.component === 'projects' ? this.renderProjects() - : this.state.component === 'project' ? this.renderProject() - : this.renderError() + const renderComponent = () => + this.state.loading + ? this.renderLoading() + : this.state.component === 'tasks' + ? this.renderTasks(filtered, completed) + : this.state.component === 'about' + ? this.renderAbout() + : this.state.component === 'profile' + ? this.renderProfile() + : this.state.component === 'projects' + ? this.renderProjects() + : this.state.component === 'project' + ? this.renderProject() + : this.renderError() - return (
- - { renderComponent() } -
) + return ( +
+ + {renderComponent()} +
+ ) } } diff --git a/src/components/index.js b/src/components/index.js index f704b6a..b664437 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -1,11 +1,6 @@ -// this is just for exporting each component from this folder, -// so they can all be imported neatly into App using object destructuring - export { default as Navbar } from './navbar' export { default as About } from './about' export { default as Tasks } from './tasks' export { default as Profile } from './profile' export { default as Projects } from './projects' export { default as Project } from './project' -// export {default as CreateASign} from ./create-a-sign.js -// etc diff --git a/src/components/navbar.js b/src/components/navbar.js index efda7fd..e34c3a1 100644 --- a/src/components/navbar.js +++ b/src/components/navbar.js @@ -2,24 +2,42 @@ import React from 'react' function Navbar(props) { // props are passed from App as {...this.state} - return ( - ) } diff --git a/src/components/profile.js b/src/components/profile.js index 76566c0..750fcef 100644 --- a/src/components/profile.js +++ b/src/components/profile.js @@ -1,9 +1,7 @@ import React from 'react' function Profile(props) { - return ( -
You are { props.user.name }.
- ) + return
You are {props.user.name}.
} export default Profile diff --git a/src/components/project.js b/src/components/project.js index 6721f6b..e1e6471 100644 --- a/src/components/project.js +++ b/src/components/project.js @@ -2,16 +2,16 @@ import React from 'react' import Tasks from './tasks' function Project(props) { - console.log(props.projects) - const filtered = props.tasks.filter(t => t.project === props.project && !t.completed ) - const completed = props.tasks.filter(t => t.project === props.project && t.completed === true ) + console.log(props.projects) + const filtered = props.tasks.filter(t => t.project === props.project && !t.completed) + const completed = props.tasks.filter(t => t.project === props.project && t.completed === true) - return ( -
-

{props.projects[props.project].name}

- -
- ) + return ( +
+

{props.projects[props.project].name}

+ +
+ ) } export default Project diff --git a/src/components/projects.js b/src/components/projects.js index 880babd..6e01336 100644 --- a/src/components/projects.js +++ b/src/components/projects.js @@ -1,23 +1,33 @@ import React from 'react' function Projects(props) { - return ( -
+ return ( +

Projects

    - {props.projects.map(project => -
  • - - props.editProject(project.id) }>{project.name} -
  • ) - } -
    - + {props.projects.map(project => ( +
  • + + props.editProject(project.id)}>{project.name} +
  • + ))} + +
- -
- ) +
+ ) } export default Projects diff --git a/src/components/tasks.js b/src/components/tasks.js index 9c1765e..7ca6a5b 100644 --- a/src/components/tasks.js +++ b/src/components/tasks.js @@ -2,46 +2,99 @@ import React from 'react' function Tasks(props) { // props are passed from App as {...this.state} - const filtered = props.filtered || [] - const completed = props.completed || [] + const filtered = props.filtered || [] + const completed = props.completed || [] return (

Your open tasks

- props.handleChange(e)} /> - + props.handleChange(e)} + /> +
    - {filtered.map(task => -
  • - - {task.desc}{props.component === 'project' ? null - : props.editProject(task.project) }> ({props.projects[task.project].name})} - -
  • ) - } -
  • -
    - - { props.component === 'project' ? null : - - } -
    -
  • + {filtered.map(task => ( +
  • + + {task.desc} + {props.component === 'project' ? null : ( + props.editProject(task.project)}> + {' '} + ({props.projects[task.project].name}) + + )} + +
  • + ))} +
  • +
    + + {props.component === 'project' ? null : ( + + )} +
    +
- { completed.length === 0 ? null :

Completed

} -
    - {completed.map(task => -
  • - - {task.desc} - -
  • ) - } -
+ {completed.length === 0 ? null :

Completed

} +
    + {completed.map(task => ( +
  • + + {task.desc} + +
  • + ))} +
) }