-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskListView.js
More file actions
44 lines (37 loc) · 1.2 KB
/
TaskListView.js
File metadata and controls
44 lines (37 loc) · 1.2 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
import styles from "./TaskListView.module.css";
import PropTypes from "prop-types";
import { TaskColors } from "../../ThemeColors";
import TaskListItem from "../TaskListItem/TaskListItem";
const TaskListView = ({ tasks, onDelete, onEdit }) => {
const convertTaskToInt = taskToConvert => {
if (taskToConvert.task_done && taskToConvert.prereqs_done) {
return 0;
} else if (!taskToConvert.task_done && !taskToConvert.prereqs_done) {
return 1;
} else {
return 2;
}
};
tasks.sort(function (task1, task2) {
return convertTaskToInt(task2) - convertTaskToInt(task1);
});
const listItems = tasks.map(function (task, ix) {
const taskColor = task.task_done
? TaskColors.Finished
: task.prereqs_done
? TaskColors.Valid
: TaskColors.Invalid;
return (
<li key={ix} className={styles.ListItem}>
<TaskListItem taskName={task.name} taskStatusColor={taskColor} />
</li>
);
});
return <div className={styles.listView}>{listItems}</div>;
};
TaskListView.propTypes = {
tasks: PropTypes.arrayOf(PropTypes.object).isRequired,
onDelete: PropTypes.func.isRequired,
onEdit: PropTypes.func.isRequired,
};
export default TaskListView;