Skip to content

Commit 4c9264c

Browse files
committed
feat: highlight urgent tasks
1 parent 7307d9b commit 4c9264c

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

src/components/TaskList.tsx

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { green, red, blue } from "@material-ui/core/colors"
1+
import { green, red, blue, cyan, amber } from "@material-ui/core/colors"
22
import { Chip, IconButton, makeStyles, Tooltip } from "@material-ui/core";
33
import MUIDataTable from "mui-datatables";
44
import {
@@ -45,6 +45,18 @@ const useStyles = makeStyles(theme => ({
4545
marginRight: theme.spacing(1),
4646
marginTop: theme.spacing(0.5),
4747
marginBottom: theme.spacing(0.5)
48+
},
49+
cyan: {
50+
fontWeight: 500,
51+
color: theme.palette.type === "dark" ? cyan[500] : cyan[600]
52+
},
53+
red: {
54+
fontWeight: 500,
55+
color: red[400]
56+
},
57+
amber: {
58+
fontWeight: 500,
59+
color: theme.palette.type === "dark" ? amber[500] : amber[800]
4860
}
4961
}));
5062

@@ -180,8 +192,11 @@ function TaskList(props: Props) {
180192
// sorted tasks
181193
const tasks = useSelector(
182194
(state: RootState) => (
183-
state.taskJson[props.taskType].sort(
184-
(a, b) => taskUrgency(a) - taskUrgency(b)
195+
state.taskJson[props.taskType].map(task => ({
196+
...task,
197+
due: task.due && DateTime.fromISO(task.due).toFormat("yyyy-MM-dd")
198+
})).sort(
199+
(a, b) => taskUrgency(b) - taskUrgency(a)
185200
)
186201
)
187202
);
@@ -208,6 +223,17 @@ function TaskList(props: Props) {
208223
dispatch(rootActions.doTasks(ids));
209224
};
210225

226+
const colorTask = (task: Task) => {
227+
const urgency = taskUrgency(task);
228+
if (urgency >= 1000)
229+
return classes.red;
230+
if (urgency >= 100)
231+
return classes.amber;
232+
if (urgency >= 1)
233+
return classes.cyan;
234+
return "";
235+
};
236+
211237
return (
212238
<MUIDataTable
213239
title=""
@@ -252,15 +278,21 @@ function TaskList(props: Props) {
252278

253279
return result * (order === "asc" ? 1 : -1);
254280
};
255-
}
281+
},
282+
customBodyRenderLite: index => (
283+
<span className={colorTask(tasks[index])}>{tasks[index].priority}</span>
284+
)
256285
}
257286
},
258287
{
259288
name: "text",
260289
label: "Text",
261290
options: {
262291
filterType: "textField",
263-
sort: false
292+
sort: false,
293+
customBodyRenderLite: index => (
294+
<span className={colorTask(tasks[index])}>{tasks[index].text}</span>
295+
)
264296
}
265297
},
266298
{
@@ -299,7 +331,9 @@ function TaskList(props: Props) {
299331
options: {
300332
sortThirdClickReset: true,
301333
filterType: "textField",
302-
customBodyRender: (row: string | null) => row && DateTime.fromISO(row).toFormat("yyyy-MM-dd")
334+
customBodyRenderLite: index => (
335+
<span className={colorTask(tasks[index])}>{tasks[index].due}</span>
336+
)
303337
}
304338
},
305339
{

0 commit comments

Comments
 (0)