2020-02-05 18:12:54 +03:00
|
|
|
// As seen here, we can import npm packages used in code generated by Wasp, which will be clearly defined.
|
|
|
|
// In the future, we will of course also be able to specify additional packages as dependencies.
|
2020-01-21 21:34:59 +03:00
|
|
|
import React from 'react'
|
2020-02-14 14:30:16 +03:00
|
|
|
import { connect } from 'react-redux'
|
2020-01-21 21:34:59 +03:00
|
|
|
|
2020-02-05 18:12:54 +03:00
|
|
|
// As seen here, we can import specific components/code generated by Wasp.
|
|
|
|
// These will have well defined and documented APIs and paths.
|
2020-02-06 13:53:52 +03:00
|
|
|
// Note that Task, NewTaskForm and TaskList are generated based on the declarations
|
2020-02-05 18:12:54 +03:00
|
|
|
// we made in todoApp.wasp file.
|
2020-01-21 21:34:59 +03:00
|
|
|
import NewTaskForm from '@wasp/entities/task/components/NewTaskForm'
|
2020-01-29 14:53:22 +03:00
|
|
|
import TaskList from '@wasp/entities/task/components/TaskList'
|
2020-02-14 14:30:16 +03:00
|
|
|
import * as taskState from '@wasp/entities/task/state.js'
|
|
|
|
import * as taskActions from '@wasp/entities/task/actions.js'
|
2020-03-01 19:20:14 +03:00
|
|
|
import ToggleIsDoneButton from '@wasp/components/ToggleIsDoneButton'
|
|
|
|
import DeleteDoneButton from '@wasp/components/DeleteDoneButton'
|
2020-01-21 21:34:59 +03:00
|
|
|
|
2020-02-14 14:30:16 +03:00
|
|
|
class Todo extends React.Component {
|
2020-02-05 18:12:54 +03:00
|
|
|
// TODO: prop types.
|
2020-01-30 13:23:04 +03:00
|
|
|
|
2020-02-05 18:12:54 +03:00
|
|
|
isAnyTaskCompleted = () => this.props.taskList.some(t => t.isDone)
|
|
|
|
|
|
|
|
isThereAnyTask = () => this.props.taskList.length > 0
|
|
|
|
|
2020-01-21 21:34:59 +03:00
|
|
|
render = () => {
|
2020-01-23 18:31:00 +03:00
|
|
|
return (
|
2020-02-05 20:58:14 +03:00
|
|
|
<div className="todos">
|
|
|
|
<div className="todos__container">
|
|
|
|
<h1> Todos </h1>
|
2020-01-21 21:34:59 +03:00
|
|
|
|
2020-02-05 20:58:14 +03:00
|
|
|
<div className="todos__toggleAndInput">
|
2020-03-01 19:20:14 +03:00
|
|
|
<ToggleIsDoneButton
|
2020-02-05 13:47:58 +03:00
|
|
|
disabled={!this.isThereAnyTask()}
|
2020-02-05 20:58:14 +03:00
|
|
|
className="todos__toggleButton"
|
2020-03-01 19:20:14 +03:00
|
|
|
/>
|
2020-02-05 13:47:58 +03:00
|
|
|
|
|
|
|
<NewTaskForm
|
2020-02-05 20:58:14 +03:00
|
|
|
className="todos__newTaskForm"
|
2020-02-05 13:47:58 +03:00
|
|
|
onCreate={task => this.props.addTask(task)}
|
|
|
|
submitButtonLabel={'Create new task'}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-02-05 12:52:54 +03:00
|
|
|
|
2020-02-05 20:58:14 +03:00
|
|
|
{ this.isThereAnyTask() && (<>
|
2020-03-01 19:20:14 +03:00
|
|
|
<TaskList editable />
|
2020-01-23 18:31:00 +03:00
|
|
|
|
2020-02-05 20:58:14 +03:00
|
|
|
<div className="todos__footer">
|
|
|
|
<div className="todos__footer__itemsLeft">
|
2020-02-05 13:47:58 +03:00
|
|
|
{ this.props.taskList.filter(task => !task.isDone).length } items left
|
|
|
|
</div>
|
|
|
|
|
2020-02-05 20:58:14 +03:00
|
|
|
<div className="todos__footer__clearCompleted">
|
2020-03-01 19:20:14 +03:00
|
|
|
<DeleteDoneButton
|
|
|
|
className={this.isAnyTaskCompleted() ? '' : 'hidden' }
|
|
|
|
/>
|
2020-02-05 13:47:58 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-02-05 20:58:14 +03:00
|
|
|
</>)}
|
|
|
|
</div>
|
2020-01-21 21:34:59 +03:00
|
|
|
</div>
|
2020-01-23 18:31:00 +03:00
|
|
|
)
|
2020-01-21 21:34:59 +03:00
|
|
|
}
|
|
|
|
}
|
2020-02-14 14:30:16 +03:00
|
|
|
|
|
|
|
export default connect(state => ({
|
|
|
|
taskList: taskState.selectors.all(state)
|
|
|
|
}), {
|
2020-03-01 19:20:14 +03:00
|
|
|
addTask: taskActions.add
|
2020-02-14 14:30:16 +03:00
|
|
|
})(Todo)
|