From 3daf0336700107c84afb3cb02a3cf903b30b2967 Mon Sep 17 00:00:00 2001 From: MangoCubes <10383115+MangoCubes@users.noreply.github.com> Date: Sun, 16 Jul 2023 18:43:17 +0900 Subject: [PATCH] Tasks edit: Added parent task selector --- src/Tasks/Main.tsx | 4 ++- src/Tasks/TaskEdit.tsx | 24 +++++++++++++ src/Tasks/TaskSelector.tsx | 58 ++++++++++++++++++++++++++++++ src/Tasks/TaskSelectorListItem.tsx | 32 +++++++++++++++++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 src/Tasks/TaskSelector.tsx create mode 100644 src/Tasks/TaskSelectorListItem.tsx diff --git a/src/Tasks/Main.tsx b/src/Tasks/Main.tsx index e8d973eb..3823ffa3 100644 --- a/src/Tasks/Main.tsx +++ b/src/Tasks/Main.tsx @@ -72,7 +72,7 @@ export default function TasksMain() { history.goBack(); } - const flatEntries = []; + const flatEntries: TaskType[] = []; for (const col of entries.values()) { for (const item of col.values()) { flatEntries.push(item); @@ -113,6 +113,7 @@ export default function TasksMain() { exact > { description: string; tags: string[]; collectionUid: string; + showSelectorDialog: boolean; + parentEntry: string; error?: string; showDeleteDialog: boolean; @@ -76,6 +80,7 @@ export default class TaskEdit extends React.PureComponent { constructor(props: PropsType) { super(props); this.state = { + parentEntry: "", uid: "", title: "", status: TaskStatusType.NeedsAction, @@ -85,6 +90,7 @@ export default class TaskEdit extends React.PureComponent { description: "", tags: [], timezone: null, + showSelectorDialog: false, collectionUid: "", showDeleteDialog: false, @@ -322,6 +328,17 @@ export default class TaskEdit extends React.PureComponent { + + e.uid === this.state.parentEntry)?.title ?? "None"} + /> + Status @@ -492,6 +509,13 @@ export default class TaskEdit extends React.PureComponent { > Are you sure you would like to delete this task? + console.log(entry)} + onCancel={() => this.setState({ openSelector: false })} + /> ); } diff --git a/src/Tasks/TaskSelector.tsx b/src/Tasks/TaskSelector.tsx new file mode 100644 index 00000000..70ee09d3 --- /dev/null +++ b/src/Tasks/TaskSelector.tsx @@ -0,0 +1,58 @@ +import { useState } from "react"; +import { TaskType } from "../pim-types"; +import { Button, Dialog, DialogActions, DialogContent, DialogTitle, List } from "@material-ui/core"; +import React from "react"; +import TaskSelectorListItem from "./TaskSelectorListItem"; + +interface PropsType { + entries: TaskType[]; + orig: string; + open: boolean; + onConfirm: (entry: string | null) => void; + onCancel: () => void; +} + +export default function TaskSelector(props: PropsType) { + const [itemId, setItemId] = useState(props.orig); + + const select = () => { + if (itemId) { + props.onConfirm(itemId); + } + }; + + const itemList = props.entries.filter((e) => !e.relatedTo) + .map((e) => + + ); + + return ( + + + Select parent task + + + + {itemList} + + + + + + + + + ); +} \ No newline at end of file diff --git a/src/Tasks/TaskSelectorListItem.tsx b/src/Tasks/TaskSelectorListItem.tsx new file mode 100644 index 00000000..d755732b --- /dev/null +++ b/src/Tasks/TaskSelectorListItem.tsx @@ -0,0 +1,32 @@ +import { TaskType } from "../pim-types"; +import { ListItem } from "../widgets/List"; +import React from "react"; + +interface PropsType { + entries: TaskType[]; + onClick: (uid: string) => void; + selected: string | null; + thisEntry: TaskType; +} + +export default function TaskSelectorListItem(props: PropsType) { + const tasks = props.entries.filter((e) => e.relatedTo === props.thisEntry.uid); + + return ( + props.onClick(props.thisEntry.uid)} + nestedItems={tasks.map((e) => + + )} + /> + ); +} \ No newline at end of file