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.

feat: Switch pagination to infinite scroll

Khuram Niazb05580a10f5f
diff --git a/__tests__/ActivitiesContainer.spec.tsx b/__tests__/ActivitiesContainer.spec.tsx
index d8f70eb..72ca611 100644
--- a/__tests__/ActivitiesContainer.spec.tsx
+++ b/__tests__/ActivitiesContainer.spec.tsx
@@ -56,6 +56,16 @@ global.ResizeObserver = class ResizeObserver {
disconnect() {}
};
+let intersectionCallback: IntersectionObserverCallback;
+global.IntersectionObserver = class IntersectionObserver {
+ constructor(callback: IntersectionObserverCallback) {
+ intersectionCallback = callback;
+ }
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+} as any;
+
document.createRange = () => {
const range = new Range();
@@ -380,8 +390,8 @@ describe("ActivitiesContainer Search Functionality", () => {
});
});
- describe("Load More with Search", () => {
- it("should preserve search term when loading more", async () => {
+ describe("Infinite Scroll with Search", () => {
+ it("should preserve search term when loading more via scroll", async () => {
(getActivitiesList as any).mockResolvedValue({
success: true,
data: mockActivities,
@@ -391,7 +401,7 @@ describe("ActivitiesContainer Search Functionality", () => {
renderComponent();
await waitFor(() => {
- expect(screen.getByText("Load More")).toBeInTheDocument();
+ expect(screen.getByText("TypeScript Learning")).toBeInTheDocument();
});
// Type search
@@ -408,13 +418,15 @@ describe("ActivitiesContainer Search Functionality", () => {
expect(getActivitiesList).toHaveBeenCalledWith(1, 25, "Learning");
});
- // Click load more
- const loadMoreButton = screen.getByText("Load More");
+ // Simulate sentinel becoming visible
await act(async () => {
- await user.click(loadMoreButton);
+ intersectionCallback(
+ [{ isIntersecting: true }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
+ );
});
- // Should include search term in load more call
+ // Should include search term in infinite scroll call
await waitFor(() => {
expect(getActivitiesList).toHaveBeenCalledWith(2, 25, "Learning");
});
diff --git a/__tests__/JobsContainer.spec.tsx b/__tests__/JobsContainer.spec.tsx
index 461f038..5cf114d 100644
--- a/__tests__/JobsContainer.spec.tsx
+++ b/__tests__/JobsContainer.spec.tsx
@@ -58,6 +58,16 @@ global.ResizeObserver = class ResizeObserver {
disconnect() {}
};
+let intersectionCallback: IntersectionObserverCallback;
+global.IntersectionObserver = class IntersectionObserver {
+ constructor(callback: IntersectionObserverCallback) {
+ intersectionCallback = callback;
+ }
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+} as any;
+
document.createRange = () => {
const range = new Range();
@@ -613,8 +623,8 @@ describe("JobsContainer Search Functionality", () => {
});
});
- describe("Load More with Search", () => {
- it("should preserve search term when loading more", async () => {
+ describe("Infinite Scroll with Search", () => {
+ it("should preserve search term when loading more via scroll", async () => {
(getJobsList as any).mockResolvedValue({
success: true,
data: mockJobs,
@@ -624,7 +634,7 @@ describe("JobsContainer Search Functionality", () => {
renderComponent();
await waitFor(() => {
- expect(screen.getByText("Load More")).toBeInTheDocument();
+ expect(screen.getByText("Amazon")).toBeInTheDocument();
});
// Type search
@@ -641,13 +651,15 @@ describe("JobsContainer Search Functionality", () => {
expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Developer", undefined, undefined, undefined, undefined, undefined);
});
- // Click load more
- const loadMoreButton = screen.getByText("Load More");
+ // Simulate sentinel becoming visible
await act(async () => {
- await user.click(loadMoreButton);
+ intersectionCallback(
+ [{ isIntersecting: true }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
+ );
});
- // Should include search term in load more call
+ // Should include search term in infinite scroll call
await waitFor(() => {
expect(getJobsList).toHaveBeenCalledWith(2, 25, undefined, "Developer", undefined, undefined, undefined, undefined, undefined);
});
diff --git a/__tests__/TasksContainer.spec.tsx b/__tests__/TasksContainer.spec.tsx
index dc53862..1e54a42 100644
--- a/__tests__/TasksContainer.spec.tsx
+++ b/__tests__/TasksContainer.spec.tsx
@@ -66,6 +66,16 @@ global.ResizeObserver = class ResizeObserver {
disconnect() {}
};
+let intersectionCallback: IntersectionObserverCallback;
+global.IntersectionObserver = class IntersectionObserver {
+ constructor(callback: IntersectionObserverCallback) {
+ intersectionCallback = callback;
+ }
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+} as any;
+
document.createRange = () => {
const range = new Range();
@@ -525,7 +535,7 @@ describe("TasksContainer Component", () => {
});
describe("Pagination", () => {
- it("should show load more button when there are more tasks", async () => {
+ it("should show sentinel when there are more tasks", async () => {
(getTasksList as any).mockResolvedValue({
success: true,
data: mockTasks,
@@ -535,11 +545,12 @@ describe("TasksContainer Component", () => {
render(<TasksContainer activityTypes={mockActivityTypes} />);
await waitFor(() => {
- expect(screen.getByText("Load More")).toBeInTheDocument();
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
+ expect(screen.queryByText("Load More")).not.toBeInTheDocument();
});
});
- it("should load more tasks when load more button is clicked", async () => {
+ it("should load more tasks when sentinel becomes visible", async () => {
(getTasksList as any)
.mockResolvedValueOnce({
success: true,
@@ -561,11 +572,14 @@ describe("TasksContainer Component", () => {
render(<TasksContainer activityTypes={mockActivityTypes} />);
await waitFor(() => {
- expect(screen.getByText("Load More")).toBeInTheDocument();
+ expect(screen.getByText("Task 1")).toBeInTheDocument();
});
- const loadMoreButton = screen.getByText("Load More");
- await user.click(loadMoreButton);
+ // Simulate sentinel becoming visible
+ intersectionCallback(
+ [{ isIntersecting: true }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
+ );
await waitFor(() => {
expect(getTasksList).toHaveBeenCalledWith(2, 25, undefined, [
@@ -575,7 +589,7 @@ describe("TasksContainer Component", () => {
});
});
- it("should not show load more button when all tasks are loaded", async () => {
+ it("should not show sentinel when all tasks are loaded", async () => {
(getTasksList as any).mockResolvedValue({
success: true,
data: mockTasks,
@@ -885,7 +899,7 @@ describe("TasksContainer Component", () => {
});
});
- it("should pass search term when loading more tasks", async () => {
+ it("should pass search term when loading more tasks via scroll", async () => {
(getTasksList as any)
.mockResolvedValueOnce({
success: true,
@@ -930,10 +944,10 @@ describe("TasksContainer Component", () => {
vi.clearAllMocks();
- // Click Load More
- const loadMoreButton = screen.getByText("Load More");
- await userEvent.setup({ advanceTimers: vi.advanceTimersByTime }).click(
- loadMoreButton
+ // Simulate sentinel becoming visible
+ intersectionCallback(
+ [{ isIntersecting: true }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
);
await waitFor(() => {
diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx
index 805772f..b1884ee 100644
--- a/src/app/dashboard/page.tsx
+++ b/src/app/dashboard/page.tsx
@@ -60,12 +60,12 @@ export default async function Dashboard() {
<NumberCardToggle
data={[
{
- label: "Last 7 days",
+ label: "7d",
num: jobsAppliedLast7Days,
trend: trendFor7Days,
},
{
- label: "Last 30 days",
+ label: "30d",
num: jobsAppliedLast30Days,
trend: trendFor30Days,
},
@@ -73,8 +73,8 @@ export default async function Dashboard() {
/>
<TopActivitiesCard
data={[
- { label: "Last 7 days", activities: topActivities7Days },
- { label: "Last 30 days", activities: topActivities30Days },
+ { label: "7d", activities: topActivities7Days },
+ { label: "30d", activities: topActivities30Days },
]}
/>
</div>
diff --git a/src/components/activities/ActivitiesContainer.tsx b/src/components/activities/ActivitiesContainer.tsx
index dfdb4e5..897a7d5 100644
--- a/src/components/activities/ActivitiesContainer.tsx
+++ b/src/components/activities/ActivitiesContainer.tsx
@@ -3,7 +3,7 @@ import ActivitiesTable from "./ActivitiesTable";
import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
-import { PlusCircle, Search } from "lucide-react";
+import { Loader, PlusCircle, Search } from "lucide-react";
import { useCallback, useEffect, useRef, useState } from "react";
import {
Dialog,
@@ -27,12 +27,14 @@ function ActivitiesContainer() {
const [activitiesList, setActivitiesList] = useState<Activity[]>([]);
const [page, setPage] = useState<number>(1);
const [totalActivities, setTotalActivities] = useState<number>(0);
- const [loading, setLoading] = useState(false);
+ const [initialLoading, setInitialLoading] = useState(false);
+ const [loadingMore, setLoadingMore] = useState(false);
const [recordsPerPage, setRecordsPerPage] = useState<number>(
APP_CONSTANTS.RECORDS_PER_PAGE,
);
const [searchTerm, setSearchTerm] = useState("");
const hasSearched = useRef(false);
+ const sentinelRef = useRef<HTMLDivElement>(null);
const { currentActivity, startActivity } = useActivity();
const prevActivityRef = useRef<Activity | undefined>(undefined);
@@ -41,7 +43,8 @@ function ActivitiesContainer() {
const loadActivities = useCallback(
async (page: number, limit: number, search?: string) => {
- setLoading(true);
+ if (page === 1) setInitialLoading(true);
+ else setLoadingMore(true);
try {
const { data, success, message, total } = await getActivitiesList(
page,
@@ -66,7 +69,8 @@ function ActivitiesContainer() {
description: "Failed to load activities. Please try again.",
});
} finally {
- setLoading(false);
+ setInitialLoading(false);
+ setLoadingMore(false);
}
},
[],
@@ -109,6 +113,38 @@ function ActivitiesContainer() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchTerm]);
+ // Infinite scroll: auto-load next page when sentinel is visible
+ useEffect(() => {
+ const sentinel = sentinelRef.current;
+ if (!sentinel) return;
+
+ const observer = new IntersectionObserver(
+ (entries) => {
+ if (
+ entries[0].isIntersecting &&
+ !initialLoading &&
+ !loadingMore &&
+ activitiesList.length < totalActivities
+ ) {
+ loadActivities(page + 1, recordsPerPage, searchTerm || undefined);
+ }
+ },
+ { threshold: 0.1 },
+ );
+
+ observer.observe(sentinel);
+ return () => observer.disconnect();
+ }, [
+ activitiesList.length,
+ totalActivities,
+ page,
+ recordsPerPage,
+ searchTerm,
+ initialLoading,
+ loadingMore,
+ loadActivities,
+ ]);
+
return (
<Card>
<CardHeader className="flex-row justify-between items-center">
@@ -153,7 +189,7 @@ function ActivitiesContainer() {
</div>
</CardHeader>
<CardContent>
- {loading && <Loading />}
+ {initialLoading && <Loading />}
{activitiesList.length > 0 && (
<>
<ActivitiesTable
@@ -178,22 +214,10 @@ function ActivitiesContainer() {
</>
)}
{activitiesList.length < totalActivities && (
- <div className="flex justify-center p-4">
- <Button
- size="sm"
- variant="outline"
- onClick={() =>
- loadActivities(
- page + 1,
- recordsPerPage,
- searchTerm || undefined,
- )
- }
- disabled={loading}
- className="btn btn-primary"
- >
- {loading ? "Loading..." : "Load More"}
- </Button>
+ <div ref={sentinelRef} className="flex justify-center p-4">
+ {loadingMore && (
+ <Loader className="h-5 w-5 animate-spin text-blue-500" />
+ )}
</div>
)}
</CardContent>
diff --git a/src/components/myjobs/JobsContainer.tsx b/src/components/myjobs/JobsContainer.tsx
index 2fb68a8..c3f0971 100644
--- a/src/components/myjobs/JobsContainer.tsx
+++ b/src/components/myjobs/JobsContainer.tsx
@@ -9,7 +9,7 @@ import {
} from "../ui/card";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
-import { File, ListFilter, Search, X } from "lucide-react";
+import { File, ListFilter, Loader, Search, X } from "lucide-react";
import {
deleteJobById,
getJobDetails,
@@ -96,13 +96,15 @@ function JobsContainer({
const [filterKey, setFilterKey] = useState<string>();
const [searchTerm, setSearchTerm] = useState("");
const [editJob, setEditJob] = useState(null);
- const [loading, setLoading] = useState(false);
+ const [initialLoading, setInitialLoading] = useState(false);
+ const [loadingMore, setLoadingMore] = useState(false);
const [recordsPerPage, setRecordsPerPage] = useState<number>(
APP_CONSTANTS.RECORDS_PER_PAGE,
);
const [noteDialogOpen, setNoteDialogOpen] = useState(false);
const [noteJobId, setNoteJobId] = useState("");
const hasSearched = useRef(false);
+ const sentinelRef = useRef<HTMLDivElement>(null);
const companyLabel = companyFilter
? companies.find((c) => c.value === companyFilter)?.label
@@ -161,7 +163,8 @@ function JobsContainer({
const loadJobs = useCallback(
async (page: number, filter?: string, search?: string) => {
- setLoading(true);
+ if (page === 1) setInitialLoading(true);
+ else setLoadingMore(true);
const { success, data, total, message } = await getJobsList(
page,
jobsPerPage,
@@ -177,16 +180,15 @@ function JobsContainer({
setJobs((prev) => (page === 1 ? data : [...prev, ...data]));
setTotalJobs(total);
setPage(page);
- setLoading(false);
} else {
toast({
variant: "destructive",
title: "Error!",
description: message,
});
- setLoading(false);
- return;
}
+ setInitialLoading(false);
+ setLoadingMore(false);
},
[jobsPerPage, companyFilter, appliedFilter, titleFilter, locationFilter, sourceFilter],
);
@@ -273,6 +275,38 @@ function JobsContainer({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchTerm]);
+ // Infinite scroll: auto-load next page when sentinel is visible
+ useEffect(() => {
+ const sentinel = sentinelRef.current;
+ if (!sentinel) return;
+
+ const observer = new IntersectionObserver(
+ (entries) => {
+ if (
+ entries[0].isIntersecting &&
+ !initialLoading &&
+ !loadingMore &&
+ jobs.length < totalJobs
+ ) {
+ loadJobs(page + 1, filterKey, searchTerm || undefined);
+ }
+ },
+ { threshold: 0.1 },
+ );
+
+ observer.observe(sentinel);
+ return () => observer.disconnect();
+ }, [
+ jobs.length,
+ totalJobs,
+ page,
+ filterKey,
+ searchTerm,
+ initialLoading,
+ loadingMore,
+ loadJobs,
+ ]);
+
const onFilterChange = (filterBy: string) => {
if (filterBy === "none") {
setFilterKey(undefined);
@@ -390,7 +424,7 @@ function JobsContainer({
size="sm"
variant="outline"
className="h-8 gap-1"
- disabled={loading}
+ disabled={initialLoading}
onClick={downloadJobsList}
>
<File className="h-3.5 w-3.5" />
@@ -411,7 +445,7 @@ function JobsContainer({
</div>
</CardHeader>
<CardContent>
- {loading && <Loading />}
+ {initialLoading && <Loading />}
{jobs.length > 0 && (
<>
<MyJobsTable
@@ -438,18 +472,10 @@ function JobsContainer({
</>
)}
{jobs.length < totalJobs && (
- <div className="flex justify-center p-4">
- <Button
- size="sm"
- variant="outline"
- onClick={() =>
- loadJobs(page + 1, filterKey, searchTerm || undefined)
- }
- disabled={loading}
- className="btn btn-primary"
- >
- {loading ? "Loading..." : "Load More"}
- </Button>
+ <div ref={sentinelRef} className="flex justify-center p-4">
+ {loadingMore && (
+ <Loader className="h-5 w-5 animate-spin text-blue-500" />
+ )}
</div>
)}
</CardContent>
diff --git a/src/components/tasks/TasksContainer.tsx b/src/components/tasks/TasksContainer.tsx
index 289004a..9d06d24 100644
--- a/src/components/tasks/TasksContainer.tsx
+++ b/src/components/tasks/TasksContainer.tsx
@@ -9,7 +9,7 @@ import {
CardTitle,
} from "../ui/card";
import { Button } from "../ui/button";
-import { ListFilter, PlusCircle, Filter, Search } from "lucide-react";
+import { ListFilter, Loader, PlusCircle, Filter, Search } from "lucide-react";
import { Input } from "../ui/input";
import {
deleteTaskById,
@@ -68,7 +68,8 @@ function TasksContainer({
const [page, setPage] = useState(1);
const [totalTasks, setTotalTasks] = useState(0);
const [editTask, setEditTask] = useState<Task | null>(null);
- const [loading, setLoading] = useState(false);
+ const [initialLoading, setInitialLoading] = useState(false);
+ const [loadingMore, setLoadingMore] = useState(false);
const [groupBy, setGroupBy] = useState<
"none" | "createdDate" | "dueDate" | "updatedDate" | "activityType"
>("none");
@@ -81,6 +82,7 @@ function TasksContainer({
);
const [searchTerm, setSearchTerm] = useState("");
const hasSearched = useRef(false);
+ const sentinelRef = useRef<HTMLDivElement>(null);
const [mounted, setMounted] = useState(false);
// Avoid hydration mismatch with Radix UI components
@@ -97,7 +99,8 @@ function TasksContainer({
statuses?: TaskStatus[],
search?: string,
) => {
- setLoading(true);
+ if (pageNum === 1) setInitialLoading(true);
+ else setLoadingMore(true);
const { success, data, total, message } = await getTasksList(
pageNum,
tasksPerPage,
@@ -109,15 +112,15 @@ function TasksContainer({
setTasks((prev) => (pageNum === 1 ? data : [...prev, ...data]));
setTotalTasks(total);
setPage(pageNum);
- setLoading(false);
} else {
toast({
variant: "destructive",
title: "Error!",
description: message,
});
- setLoading(false);
}
+ setInitialLoading(false);
+ setLoadingMore(false);
},
[tasksPerPage],
);
@@ -228,6 +231,44 @@ function TasksContainer({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchTerm]);
+ // Infinite scroll: auto-load next page when sentinel is visible
+ useEffect(() => {
+ const sentinel = sentinelRef.current;
+ if (!sentinel) return;
+
+ const observer = new IntersectionObserver(
+ (entries) => {
+ if (
+ entries[0].isIntersecting &&
+ !initialLoading &&
+ !loadingMore &&
+ tasks.length < totalTasks
+ ) {
+ loadTasks(
+ page + 1,
+ filterKey,
+ statusFilter,
+ searchTerm || undefined,
+ );
+ }
+ },
+ { threshold: 0.1 },
+ );
+
+ observer.observe(sentinel);
+ return () => observer.disconnect();
+ }, [
+ tasks.length,
+ totalTasks,
+ page,
+ filterKey,
+ statusFilter,
+ searchTerm,
+ initialLoading,
+ loadingMore,
+ loadTasks,
+ ]);
+
const onGroupByChange = (value: string) => {
setGroupBy(
value as
@@ -344,8 +385,8 @@ function TasksContainer({
</div>
</CardHeader>
<CardContent>
- {loading && <Loading />}
- {!loading && tasks.length > 0 && (
+ {initialLoading && <Loading />}
+ {!initialLoading && tasks.length > 0 && (
<>
<TasksTable
tasks={tasks}
@@ -370,29 +411,16 @@ function TasksContainer({
</div>
</>
)}
- {!loading && tasks.length === 0 && (
+ {!initialLoading && tasks.length === 0 && (
<div className="text-center py-8 text-muted-foreground">
No tasks found. Create your first task to get started.
</div>
)}
{tasks.length < totalTasks && (
- <div className="flex justify-center p-4">
- <Button
- size="sm"
- variant="outline"
- onClick={() =>
- loadTasks(
- page + 1,
- filterKey,
- statusFilter,
- searchTerm || undefined,
- )
- }
- disabled={loading}
- className="btn btn-primary"
- >
- {loading ? "Loading..." : "Load More"}
- </Button>
+ <div ref={sentinelRef} className="flex justify-center p-4">
+ {loadingMore && (
+ <Loader className="h-5 w-5 animate-spin text-blue-500" />
+ )}
</div>
)}
</CardContent>