Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Add search feature to tasks page

Khuram Niazea2a06bea50e
diff --git a/__tests__/TasksContainer.spec.tsx b/__tests__/TasksContainer.spec.tsx
index e206bf2..7860316 100644
--- a/__tests__/TasksContainer.spec.tsx
+++ b/__tests__/TasksContainer.spec.tsx
@@ -178,7 +178,7 @@ describe("TasksContainer Component", () => {
expect(getTasksList).toHaveBeenCalledWith(1, 25, undefined, [
"in-progress",
"needs-attention",
- ]);
+ ], undefined);
});
await waitFor(() => {
@@ -478,7 +478,7 @@ describe("TasksContainer Component", () => {
expect(getTasksList).toHaveBeenCalledWith(1, 25, "type-1", [
"in-progress",
"needs-attention",
- ]);
+ ], undefined);
});
});
@@ -496,7 +496,7 @@ describe("TasksContainer Component", () => {
await waitFor(() => {
expect(getTasksList).toHaveBeenCalledWith(1, 25, "type-1", [
"needs-attention",
- ]);
+ ], undefined);
});
});
@@ -560,7 +560,7 @@ describe("TasksContainer Component", () => {
expect(getTasksList).toHaveBeenCalledWith(2, 25, undefined, [
"in-progress",
"needs-attention",
- ]);
+ ], undefined);
});
});
@@ -639,4 +639,439 @@ describe("TasksContainer Component", () => {
expect(mockOnFilterChange).not.toHaveBeenCalled();
});
});
+
+ describe("Search Feature", () => {
+ beforeEach(() => {
+ jest.useFakeTimers();
+ });
+
+ afterEach(() => {
+ jest.useRealTimers();
+ });
+
+ it("should render search input", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ const searchInput = screen.getByPlaceholderText("Search tasks...");
+ expect(searchInput).toBeInTheDocument();
+ });
+
+ it("should call getTasksList with search term after debounce", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ undefined,
+ ["in-progress", "needs-attention"],
+ undefined
+ );
+ });
+
+ jest.clearAllMocks();
+
+ const searchInput = screen.getByPlaceholderText("Search tasks...");
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).type(
+ searchInput,
+ "Task 1"
+ );
+
+ // Before debounce, getTasksList should not be called with search term
+ expect(getTasksList).not.toHaveBeenCalled();
+
+ // Fast-forward past the 300ms debounce
+ jest.advanceTimersByTime(300);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ undefined,
+ ["in-progress", "needs-attention"],
+ "Task 1"
+ );
+ });
+ });
+
+ it("should filter tasks based on search term", async () => {
+ const filteredTasks = [mockTasks[0]];
+
+ (getTasksList as jest.Mock)
+ .mockResolvedValueOnce({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ })
+ .mockResolvedValueOnce({
+ success: true,
+ data: filteredTasks,
+ total: 1,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ expect(screen.getByText("Task 2")).toBeInTheDocument();
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search tasks...");
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).type(
+ searchInput,
+ "Task 1"
+ );
+
+ jest.advanceTimersByTime(300);
+
+ await waitFor(() => {
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ expect(screen.queryByText("Task 2")).not.toBeInTheDocument();
+ });
+ });
+
+ it("should show no tasks found when search returns empty results", async () => {
+ (getTasksList as jest.Mock)
+ .mockResolvedValueOnce({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ })
+ .mockResolvedValueOnce({
+ success: true,
+ data: [],
+ total: 0,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search tasks...");
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).type(
+ searchInput,
+ "nonexistent"
+ );
+
+ jest.advanceTimersByTime(300);
+
+ await waitFor(() => {
+ expect(screen.getByText(/No tasks found/i)).toBeInTheDocument();
+ });
+ });
+
+ it("should combine search with status filter", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ });
+
+ // Toggle status filter first
+ const filterButton = screen.getByRole("button", { name: /status/i });
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).click(
+ filterButton
+ );
+
+ const inProgressCheckbox = screen.getByRole("menuitemcheckbox", {
+ name: "In Progress",
+ });
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).click(
+ inProgressCheckbox
+ );
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ undefined,
+ ["needs-attention"],
+ undefined
+ );
+ });
+
+ jest.clearAllMocks();
+
+ // Now search
+ const searchInput = screen.getByPlaceholderText("Search tasks...");
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).type(
+ searchInput,
+ "Task"
+ );
+
+ jest.advanceTimersByTime(300);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ undefined,
+ ["needs-attention"],
+ "Task"
+ );
+ });
+ });
+
+ it("should combine search with activity type filter", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ render(
+ <TasksContainer activityTypes={mockActivityTypes} filterKey="type-1" />
+ );
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ "type-1",
+ ["in-progress", "needs-attention"],
+ undefined
+ );
+ });
+
+ jest.clearAllMocks();
+
+ const searchInput = screen.getByPlaceholderText("Search tasks...");
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).type(
+ searchInput,
+ "Development"
+ );
+
+ jest.advanceTimersByTime(300);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ "type-1",
+ ["in-progress", "needs-attention"],
+ "Development"
+ );
+ });
+ });
+
+ it("should pass search term when loading more tasks", async () => {
+ (getTasksList as jest.Mock)
+ .mockResolvedValueOnce({
+ success: true,
+ data: mockTasks,
+ total: 20,
+ })
+ .mockResolvedValueOnce({
+ success: true,
+ data: mockTasks,
+ total: 20,
+ })
+ .mockResolvedValueOnce({
+ success: true,
+ data: [{ ...mockTasks[0], id: "task-3", title: "Task 3" }],
+ total: 20,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ });
+
+ // Type search term
+ const searchInput = screen.getByPlaceholderText("Search tasks...");
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).type(
+ searchInput,
+ "Task"
+ );
+
+ jest.advanceTimersByTime(300);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ undefined,
+ ["in-progress", "needs-attention"],
+ "Task"
+ );
+ });
+
+ jest.clearAllMocks();
+
+ // Click Load More
+ const loadMoreButton = screen.getByText("Load More");
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).click(
+ loadMoreButton
+ );
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 2,
+ 25,
+ undefined,
+ ["in-progress", "needs-attention"],
+ "Task"
+ );
+ });
+ });
+
+ it("should reset to page 1 when search term changes", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ });
+
+ jest.clearAllMocks();
+
+ const searchInput = screen.getByPlaceholderText("Search tasks...");
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).type(
+ searchInput,
+ "first search"
+ );
+
+ jest.advanceTimersByTime(300);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ undefined,
+ ["in-progress", "needs-attention"],
+ "first search"
+ );
+ });
+
+ jest.clearAllMocks();
+
+ // Change search term
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).clear(
+ searchInput
+ );
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).type(
+ searchInput,
+ "second search"
+ );
+
+ jest.advanceTimersByTime(300);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ undefined,
+ ["in-progress", "needs-attention"],
+ "second search"
+ );
+ });
+ });
+
+ it("should debounce multiple rapid keystrokes", async () => {
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ const typingUser = userEvent.setup({
+ advanceTimers: jest.advanceTimersByTime,
+ });
+
+ render(<TasksContainer activityTypes={mockActivityTypes} />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ });
+
+ jest.clearAllMocks();
+
+ const searchInput = screen.getByPlaceholderText("Search tasks...");
+
+ // Type "Task" rapidly - single userEvent instance handles debouncing correctly
+ await typingUser.type(searchInput, "Task");
+
+ // Only after full debounce should API be called
+ jest.advanceTimersByTime(300);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenLastCalledWith(
+ 1,
+ 25,
+ undefined,
+ ["in-progress", "needs-attention"],
+ "Task"
+ );
+ });
+ });
+
+ it("should reload tasks with search term after task is saved", async () => {
+ const mockOnTasksChanged = jest.fn();
+
+ (getTasksList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockTasks,
+ total: 2,
+ });
+
+ render(
+ <TasksContainer
+ activityTypes={mockActivityTypes}
+ onTasksChanged={mockOnTasksChanged}
+ />
+ );
+
+ await waitFor(() => {
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ });
+
+ // Type search term
+ const searchInput = screen.getByPlaceholderText("Search tasks...");
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).type(
+ searchInput,
+ "Task"
+ );
+
+ jest.advanceTimersByTime(300);
+
+ await waitFor(() => {
+ expect(getTasksList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ undefined,
+ ["in-progress", "needs-attention"],
+ "Task"
+ );
+ });
+
+ // Verify that search term is maintained in state
+ expect(searchInput).toHaveValue("Task");
+ });
+ });
});
diff --git a/__tests__/TasksPageClient.spec.tsx b/__tests__/TasksPageClient.spec.tsx
index c40ba74..7681df7 100644
--- a/__tests__/TasksPageClient.spec.tsx
+++ b/__tests__/TasksPageClient.spec.tsx
@@ -379,7 +379,8 @@ describe("TasksPageClient Component", () => {
1,
25,
"type-1",
- expect.any(Array)
+ expect.any(Array),
+ undefined
);
});
});
@@ -410,7 +411,8 @@ describe("TasksPageClient Component", () => {
1,
25,
"type-1",
- expect.any(Array)
+ expect.any(Array),
+ undefined
);
});
@@ -426,7 +428,8 @@ describe("TasksPageClient Component", () => {
1,
25,
undefined,
- expect.any(Array)
+ expect.any(Array),
+ undefined
);
});
});
diff --git a/src/actions/task.actions.ts b/src/actions/task.actions.ts
index 8a2b728..370e7d1 100644
--- a/src/actions/task.actions.ts
+++ b/src/actions/task.actions.ts
@@ -11,7 +11,8 @@ export const getTasksList = async (
page: number = 1,
limit: number = APP_CONSTANTS.RECORDS_PER_PAGE,
filter?: string,
- statusFilter?: TaskStatus[]
+ statusFilter?: TaskStatus[],
+ search?: string
): Promise<any | undefined> => {
try {
const user = await getCurrentUser();
@@ -34,6 +35,14 @@ export const getTasksList = async (
whereClause.status = { in: statusFilter };
}
+ if (search) {
+ whereClause.OR = [
+ { title: { contains: search } },
+ { description: { contains: search } },
+ { activityType: { label: { contains: search } } },
+ ];
+ }
+
const [data, total] = await Promise.all([
prisma.task.findMany({
where: whereClause,
diff --git a/src/components/tasks/TasksContainer.tsx b/src/components/tasks/TasksContainer.tsx
index 5e0f0de..4c39287 100644
--- a/src/components/tasks/TasksContainer.tsx
+++ b/src/components/tasks/TasksContainer.tsx
@@ -1,5 +1,5 @@
"use client";
-import { useCallback, useEffect, useState } from "react";
+import { useCallback, useEffect, useRef, useState } from "react";
import {
Card,
CardContent,
@@ -8,7 +8,8 @@ import {
CardTitle,
} from "../ui/card";
import { Button } from "../ui/button";
-import { ListFilter, PlusCircle, Filter } from "lucide-react";
+import { ListFilter, PlusCircle, Filter, Search } from "lucide-react";
+import { Input } from "../ui/input";
import {
deleteTaskById,
getTaskById,
@@ -76,17 +77,20 @@ function TasksContainer({
const [recordsPerPage, setRecordsPerPage] = useState<number>(
APP_CONSTANTS.RECORDS_PER_PAGE,
);
+ const [searchTerm, setSearchTerm] = useState("");
+ const hasSearched = useRef(false);
const tasksPerPage = recordsPerPage;
const loadTasks = useCallback(
- async (pageNum: number, filter?: string, statuses?: TaskStatus[]) => {
+ async (pageNum: number, filter?: string, statuses?: TaskStatus[], search?: string) => {
setLoading(true);
const { success, data, total, message } = await getTasksList(
pageNum,
tasksPerPage,
filter,
statuses,
+ search,
);
if (success && data) {
setTasks((prev) => (pageNum === 1 ? data : [...prev, ...data]));
@@ -106,9 +110,9 @@ function TasksContainer({
);
const reloadTasks = useCallback(async () => {
- await loadTasks(1, filterKey, statusFilter);
+ await loadTasks(1, filterKey, statusFilter, searchTerm || undefined);
onTasksChanged?.();
- }, [loadTasks, filterKey, statusFilter, onTasksChanged]);
+ }, [loadTasks, filterKey, statusFilter, searchTerm, onTasksChanged]);
const onDeleteTask = async (taskId: string) => {
const { success, message } = await deleteTaskById(taskId);
@@ -191,9 +195,24 @@ function TasksContainer({
};
useEffect(() => {
- (async () => await loadTasks(1, filterKey, statusFilter))();
+ (async () => await loadTasks(1, filterKey, statusFilter, searchTerm || undefined))();
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [loadTasks, filterKey, statusFilter, recordsPerPage]);
+ // Debounced search effect
+ useEffect(() => {
+ if (searchTerm !== "") {
+ hasSearched.current = true;
+ }
+ if (searchTerm === "" && !hasSearched.current) return;
+
+ const timer = setTimeout(() => {
+ loadTasks(1, filterKey, statusFilter, searchTerm || undefined);
+ }, 300);
+ return () => clearTimeout(timer);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [searchTerm]);
+
const onGroupByChange = (value: string) => {
setGroupBy(
value as
@@ -220,6 +239,16 @@ function TasksContainer({
<CardTitle>My Tasks</CardTitle>
<div className="flex items-center">
<div className="ml-auto flex items-center gap-2">
+ <div className="relative">
+ <Search className="absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground" />
+ <Input
+ type="search"
+ placeholder="Search tasks..."
+ className="pl-8 h-8 w-[150px] lg:w-[200px]"
+ value={searchTerm}
+ onChange={(e) => setSearchTerm(e.target.value)}
+ />
+ </div>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="sm" className="h-8 gap-1">
@@ -314,7 +343,7 @@ function TasksContainer({
<Button
size="sm"
variant="outline"
- onClick={() => loadTasks(page + 1, filterKey, statusFilter)}
+ onClick={() => loadTasks(page + 1, filterKey, statusFilter, searchTerm || undefined)}
disabled={loading}
className="btn btn-primary"
>