Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 22b5bf6

Browse files
todo status changed, label colors added
1 parent 1d6fedd commit 22b5bf6

File tree

6 files changed

+39
-14
lines changed

6 files changed

+39
-14
lines changed

src/components/todo/TodoBox.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import React from 'react';
2-
import { TodoActionControls } from '../todo';
2+
import { Tag, Divider } from 'antd';
3+
import { TodoActionControls, TodoLabel } from '../todo';
34

45
export default function TodoBox(props) {
56
const { data } = props;
67
return (
78
<div className="kanban__box">
8-
<h4>{data.title}</h4>
9+
<h4>
10+
{data.title} <TodoLabel data={data} />
11+
</h4>
12+
913
<div>{data.description}</div>
1014
<TodoActionControls {...props} />
1115
</div>

src/components/todo/TodoLabel.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import React, { useState, useEffect } from 'react';
2-
import { TODO_STATUS } from '../../helpers/constants';
2+
import { Tag } from 'antd';
3+
import { TODO_LABEL } from '../../helpers/constants';
34

45
export default function TodoLabel({ data }) {
5-
const [label, setLabel] = useState('');
6+
const [state, setState] = useState({
7+
color: '',
8+
key: '',
9+
});
610

711
useEffect(() => {
812
if (data) {
9-
let obj = TODO_STATUS.find((status) => status.id === data.status);
13+
let obj = TODO_LABEL.find((status) => status.id === data.label);
1014
if (obj) {
11-
setLabel(obj.key);
15+
setState(obj);
1216
}
1317
}
1418
}, [data]);
15-
16-
return <div className="title-label">{label}</div>;
19+
return <Tag color={state.color}>{state.key}</Tag>;
1720
}

src/components/todo/TodoList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState, useEffect } from 'react';
22
import { API } from '../../services';
3-
import { DeleteTodo, TodoBox, TodoLabel } from '../todo';
3+
import { DeleteTodo, TodoBox, TodoStatus } from '../todo';
44
import { mapValues, groupBy } from 'lodash';
55

66
export default function TodoList() {
@@ -52,7 +52,7 @@ export default function TodoList() {
5252
{grouped &&
5353
Object.entries(grouped).map(([key, values], i) => (
5454
<div key={i} className="kanban__group">
55-
<TodoLabel data={values[0]} />
55+
<TodoStatus data={values[0]} />
5656
{values.map((data) => (
5757
<TodoBox key={data._id} data={data} />
5858
))}

src/components/todo/TodoStatus.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, { useState, useEffect } from 'react';
2+
import { TODO_STATUS } from '../../helpers/constants';
3+
4+
export default function TodoStatus({ data }) {
5+
const [label, setLabel] = useState('');
6+
7+
useEffect(() => {
8+
if (data) {
9+
let obj = TODO_STATUS.find((status) => status.id === data.status);
10+
if (obj) {
11+
setLabel(obj.key);
12+
}
13+
}
14+
}, [data]);
15+
16+
return <div className="title-label">{label}</div>;
17+
}

src/components/todo/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export { default as TodoBox } from './TodoBox';
44
export { default as TodoDelete } from './TodoDelete';
55
export { default as TodoLabel } from './TodoLabel';
66
export { default as TodoList } from './TodoList';
7+
export { default as TodoStatus } from './TodoStatus';
78
export { default as TodoStatusChange } from './TodoStatusChange';

src/helpers/constants.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export const TODO_STATUS = [
88
];
99

1010
export const TODO_LABEL = [
11-
{ id: 1, key: 'PERSONAL' },
12-
{ id: 2, key: 'WORK' },
13-
{ id: 3, key: 'SHOPPING' },
14-
{ id: 4, key: 'OTHER' },
11+
{ id: 1, key: 'PERSONAL', color: 'magenta' },
12+
{ id: 2, key: 'WORK', color: 'gold' },
13+
{ id: 3, key: 'SHOPPING', color: 'green' },
14+
{ id: 4, key: 'OTHER', color: 'blue' },
1515
];

0 commit comments

Comments
 (0)