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: add card view toggle to the jobs page

Khuram Niaz436723e46a4f
diff --git a/__tests__/JobsContainer.spec.tsx b/__tests__/JobsContainer.spec.tsx
index f8e242f..9d8abb9 100644
--- a/__tests__/JobsContainer.spec.tsx
+++ b/__tests__/JobsContainer.spec.tsx
@@ -1061,4 +1061,48 @@ describe("JobsContainer Search Functionality", () => {
});
});
});
+
+ describe("view mode toggle", () => {
+ beforeEach(() => {
+ localStorage.clear();
+ });
+
+ it("renders the table by default and switches to cards on toggle", async () => {
+ (getJobsList as any).mockResolvedValue({
+ success: true,
+ data: mockJobs,
+ total: 2,
+ });
+
+ renderComponent();
+
+ await waitFor(() =>
+ expect(screen.getByRole("table")).toBeInTheDocument(),
+ );
+
+ await user.click(screen.getByTestId("jobs-view-cards-btn"));
+
+ expect(screen.queryByRole("table")).not.toBeInTheDocument();
+ expect(localStorage.getItem("jobs-view-mode")).toBe('"cards"');
+ });
+
+ it("restores the persisted card view on mount", async () => {
+ localStorage.setItem("jobs-view-mode", '"cards"');
+ (getJobsList as any).mockResolvedValue({
+ success: true,
+ data: mockJobs,
+ total: 2,
+ });
+
+ renderComponent();
+
+ await waitFor(() =>
+ expect(screen.getByTestId("jobs-view-cards-btn")).toHaveAttribute(
+ "aria-pressed",
+ "true",
+ ),
+ );
+ expect(screen.queryByRole("table")).not.toBeInTheDocument();
+ });
+ });
});
diff --git a/src/components/myjobs/JobsContainer.tsx b/src/components/myjobs/JobsContainer.tsx
index 46527e1..1dece2b 100644
--- a/src/components/myjobs/JobsContainer.tsx
+++ b/src/components/myjobs/JobsContainer.tsx
@@ -23,6 +23,7 @@ import {
JobResponse,
JobSource,
JobStatus,
+ JobsViewMode,
JobTitle,
Tag,
} from "@/models/job.model";
@@ -41,9 +42,12 @@ import Loading from "../Loading";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { AddJob } from "./AddJob";
import MyJobsTable from "./MyJobsTable";
+import MyJobsGrid from "./MyJobsGrid";
+import { JobsViewToggle } from "./JobsViewToggle";
import { NoteDialog } from "./NoteDialog";
import { format } from "date-fns";
import { RecordsCount } from "../RecordsCount";
+import { getFromLocalStorage, saveToLocalStorage } from "@/utils/localstorage.utils";
type MyJobsProps = {
statuses: JobStatus[];
@@ -90,6 +94,7 @@ function JobsContainer({
queryParams.get("applied") === "true",
);
const [jobs, setJobs] = useState<JobResponse[]>([]);
+ const [viewMode, setViewMode] = useState<JobsViewMode>("table");
const [page, setPage] = useState(1);
const [totalJobs, setTotalJobs] = useState(0);
const [filterKey, setFilterKey] = useState<string>("none");
@@ -155,6 +160,21 @@ function JobsContainer({
setAppliedFilter(ap);
}, [queryParams]);
+ // Read after mount: localStorage is unavailable during SSR, so seeding the
+ // initial state from it would cause a hydration mismatch.
+ useEffect(() => {
+ const saved = getFromLocalStorage(
+ APP_CONSTANTS.JOBS_VIEW_MODE_STORAGE_KEY,
+ null,
+ );
+ if (saved === "cards" || saved === "table") setViewMode(saved);
+ }, []);
+
+ const onChangeViewMode = (mode: JobsViewMode) => {
+ setViewMode(mode);
+ saveToLocalStorage(APP_CONSTANTS.JOBS_VIEW_MODE_STORAGE_KEY, mode);
+ };
+
const jobsPerPage = APP_CONSTANTS.RECORDS_PER_PAGE;
const loadJobs = useCallback(
@@ -335,6 +355,7 @@ function JobsContainer({
)}
</div>
<div className="flex flex-wrap items-center justify-end gap-2 sm:ml-auto">
+ <JobsViewToggle value={viewMode} onChange={onChangeViewMode} />
{companyLabel && (
<button
onClick={clearCompanyFilter}
@@ -443,8 +464,17 @@ function JobsContainer({
</CardHeader>
<CardContent>
{initialLoading && <Loading />}
- {jobs.length > 0 && (
- <>
+ {jobs.length > 0 &&
+ (viewMode === "cards" ? (
+ <MyJobsGrid
+ jobs={jobs}
+ jobStatuses={statuses}
+ deleteJob={onDeleteJob}
+ editJob={onEditJob}
+ onChangeJobStatus={onChangeJobStatus}
+ onAddNote={onAddNote}
+ />
+ ) : (
<MyJobsTable
jobs={jobs}
jobStatuses={statuses}
@@ -453,8 +483,7 @@ function JobsContainer({
onChangeJobStatus={onChangeJobStatus}
onAddNote={onAddNote}
/>
- </>
- )}
+ ))}
{jobs.length < totalJobs && (
<div ref={sentinelRef} className="flex justify-center p-4">
{loadingMore && (