From 3629515bd4919133f94b33c7fc975f8706eace7e Mon Sep 17 00:00:00 2001 From: marshennikovaolga Date: Fri, 22 Nov 2024 12:28:26 +0100 Subject: [PATCH] tasks --- web/app/hooks/actions/use-task-actions.ts | 8 +++++--- .../routes/_layout/_pages/_protected/tasks/-list.tsx | 8 ++++++++ .../routes/_layout/_pages/_protected/tasks/index.tsx | 10 +++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/web/app/hooks/actions/use-task-actions.ts b/web/app/hooks/actions/use-task-actions.ts index 4f6d4b25..8410062b 100644 --- a/web/app/hooks/actions/use-task-actions.ts +++ b/web/app/hooks/actions/use-task-actions.ts @@ -2,7 +2,7 @@ import { useCallback } from "react" import { toast } from "sonner" import { LaAccount } from "@/lib/schema" import { ID } from "jazz-tools" -import { ListOfTasks, Task } from "~/lib/schema/task" +import { Task } from "~/lib/schema/task" export const useTaskActions = () => { const newTask = useCallback((me: LaAccount): Task | null => { @@ -12,7 +12,7 @@ export const useTaskActions = () => { } if (!me.root.tasks) { - me.root.tasks = ListOfTasks.create([], { owner: me }) + me.root.tasks = [] } const newTask = Task.create( @@ -33,7 +33,9 @@ export const useTaskActions = () => { const deleteTask = useCallback((me: LaAccount, taskId: ID): void => { if (!me.root?.tasks) return - const index = me.root.tasks.findIndex((item) => item?.id === taskId) + const index: number = me.root.tasks.findIndex( + (item: Task) => item?.id === taskId, + ) if (index === -1) { toast.error("Task not found") return diff --git a/web/app/routes/_layout/_pages/_protected/tasks/-list.tsx b/web/app/routes/_layout/_pages/_protected/tasks/-list.tsx index 6185a7a8..9d8f3b82 100644 --- a/web/app/routes/_layout/_pages/_protected/tasks/-list.tsx +++ b/web/app/routes/_layout/_pages/_protected/tasks/-list.tsx @@ -12,6 +12,14 @@ export const TaskList: React.FC = ({ onUpdateTask, onDeleteTask, }) => { + if (tasks.length === 0) { + return ( +
+

You have no tasks yet

+
+ ) + } + return (
    {tasks?.map( diff --git a/web/app/routes/_layout/_pages/_protected/tasks/index.tsx b/web/app/routes/_layout/_pages/_protected/tasks/index.tsx index 3770fb7a..80674592 100644 --- a/web/app/routes/_layout/_pages/_protected/tasks/index.tsx +++ b/web/app/routes/_layout/_pages/_protected/tasks/index.tsx @@ -86,7 +86,7 @@ function TaskComponent() { const tasks = me?.root.tasks const { deleteTask } = useTaskActions() - const filteredTasks = tasks?.filter((task) => { + const filteredTasks = tasks?.filter((task: Task) => { if (!task) return false if (filter === "today") { return task.status !== "done" && task.dueDate && isToday(task.dueDate) @@ -98,7 +98,9 @@ function TaskComponent() { const updateTask = (taskId: string, updates: Partial) => { if (me?.root?.tasks) { - const taskIndex = me.root.tasks.findIndex((task) => task?.id === taskId) + const taskIndex = me.root.tasks.findIndex( + (task: Task) => task?.id === taskId, + ) if (taskIndex !== -1) { Object.assign(me.root.tasks[taskIndex]!, updates) } @@ -135,9 +137,7 @@ function TaskComponent() { */} task !== null) || [] - } + tasks={filteredTasks?.filter((task: Task) => task !== null) || []} onUpdateTask={updateTask} onDeleteTask={onDeleteTask} />