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(jobs-activity): add jobs trend calculation and minor adjustments

Khuram Niaz9f2ef325a0c4
diff --git a/__tests__/JobsActivityCard.spec.tsx b/__tests__/JobsActivityCard.spec.tsx
index 673cf58..2638363 100644
--- a/__tests__/JobsActivityCard.spec.tsx
+++ b/__tests__/JobsActivityCard.spec.tsx
@@ -21,11 +21,19 @@ vi.mock("@nivo/pie", () => ({
describe("JobsActivityCard", () => {
const user = userEvent.setup();
+ // usePersistedTabIndex writes the chosen tab to localStorage, which
+ // vitest's clearMocks does not reset — without this a test that clicks
+ // "30d" decides the starting tab for every test after it.
+ beforeEach(() => {
+ localStorage.clear();
+ });
+
const data = [
{
label: "7d",
summary: {
jobsApplied: 16,
+ jobsTrend: 25,
topActivities: [
{ label: "Jobsync", hours: 28.1 },
{ label: "Side Project 1", hours: 9.2 },
@@ -39,6 +47,7 @@ describe("JobsActivityCard", () => {
label: "30d",
summary: {
jobsApplied: 34,
+ jobsTrend: -12,
topActivities: [{ label: "Job Search", hours: 6.4 }],
otherHours: 0,
totalHours: 6.4,
@@ -91,6 +100,34 @@ describe("JobsActivityCard", () => {
expect(screen.queryByText("Other")).not.toBeInTheDocument();
});
+ it("shows the jobs trend under the job count", () => {
+ render(<JobsActivityCard data={data} />);
+
+ const total = screen.getByTestId("jobs-activity-total");
+
+ expect(within(total).getByText("25%")).toBeInTheDocument();
+ });
+
+ it("drops the sign from a falling trend, leaving the arrow to carry it", async () => {
+ render(<JobsActivityCard data={data} />);
+
+ const toggle = screen.getByTestId("jobs-activity-toggle-group");
+ await user.click(within(toggle).getByRole("button", { name: "30d" }));
+
+ const total = screen.getByTestId("jobs-activity-total");
+
+ expect(within(total).getByText("12%")).toBeInTheDocument();
+ expect(within(total).queryByText("-12%")).not.toBeInTheDocument();
+ });
+
+ it("hides the trend entirely when it is flat", () => {
+ render(<JobsActivityCard data={data.slice(0, 1)} />);
+
+ const total = screen.getByTestId("jobs-activity-total");
+
+ expect(within(total).queryByText("0%")).not.toBeInTheDocument();
+ });
+
it("says one job, not one jobs", () => {
render(
<JobsActivityCard
@@ -99,6 +136,7 @@ describe("JobsActivityCard", () => {
label: "7d",
summary: {
jobsApplied: 1,
+ jobsTrend: 0,
topActivities: [{ label: "Job Search", hours: 2 }],
otherHours: 0,
totalHours: 2,
@@ -119,6 +157,7 @@ describe("JobsActivityCard", () => {
label: "7d",
summary: {
jobsApplied: 3,
+ jobsTrend: 0,
topActivities: [],
otherHours: 0,
totalHours: 0,
diff --git a/__tests__/RecentCardToggle.spec.tsx b/__tests__/RecentCardToggle.spec.tsx
index 003825b..e8f5918 100644
--- a/__tests__/RecentCardToggle.spec.tsx
+++ b/__tests__/RecentCardToggle.spec.tsx
@@ -32,6 +32,8 @@ describe("RecentCardToggle - Start Activity", () => {
beforeEach(() => {
vi.clearAllMocks();
+ // usePersistedTabIndex persists the tab; clearAllMocks does not reset it.
+ localStorage.clear();
});
it("starts the activity directly when nothing is currently in progress", async () => {
diff --git a/__tests__/dashboard.actions.spec.ts b/__tests__/dashboard.actions.spec.ts
index 41ba295..b132b05 100644
--- a/__tests__/dashboard.actions.spec.ts
+++ b/__tests__/dashboard.actions.spec.ts
@@ -354,6 +354,7 @@ describe("Dashboard Actions", () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
(prisma.$transaction as any).mockResolvedValue([
12,
+ 8,
activityRows([
["Jobsync", 600],
["Learning", 300],
@@ -378,6 +379,7 @@ describe("Dashboard Actions", () => {
it("makes totalHours equal the sum of the values it reports", async () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
(prisma.$transaction as any).mockResolvedValue([
+ 0,
0,
activityRows([
["A", 50],
@@ -398,6 +400,7 @@ describe("Dashboard Actions", () => {
it("reports zero otherHours when there are three or fewer types", async () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
(prisma.$transaction as any).mockResolvedValue([
+ 3,
3,
activityRows([
["Jobsync", 120],
@@ -414,12 +417,13 @@ describe("Dashboard Actions", () => {
it("returns empty results when nothing is logged", async () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
- (prisma.$transaction as any).mockResolvedValue([0, []]);
+ (prisma.$transaction as any).mockResolvedValue([0, 0, []]);
const result = await getJobsActivitySummary(7);
expect(result).toEqual({
jobsApplied: 0,
+ jobsTrend: 0,
topActivities: [],
otherHours: 0,
totalHours: 0,
@@ -429,6 +433,7 @@ describe("Dashboard Actions", () => {
it("labels activities with no type as Unknown", async () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
(prisma.$transaction as any).mockResolvedValue([
+ 0,
0,
[{ duration: 90, activityType: null }],
]);
@@ -438,6 +443,33 @@ describe("Dashboard Actions", () => {
expect(result.topActivities).toEqual([{ label: "Unknown", hours: 1.5 }]);
});
+ it("reports the percent change against the preceding window", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ (prisma.$transaction as any).mockResolvedValue([15, 10, []]);
+
+ const result = await getJobsActivitySummary(7);
+
+ expect(result.jobsTrend).toBe(50);
+ });
+
+ it("reports a negative trend when the count fell", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ (prisma.$transaction as any).mockResolvedValue([5, 10, []]);
+
+ const result = await getJobsActivitySummary(7);
+
+ expect(result.jobsTrend).toBe(-50);
+ });
+
+ it("reports a zero trend when the preceding window was also empty", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ (prisma.$transaction as any).mockResolvedValue([0, 0, []]);
+
+ const result = await getJobsActivitySummary(7);
+
+ expect(result.jobsTrend).toBe(0);
+ });
+
it("throws when the user is not authenticated", async () => {
(getCurrentUser as any).mockResolvedValue(null);
diff --git a/src/actions/dashboard/stats.ts b/src/actions/dashboard/stats.ts
index afdfd73..4c6f3d5 100644
--- a/src/actions/dashboard/stats.ts
+++ b/src/actions/dashboard/stats.ts
@@ -1,4 +1,5 @@
import prisma from "@/lib/db";
+import { calculatePercentageDifference } from "@/lib/utils";
import { requireUser } from "../shared";
import { getLocalDayRange } from "./shared";
@@ -9,6 +10,7 @@ export interface TopActivityType {
export interface JobsActivitySummary {
jobsApplied: number;
+ jobsTrend: number;
topActivities: TopActivityType[];
otherHours: number;
totalHours: number;
@@ -28,8 +30,10 @@ export const getJobsActivitySummary = async (
try {
const { start, end } = getLocalDayRange(daysAgo - 1);
+ // The equally long window immediately before this one, for the trend.
+ const { start: priorStart } = getLocalDayRange(daysAgo * 2 - 1);
- const [jobsApplied, activities] = await prisma.$transaction([
+ const [jobsApplied, priorJobs, activities] = await prisma.$transaction([
prisma.job.count({
where: {
userId: user.id,
@@ -37,6 +41,13 @@ export const getJobsActivitySummary = async (
appliedDate: { gte: start, lte: end },
},
}),
+ prisma.job.count({
+ where: {
+ userId: user.id,
+ applied: true,
+ appliedDate: { gte: priorStart, lt: start },
+ },
+ }),
prisma.activity.findMany({
where: {
userId: user.id,
@@ -74,7 +85,10 @@ export const getJobsActivitySummary = async (
topActivities.reduce((sum, entry) => sum + entry.hours, 0) + otherHours,
);
- return { jobsApplied, topActivities, otherHours, totalHours };
+ const jobsTrend =
+ calculatePercentageDifference(priorJobs, jobsApplied) ?? 0;
+
+ return { jobsApplied, jobsTrend, topActivities, otherHours, totalHours };
} catch (error) {
const msg = "Failed to fetch jobs and activity summary";
console.error(msg, error);
diff --git a/src/components/dashboard/JobsActivityCard.tsx b/src/components/dashboard/JobsActivityCard.tsx
index 011d6ec..0710838 100644
--- a/src/components/dashboard/JobsActivityCard.tsx
+++ b/src/components/dashboard/JobsActivityCard.tsx
@@ -2,6 +2,7 @@
import { ResponsivePie } from "@nivo/pie";
import { useTheme } from "next-themes";
+import { TrendingDown, TrendingUp } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { JobsActivitySummary } from "@/actions/dashboard.actions";
import { usePersistedTabIndex } from "@/hooks/usePersistedTabIndex";
@@ -23,7 +24,7 @@ export default function JobsActivityCard({ data }: JobsActivityCardProps) {
);
const { resolvedTheme } = useTheme();
const current = data[activeIndex];
- const { jobsApplied, topActivities, otherHours, totalHours } =
+ const { jobsApplied, jobsTrend, topActivities, otherHours, totalHours } =
current.summary;
const slices = buildDonutSlices(
topActivities,
@@ -35,7 +36,7 @@ export default function JobsActivityCard({ data }: JobsActivityCardProps) {
<Card className="@lg:col-span-2">
<CardHeader className="pb-2">
<div className="flex items-center justify-between gap-2">
- <CardTitle className="text-sm font-medium text-green-600 min-w-0 truncate">
+ <CardTitle className="text-lg text-green-600 min-w-0 truncate">
Jobs &amp; Activity
</CardTitle>
<div
@@ -69,7 +70,7 @@ export default function JobsActivityCard({ data }: JobsActivityCardProps) {
) : (
<ResponsivePie
data={slices}
- margin={{ top: 0, right: 0, bottom: 0, left: 0 }}
+ margin={{ top: 4, right: 4, bottom: 4, left: 4 }}
innerRadius={0.72}
padAngle={2}
cornerRadius={2}
@@ -103,12 +104,27 @@ export default function JobsActivityCard({ data }: JobsActivityCardProps) {
className="pointer-events-none absolute inset-0 flex flex-col items-center justify-center gap-px text-center"
data-testid="jobs-activity-total"
>
- <span className="text-2xl font-bold leading-tight tabular-nums">
+ <span className="text-xl font-bold leading-tight tabular-nums">
{totalHours}h
</span>
- <span className="text-xs text-muted-foreground tabular-nums">
+ <span className="text-sm text-muted-foreground tabular-nums">
{jobsApplied} {jobsApplied === 1 ? "job" : "jobs"}
</span>
+ {jobsTrend !== 0 && (
+ <span
+ className={cn(
+ "flex items-center gap-0.5 text-[10px] tabular-nums",
+ jobsTrend > 0 ? "text-emerald-600" : "text-rose-600",
+ )}
+ >
+ {jobsTrend > 0 ? (
+ <TrendingUp className="h-3 w-3" />
+ ) : (
+ <TrendingDown className="h-3 w-3" />
+ )}
+ {Math.abs(jobsTrend)}%
+ </span>
+ )}
</div>
</div>
diff --git a/src/components/dashboard/JobsAppliedCard.tsx b/src/components/dashboard/JobsAppliedCard.tsx
index 34b96b3..04224fd 100644
--- a/src/components/dashboard/JobsAppliedCard.tsx
+++ b/src/components/dashboard/JobsAppliedCard.tsx
@@ -13,14 +13,14 @@ import { useRouter } from "next/navigation";
export default function JobsAppliedCard() {
const router = useRouter();
return (
- <Card className="sm:col-span-2 min-w-0">
+ <Card className="sm:col-span-2 min-w-0 flex flex-col">
<CardHeader className="pb-3">
<CardTitle className="text-lg text-green-600">Dashboard</CardTitle>
<CardDescription className="max-w-lg text-balance leading-relaxed">
Create new jobs, tasks, automations, and questions.
</CardDescription>
</CardHeader>
- <CardFooter className="grid grid-cols-2 gap-2">
+ <CardFooter className="mt-auto grid grid-cols-2 gap-2">
<Button
variant="outline"
className="justify-start min-w-0"
diff --git a/src/components/profile/resume-container/useResumeExportSettings.ts b/src/components/profile/resume-container/useResumeExportSettings.ts
index 393f9fc..dbefee9 100644
--- a/src/components/profile/resume-container/useResumeExportSettings.ts
+++ b/src/components/profile/resume-container/useResumeExportSettings.ts
@@ -17,8 +17,8 @@ import {
const KEY = APP_CONSTANTS.RESUME_EXPORT_SETTINGS_STORAGE_KEY;
-// Rebuilt from a spread of the defaults, so the key order always comes from
-// that one literal — the preview cache key is JSON.stringify(settings).
+// Rebuilt from a spread of the template's defaults, so a stored object can
+// only ever contribute values — never extra keys, and never a missing one.
export function coerceResumeExportSettings(
stored: unknown,
): ResumeExportSettings {