Skip to content

Commit

Permalink
Merge pull request #203 from cabcookie:agile-todo-list
Browse files Browse the repository at this point in the history
Todoliste nachträglich ändern
  • Loading branch information
cabcookie authored Sep 27, 2024
2 parents 114f5b0 + 4e0cb87 commit 508bff9
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 14 deletions.
21 changes: 21 additions & 0 deletions api/useDailyPlans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type DailyPlanTodo = {
todoId: string;
todo: JSONContent;
done: boolean;
postPoned: boolean;
projectIds: string[];
activityId: string;
};
Expand All @@ -40,6 +41,7 @@ const selectionSet = [
"context",
"status",
"todos.id",
"todos.postPoned",
"todos.todo.id",
"todos.todo.todo",
"todos.todo.status",
Expand Down Expand Up @@ -196,6 +198,24 @@ const useDailyPlans = (status?: DailyPlanStatus) => {
return data.id;
};

const postponeTodo = async (recordId: string, newPostponedState: boolean) => {
const updated: DailyPlan[] | undefined = dailyPlans?.map((p) => ({
...p,
todos: p.todos.map((t) =>
t.recordId !== recordId ? t : { ...t, postPoned: newPostponedState }
),
}));
if (updated) mutate(updated, false);
const { data, errors } = await client.models.DailyPlanTodo.update({
id: recordId,
postPoned: newPostponedState,
});
if (errors)
handleApiErrors(errors, "Updating todo's postPoned state failed");
if (updated) mutate(updated);
return data?.id;
};

const updateDailyPlanStatus = async (
dailyPlanId: string,
status: "DONE" | "OPEN",
Expand Down Expand Up @@ -264,6 +284,7 @@ const useDailyPlans = (status?: DailyPlanStatus) => {
addTodoToDailyPlan,
removeTodoFromDailyPlan,
updateTodoStatus,
postponeTodo,
};
};

Expand Down
50 changes: 39 additions & 11 deletions components/planning/DailyPlanProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
import { ExternalLink } from "lucide-react";
import Link from "next/link";
import { FC } from "react";
import { Button } from "../ui/button";
import PostPonedTodo from "./PostPonedTodo";
import ProjectInformation from "./ProjectInformation";
import TodoForDecision from "./TodoForDecision";

Expand All @@ -29,7 +31,7 @@ const DailyPlanProject: FC<DailyPlanProjectProps> = ({
todos,
className,
}) => {
const { updateTodoStatus } = useDailyPlans("OPEN");
const { updateTodoStatus, postponeTodo } = useDailyPlans("OPEN");

return size(todos) === 0 ? (
<div className="mx-2 md:mx-4 my-8 font-semibold text-sm text-muted-foreground md:text-center">
Expand All @@ -49,16 +51,42 @@ const DailyPlanProject: FC<DailyPlanProjectProps> = ({
identity<DailyPlanTodo[]>,
filter(flow(get("projectIds"), includes(project.id))),
compact,
sortBy((t) => (t?.done ? 1 : 0)),
map(({ todo: { content }, todoId, activityId, done }) => (
<TodoForDecision
key={todoId}
activityId={activityId}
content={content}
todoStatus={done}
finishTodoOnDailyPlan={() => updateTodoStatus(todoId, !done)}
/>
))
sortBy((t) => (t?.postPoned ? 2 : t?.done ? 1 : 0)),
map(
({
todo: { content },
todoId,
activityId,
done,
postPoned,
recordId,
}) =>
!postPoned ? (
<TodoForDecision
key={todoId}
activityId={activityId}
content={content}
todoStatus={done}
finishTodoOnDailyPlan={() => updateTodoStatus(todoId, !done)}
>
{!done && (
<Button
variant="outline"
size="sm"
onClick={() => postponeTodo(recordId, true)}
>
Not today
</Button>
)}
</TodoForDecision>
) : (
<PostPonedTodo
done={done}
content={content}
postponeTodo={() => postponeTodo(recordId, false)}
/>
)
)
)(todos)}
</div>
))(projects)
Expand Down
46 changes: 46 additions & 0 deletions components/planning/PostPonedTodo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { JSONContent } from "@tiptap/core";
import { FC } from "react";
import { getTextFromJsonContent } from "../ui-elements/editors/helpers/text-generation";
import { Button } from "../ui/button";
import { Checkbox } from "../ui/checkbox";

type PostPonedTodoProps = {
done: boolean;
content?: JSONContent[] | undefined;
postponeTodo: () => void;
};

const PostPonedTodo: FC<PostPonedTodoProps> = ({
done,
content,
postponeTodo,
}) => (
<>
<div className="flex flex-row gap-1 items-start mt-4">
<div className="w-6 min-w-6">
<Checkbox
checked={done}
onCheckedChange={() => {}}
className="border-gray-300"
/>
</div>
<div className="flex-1">
<div className="line-through">
{getTextFromJsonContent({ type: "doc", content })}
</div>
{!done && (
<Button
variant="outline"
size="sm"
onClick={() => postponeTodo()}
className="mt-2"
>
Handle today
</Button>
)}
</div>
</div>
</>
);

export default PostPonedTodo;
1 change: 1 addition & 0 deletions components/planning/ReviewProjectForDailyPlanning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const ReviewProjectForDailyPlanning: FC<ReviewProjectForDailyPlanningProps> = ({
todo: t.todo,
todoId: t.todoId,
activityId: t.activityId,
postPoned: false,
})
}
activityId={t.activityId}
Expand Down
3 changes: 2 additions & 1 deletion docs/releases/next.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Todoliste nachträglich ändern (Version :VERSION)

- Aufgaben können nun markiert werden, wenn sie am aktuellen Tag doch nicht erledigt werden sollen. Und man kann diese Entscheidung auch wieder rückgängig machen.

## In Arbeit

- Todos als "doch nicht" markieren, wenn ich sie heute doch nicht erledigen kann.
- Ich möchte Todos auch nachträglich der Tagesliste hinzufügen können.

## Geplant
Expand Down
4 changes: 3 additions & 1 deletion helpers/dailyplans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import { filter, flatMap, flow, get, identity, map, uniq } from "lodash/fp";
const mapDailyPlanTodo: (todo: {
id: string;
todo: TodoData;
}) => DailyPlanTodo = ({ id, todo }) => ({
postPoned?: boolean | null;
}) => DailyPlanTodo = ({ id, todo, postPoned }) => ({
recordId: id,
todoId: getTodoId(todo),
todo: getTodoJson(todo),
done: getTodoStatus(todo),
projectIds: getTodoProjectIds(todo),
activityId: getTodoActivityId(todo),
postPoned: !!postPoned,
});

export const getTodosProjectIds = flow(
Expand Down
2 changes: 1 addition & 1 deletion helpers/useTodosProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const allTodosDone = (todos: DailyPlanTodo[]) => (p: Project) =>
flow(
identity<DailyPlanTodo[]>,
filter((t) => t.projectIds.includes(p.id)),
every((t) => t.done)
every((t) => t.done || t.postPoned)
)(todos)
? 1
: 0;
Expand Down

0 comments on commit 508bff9

Please sign in to comment.