Skip to content

Commit 7e8684f

Browse files
authored
Merge pull request #2 from MangoCubes/subtask
Tasks edit: Added toggle switch for hidden and completed tasks
2 parents ee51609 + 98ddff8 commit 7e8684f

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/Tasks/TaskSelector.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TaskType } from "../pim-types";
2-
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, List } from "@material-ui/core";
2+
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, FormControlLabel, FormGroup, List, Switch } from "@material-ui/core";
33
import React from "react";
44
import TaskSelectorListItem from "./TaskSelectorListItem";
55

@@ -13,9 +13,15 @@ interface PropsType {
1313

1414
export default function TaskSelector(props: PropsType) {
1515

16-
const itemList = props.entries.filter((e) => !e.relatedTo)
16+
const [showHidden, setShowHidden] = React.useState(false);
17+
const [showCompleted, setShowCompleted] = React.useState(false);
18+
19+
const itemList = props.entries
20+
.filter((e) => !e.relatedTo && (showHidden || !e.hidden) && (showCompleted || !e.finished))
1721
.map((e) =>
1822
<TaskSelectorListItem
23+
showHidden={showHidden}
24+
showCompleted={showCompleted}
1925
key={e.uid}
2026
entries={props.entries}
2127
thisEntry={e}
@@ -29,6 +35,26 @@ export default function TaskSelector(props: PropsType) {
2935
Select parent task
3036
</DialogTitle>
3137
<DialogContent>
38+
<FormGroup>
39+
<FormControlLabel
40+
control={
41+
<Switch
42+
checked={showCompleted}
43+
onChange={(e) => setShowCompleted(e.target.checked)}
44+
/>
45+
}
46+
label="Show completed"
47+
/>
48+
<FormControlLabel
49+
control={
50+
<Switch
51+
checked={showHidden}
52+
onChange={(e) => setShowHidden(e.target.checked)}
53+
/>
54+
}
55+
label="Show hidden"
56+
/>
57+
</FormGroup>
3258
<List>
3359
{itemList}
3460
</List>

src/Tasks/TaskSelectorListItem.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import React from "react";
44

55
interface PropsType {
66
entries: TaskType[];
7+
showHidden: boolean;
8+
showCompleted: boolean;
79
onClick: (uid: string) => void;
810
thisEntry: TaskType;
911
}
1012

1113
export default function TaskSelectorListItem(props: PropsType) {
12-
const tasks = props.entries.filter((e) => e.relatedTo === props.thisEntry.uid);
14+
const tasks = props.entries
15+
.filter((e) => e.relatedTo === props.thisEntry.uid && (props.showHidden || !e.hidden) && (props.showCompleted || !e.finished));
1316

1417
return (
1518
<ListItem
@@ -18,6 +21,8 @@ export default function TaskSelectorListItem(props: PropsType) {
1821
onClick={() => props.onClick(props.thisEntry.uid)}
1922
nestedItems={tasks.map((e) =>
2023
<TaskSelectorListItem
24+
showHidden={props.showHidden}
25+
showCompleted={props.showCompleted}
2126
key={e.uid}
2227
entries={props.entries}
2328
onClick={props.onClick}

0 commit comments

Comments
 (0)