flowstate/app/(app)/trash/page.tsx
Chneemann 07d80a2674
All checks were successful
Deploy Flowstate to VPS / deploy (push) Successful in 52s
feat(search): add debounced search bar with server-side TaskService filtering
2026-08-17 04:48:06 +02:00

53 lines
1.6 KiB
TypeScript

/**
* @file trash/page.tsx
* @description Server component rendering the trash management view with database search filtering.
*/
import { auth } from "@/auth";
import { redirect } from "next/navigation";
import TrashList from "../trash/TrashList";
import TrashHeader from "../trash/components/TrashHeader";
import { TaskService } from "@/services/task.service";
import { Task } from "@/types/task";
/**
* Renders the trash page view, fetching soft-deleted tasks for the authenticated user
* with optional search query filtering applied at the database level.
*
* @async
* @param {Object} props - The page component props.
* @param {Promise<{ search?: string }>} props.searchParams - Promise resolving to the route's search query parameters.
* @returns {Promise<JSX.Element>} The rendered trash page component.
*/
export default async function TrashPage({
searchParams,
}: {
searchParams: Promise<{ search?: string }>;
}) {
const session = await auth();
if (!session?.user?.id) redirect("/login");
const currentUserId = session.user.id;
const { search } = await searchParams;
const searchQuery = search?.trim() || "";
// The search is passed directly to the SQL query
const rawTrashedTasks = await TaskService.findTrashTasksForUser(
currentUserId,
searchQuery,
);
const tasks: Task[] = rawTrashedTasks.map(({ task, user }) => ({
...task,
creator: user,
assignees: [],
isCreator: task.userId === currentUserId,
}));
return (
<div className="space-y-8 max-w-7xl mx-auto pb-12">
<TrashHeader />
<TrashList tasks={tasks} />
</div>
);
}