-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtask.component.js
More file actions
105 lines (88 loc) · 3.51 KB
/
task.component.js
File metadata and controls
105 lines (88 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { Chip, Tooltip } from '@material-ui/core';
import React, { Component } from 'react';
import Checkbox from '@material-ui/core/Checkbox';
import Icon from '@material-ui/core/Icon';
import IconButton from '@material-ui/core/IconButton';
import classNames from 'classnames';
import dateformat from 'dateformat';
class Task extends Component {
// this.props.index === 0
componentDidUpdate() {
if (this.props.isSelected) {
this.titleInput.focus();
} else {
this.titleInput.blur();
}
}
render() {
return (
<div className={classNames({
task: true,
completed: this.props.task.status === 'completed',
selected: this.props.isSelected,
})} onMouseOver={this.props.onMouseOver}>
{this.props.task.parent &&
<div className="child-space"/>
}
<Tooltip title={dateformat(new Date(this.props.task.updated), 'dd/mm/yyyy')}>
<Checkbox readOnly={this.props.isReadOnly} checked={this.props.task.status === 'completed'} onChange={this.props.onCheck} />
</Tooltip>
<div className="task-container">
<input
type="text"
ref={(titleInput) => this.titleInput = titleInput}
placeholder="What do you want to do?"
readOnly={this.props.isReadOnly}
value={this.props.task.title}
className="task-title"
onChange={event => this.props.onTaskUpdate(event.target.value)}
onKeyUp={this.handleKeyUp.bind(this)}
onKeyDown={this.handleKeyDown.bind(this)} />
<p className="task-description">{this.props.task.notes}</p>
</div>
{this.props.task.notes &&
<div className="chip-container">
<Tooltip title={this.props.task.notes}>
<Chip label="Details" />
</Tooltip>
</div>
}
{this.props.task.due &&
<div className="chip-container">
<Chip label={dateformat(new Date(this.props.task.due), 'dd/mm/yyyy', true)} />
</div>
}
<Tooltip title="Edit Task (Ctrl + Q)">
<div>
<IconButton disabled={this.props.isReadOnly} onClick={this.props.onEdit}>
<Icon>edit</Icon>
</IconButton>
</div>
</Tooltip>
<Tooltip title="Delete Task (Ctrl + D)">
<div>
<IconButton disabled={this.props.isReadOnly} onClick={this.props.onDelete}>
<Icon>delete</Icon>
</IconButton>
</div>
</Tooltip>
</div>
);
}
handleKeyUp(event) {
const enterKey = 13;
if (event.keyCode === enterKey) {
event.preventDefault();
event.stopPropagation();
}
}
handleKeyDown(event) {
const backspaceKey = 8;
if (event.keyCode === backspaceKey && this.props.task.title.length === 0) {
this.props.onDelete();
event.preventDefault();
event.stopPropagation();
}
}
}
export default Task;