Skip to content

Commit a27f50b

Browse files
committed
add dnd render for todo, inprogress, done
1 parent c6ea292 commit a27f50b

File tree

5 files changed

+61
-20
lines changed

5 files changed

+61
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tracker",
3-
"version": "1.0.6",
3+
"version": "1.0.16",
44
"private": true,
55
"dependencies": {
66
"@fortawesome/fontawesome-svg-core": "^1.2.18",

src/App.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import { Container } from 'react-bootstrap';
32
// import { Route, HashRouter as Router } from 'react-router-dom';
43
import { FORM_ADD, FORM_EDIT } from './lib/const';
54
import { NAV_ITEMS, NAV_MAIN } from './lib/nav_data';
@@ -100,7 +99,7 @@ export default class App extends React.Component {
10099

101100
render() {
102101
return (
103-
<Container>
102+
<div className="container">
104103
<Navigation items={this.navHelper()} />
105104
<React.Suspense fallback={<div> Loading....</div>}>
106105
{this.state.activeNavItem === NAV_MAIN ? (
@@ -111,15 +110,15 @@ export default class App extends React.Component {
111110
taskForEdit={this.state.taskForEdit}
112111
formSate={this.state.formSate}
113112
onSaveData={this.handleSaveFormData}
114-
onListClear = {this.handleClearList}
113+
onListClear={this.handleClearList}
115114
/>
116115
) : (
117116
<Dnd />
118117
)}
119118
{/* <Route exact path="/" render={props => <MainTab {...props} />} />
120119
<Route exact path="/dnd" render={props => <Dnd {...props} />} /> */}
121120
</React.Suspense>
122-
</Container>
121+
</div>
123122
);
124123
}
125124
}

src/components/main_form/index.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { faCalendar } from '@fortawesome/free-solid-svg-icons';
44
import PropTypes from 'prop-types';
55
import { Card } from '../card';
66
import { TextInput, TextArea, SelectInput, CheckboxInput } from '../form';
7-
import { TASK_OPTIONS, FORM_ADD, FORM_EDIT } from '../../lib/const';
7+
import { TASK_OPTIONS, FORM_ADD } from '../../lib/const';
88

99
export default class MainForm extends React.Component {
1010
static propTypes = {
@@ -54,7 +54,8 @@ export default class MainForm extends React.Component {
5454

5555
handleSaveData = (e) => {
5656
e.preventDefault();
57-
if (this.props.onSaveData({ ...this.state.data, id: new Date().valueOf() }) === true) {
57+
const { taskStatus = 'TODO' } = this.state.data;
58+
if (this.props.onSaveData({ ...this.state.data, taskStatus, id: new Date().valueOf() }) === true) {
5859
this.setState({ data: {} });
5960
}
6061
}
@@ -109,7 +110,7 @@ export default class MainForm extends React.Component {
109110
</div>
110111

111112
<SelectInput
112-
value={this.state.data.taskStatus || ''}
113+
value={this.state.data.taskStatus || 'TODO'}
113114
options={TASK_OPTIONS}
114115
name='taskStatus'
115116
onChange={this.handleChange}
@@ -144,7 +145,6 @@ export default class MainForm extends React.Component {
144145
className="btn btn-secondary"
145146
onClick={this.handleResetData}
146147
>
147-
148148
{
149149
this.props.formSate === FORM_ADD ? "Clear form" : "Cancel"
150150
}

src/screens/DnD.jsx

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,62 @@
11
import React from 'react';
2+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3+
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
4+
5+
const renderOneTask = (item) => {
6+
return (
7+
<li key={item.id}
8+
className="list-group-item"
9+
style={{ position: "relative" }}>
10+
{
11+
item.taskUrgent && (<FontAwesomeIcon icon={faExclamationTriangle} />)
12+
}
13+
<a
14+
href="#"
15+
// onClick={this.handleViewTask}
16+
data-id={item.id}
17+
>
18+
{item.taskName}
19+
</a>
20+
<br />
21+
<span className="text-muted">
22+
<small>
23+
{item.taskDate}
24+
</small>
25+
</span>
26+
<br />
27+
</li>
28+
)
29+
};
30+
31+
32+
const DnD = (props) => {
33+
const [state, setState] = React.useState({
34+
todo: [],
35+
inprogress: [],
36+
done: []
37+
});
38+
39+
React.useEffect(() => {
40+
const string = localStorage.getItem('TASKS');
41+
const taskList = JSON.parse(string);
42+
const todo = taskList.filter(item => item.taskStatus === 'TODO');
43+
const inprogress = taskList.filter(item => item.taskStatus === 'INPROGRESS');
44+
const done = taskList.filter(item => item.taskStatus === 'DONE');
45+
setState({ todo, inprogress, done });
46+
}, []);
47+
48+
const emptyList = <li className="list-group-item">
49+
<strong className="text-secondary">Список пуст</strong>
50+
</li>;
251

3-
const DnD = () => {
452
return (
553
<div className="row" style={{ marginTop: '20px' }}>
654
<div className="col-sm-4">
755
<div className="card">
856
<div className="card-body card-body-dnd">
957
<h3>To Do</h3>
1058
<ul className="list-group">
11-
<li className="list-group-item">
12-
<strong className="text-secondary">Список пуст</strong>
13-
</li>
59+
{state.todo.length ? state.todo.map(renderOneTask) : emptyList}
1460
</ul>
1561
</div>
1662
</div>
@@ -20,9 +66,7 @@ const DnD = () => {
2066
<div className="card-body card-body-dnd">
2167
<h3>In progress</h3>
2268
<ul className="list-group">
23-
<li className="list-group-item">
24-
<strong className="text-secondary">Список пуст</strong>
25-
</li>
69+
{state.inprogress.length ? state.inprogress.map(renderOneTask) : emptyList}
2670
</ul>
2771
</div>
2872
</div>
@@ -32,9 +76,7 @@ const DnD = () => {
3276
<div className="card-body card-body-dnd">
3377
<h3>Done</h3>
3478
<ul className="list-group">
35-
<li className="list-group-item">
36-
<strong className="text-secondary">Список пуст</strong>
37-
</li>
79+
{state.done.length ? state.done.map(renderOneTask) : emptyList}
3880
</ul>
3981
</div>
4082
</div>

src/screens/main.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const MainTab = (props) => {
1818
<MainList
1919
onTaskEdit={props.onTaskEdit}
2020
onTaskDelete={props.onTaskDelete}
21-
onListClear = {props.onListClear}
21+
onListClear={props.onListClear}
2222
data={props.taskList}
2323
/>
2424
</div>

0 commit comments

Comments
 (0)