From 7cb02cead11c74eaf90c06656bbdc134d9f24a85 Mon Sep 17 00:00:00 2001 From: Joni Laukka <joni.laukka.overflow@gmail.com> Date: Thu, 27 Jun 2019 11:25:24 +0300 Subject: [PATCH] show new task count --- src/components/TaskList.js | 1 + src/components/TaskListButton.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/TaskList.js b/src/components/TaskList.js index 15acb5d..1a6e7f0 100644 --- a/src/components/TaskList.js +++ b/src/components/TaskList.js @@ -47,6 +47,7 @@ class TaskList extends React.Component{ return ReactDOM.createPortal( <div className='tasklist'> + <h1>Tasklist</h1> {token && <div className='task-form'> <input type='text' placeholder='Task name' value={this.state.taskName} onChange={(e) => this.setState({taskName: e.target.value})}></input> diff --git a/src/components/TaskListButton.js b/src/components/TaskListButton.js index 31c98e9..045e6c1 100644 --- a/src/components/TaskListButton.js +++ b/src/components/TaskListButton.js @@ -6,19 +6,29 @@ class TaskListButton extends React.Component{ super(props); this.state = { open: false, - newTasks: '0' + newTasks: 0 } this.handleClick = this.handleClick.bind(this); } + componentDidMount(){ + this.getNewTask(); + } + + getNewTask(){ + this.setState({ + newTasks: this.state.open ? 0 : this.state.newTasks + 1 + }); + } + handleClick = (e) => { this.setState({ open: !this.state.open },() =>{ // Set new task cout to zero when the tasklist opens if(this.state.open){ - this.setState({newTasks: '0'}) + this.setState({newTasks: 0}) } }); } -- GitLab