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.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
feat(dashboard): merge the Jobs and Activities cards into one donut card
Khuram Niazfe7d237868b9
diff --git a/__tests__/JobsActivityCard.spec.tsx b/__tests__/JobsActivityCard.spec.tsxnew file mode 100644index 0000000..673cf58--- /dev/null+++ b/__tests__/JobsActivityCard.spec.tsx@@ -0,0 +1,136 @@+import { render, screen, within } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import JobsActivityCard from "@/components/dashboard/JobsActivityCard";++vi.mock("next-themes", () => ({+ useTheme: () => ({ resolvedTheme: "light" }),+}));++vi.mock("@nivo/pie", () => ({+ ResponsivePie: (props: any) => (+ <div data-testid="donut">+ {props.data.map((slice: any) => (+ <div key={slice.id} data-testid={`slice-${slice.id}`}>+ {slice.label}:{slice.value}:{slice.color}+ </div>+ ))}+ </div>+ ),+}));++describe("JobsActivityCard", () => {+ const user = userEvent.setup();++ const data = [+ {+ label: "7d",+ summary: {+ jobsApplied: 16,+ topActivities: [+ { label: "Jobsync", hours: 28.1 },+ { label: "Side Project 1", hours: 9.2 },+ { label: "Learning", hours: 8.6 },+ ],+ otherHours: 17.5,+ totalHours: 63.4,+ },+ },+ {+ label: "30d",+ summary: {+ jobsApplied: 34,+ topActivities: [{ label: "Job Search", hours: 6.4 }],+ otherHours: 0,+ totalHours: 6.4,+ },+ },+ ];++ it("shows the period's total hours and job count in the donut center", () => {+ render(<JobsActivityCard data={data} />);++ const total = screen.getByTestId("jobs-activity-total");++ expect(within(total).getByText("63.4h")).toBeInTheDocument();+ expect(within(total).getByText("16 jobs")).toBeInTheDocument();+ });++ it("lists every slice with its hours in the legend", () => {+ render(<JobsActivityCard data={data} />);++ const legend = screen.getByTestId("jobs-activity-legend");++ expect(within(legend).getByText("Jobsync")).toBeInTheDocument();+ expect(within(legend).getByText("28.1h")).toBeInTheDocument();+ expect(within(legend).getByText("Other")).toBeInTheDocument();+ expect(within(legend).getByText("17.5h")).toBeInTheDocument();+ });++ it("feeds the same slices to the donut", () => {+ render(<JobsActivityCard data={data} />);++ expect(screen.getByTestId("slice-Jobsync")).toHaveTextContent(+ "Jobsync:28.1:#2a9d90",+ );+ expect(screen.getByTestId("slice-__other__")).toHaveTextContent(+ "Other:17.5:#94a3b8",+ );+ });++ it("switches every number when the period changes", 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("6.4h")).toBeInTheDocument();+ expect(within(total).getByText("34 jobs")).toBeInTheDocument();+ expect(screen.queryByText("Jobsync")).not.toBeInTheDocument();+ expect(screen.queryByText("Other")).not.toBeInTheDocument();+ });++ it("says one job, not one jobs", () => {+ render(+ <JobsActivityCard+ data={[+ {+ label: "7d",+ summary: {+ jobsApplied: 1,+ topActivities: [{ label: "Job Search", hours: 2 }],+ otherHours: 0,+ totalHours: 2,+ },+ },+ ]}+ />,+ );++ expect(screen.getByText("1 job")).toBeInTheDocument();+ });++ it("keeps the job count visible when no activity is logged", () => {+ render(+ <JobsActivityCard+ data={[+ {+ label: "7d",+ summary: {+ jobsApplied: 3,+ topActivities: [],+ otherHours: 0,+ totalHours: 0,+ },+ },+ ]}+ />,+ );++ expect(screen.getByText("0h")).toBeInTheDocument();+ expect(screen.getByText("3 jobs")).toBeInTheDocument();+ expect(screen.getByText("No activities recorded")).toBeInTheDocument();+ expect(screen.queryByTestId("donut")).not.toBeInTheDocument();+ });+});diff --git a/__tests__/dashboard.actions.spec.ts b/__tests__/dashboard.actions.spec.tsindex 6b7c818..41ba295 100644--- a/__tests__/dashboard.actions.spec.ts+++ b/__tests__/dashboard.actions.spec.ts@@ -1,5 +1,5 @@import {- getJobsAppliedForPeriod,+ getJobsActivitySummary,getRecentJobs,getActivityDataForPeriod,getJobsActivityForPeriod,@@ -38,46 +38,6 @@ describe("Dashboard Actions", () => {vi.clearAllMocks();});- describe("getJobsAppliedForPeriod", () => {- it("should return count and trend for authenticated user", async () => {- (getCurrentUser as any).mockResolvedValue(mockUser);- (prisma.$transaction as any).mockResolvedValue([10, 15]);-- const result = await getJobsAppliedForPeriod(7);-- expect(result).toEqual({ count: 10, trend: expect.any(Number) });- expect(prisma.$transaction).toHaveBeenCalledTimes(1);- });-- it("should throw error when user is not authenticated", async () => {- (getCurrentUser as any).mockResolvedValue(null);-- await expect(getJobsAppliedForPeriod(7)).rejects.toThrow(- "Not authenticated",- );- });-- it("should calculate zero trend when both counts are zero", async () => {- (getCurrentUser as any).mockResolvedValue(mockUser);- (prisma.$transaction as any).mockResolvedValue([0, 0]);-- const result = await getJobsAppliedForPeriod(7);-- expect(result).toEqual({ count: 0, trend: 0 });- });-- it("should handle database errors", async () => {- (getCurrentUser as any).mockResolvedValue(mockUser);- (prisma.$transaction as any).mockRejectedValue(- new Error("Database error"),- );-- await expect(getJobsAppliedForPeriod(7)).rejects.toThrow(- "Failed to calculate job count",- );- });- });-describe("getRecentJobs", () => {it("should return recent jobs for authenticated user", async () => {(getCurrentUser as any).mockResolvedValue(mockUser);@@ -382,4 +342,108 @@ describe("Dashboard Actions", () => {expect(result["2024"][0].value).toBe(5);});});++ describe("getJobsActivitySummary", () => {+ const activityRows = (rows: [string, number][]) =>+ rows.map(([label, duration]) => ({+ duration,+ activityType: { label },+ }));++ it("returns the top three types and folds the rest into otherHours", async () => {+ (getCurrentUser as any).mockResolvedValue(mockUser);+ (prisma.$transaction as any).mockResolvedValue([+ 12,+ activityRows([+ ["Jobsync", 600],+ ["Learning", 300],+ ["Side Project 1", 180],+ ["Job Search", 120],+ ["Networking", 60],+ ]),+ ]);++ const result = await getJobsActivitySummary(7);++ expect(result.jobsApplied).toBe(12);+ expect(result.topActivities).toEqual([+ { label: "Jobsync", hours: 10 },+ { label: "Learning", hours: 5 },+ { label: "Side Project 1", hours: 3 },+ ]);+ expect(result.otherHours).toBe(3);+ expect(result.totalHours).toBe(21);+ });++ it("makes totalHours equal the sum of the values it reports", async () => {+ (getCurrentUser as any).mockResolvedValue(mockUser);+ (prisma.$transaction as any).mockResolvedValue([+ 0,+ activityRows([+ ["A", 50],+ ["B", 25],+ ["C", 25],+ ["D", 5],+ ]),+ ]);++ const result = await getJobsActivitySummary(30);+ const sum =+ result.topActivities.reduce((acc, a) => acc + a.hours, 0) ++ result.otherHours;++ expect(result.totalHours).toBeCloseTo(sum, 5);+ });++ it("reports zero otherHours when there are three or fewer types", async () => {+ (getCurrentUser as any).mockResolvedValue(mockUser);+ (prisma.$transaction as any).mockResolvedValue([+ 3,+ activityRows([+ ["Jobsync", 120],+ ["Learning", 60],+ ]),+ ]);++ const result = await getJobsActivitySummary(7);++ expect(result.topActivities).toHaveLength(2);+ expect(result.otherHours).toBe(0);+ expect(result.totalHours).toBe(3);+ });++ it("returns empty results when nothing is logged", async () => {+ (getCurrentUser as any).mockResolvedValue(mockUser);+ (prisma.$transaction as any).mockResolvedValue([0, []]);++ const result = await getJobsActivitySummary(7);++ expect(result).toEqual({+ jobsApplied: 0,+ topActivities: [],+ otherHours: 0,+ totalHours: 0,+ });+ });++ it("labels activities with no type as Unknown", async () => {+ (getCurrentUser as any).mockResolvedValue(mockUser);+ (prisma.$transaction as any).mockResolvedValue([+ 0,+ [{ duration: 90, activityType: null }],+ ]);++ const result = await getJobsActivitySummary(7);++ expect(result.topActivities).toEqual([{ label: "Unknown", hours: 1.5 }]);+ });++ it("throws when the user is not authenticated", async () => {+ (getCurrentUser as any).mockResolvedValue(null);++ await expect(getJobsActivitySummary(7)).rejects.toThrow(+ "Not authenticated",+ );+ });+ });});diff --git a/__tests__/jobsActivityChart.spec.ts b/__tests__/jobsActivityChart.spec.tsnew file mode 100644index 0000000..6c17842--- /dev/null+++ b/__tests__/jobsActivityChart.spec.ts@@ -0,0 +1,78 @@+import {+ buildDonutSlices,+ OTHER_SLICE_ID,+} from "@/components/dashboard/jobsActivityChart";++describe("buildDonutSlices", () => {+ const activities = [+ { label: "Jobsync", hours: 28.1 },+ { label: "Side Project 1", hours: 9.2 },+ { label: "Learning", hours: 8.6 },+ ];++ it("assigns one fixed hue per rank in light mode", () => {+ const slices = buildDonutSlices(activities, 0, "light");++ expect(slices.map((s) => s.color)).toEqual([+ "#2a9d90",+ "#c97e22",+ "#6d4fc7",+ ]);+ });++ it("uses the dark palette in dark mode", () => {+ const slices = buildDonutSlices(activities, 0, "dark");++ expect(slices.map((s) => s.color)).toEqual([+ "#16a89a",+ "#c08438",+ "#8b72e8",+ ]);+ });++ it("keeps each activity's label, hours and identity", () => {+ const slices = buildDonutSlices(activities, 0, "light");++ expect(slices).toHaveLength(3);+ expect(slices[0]).toMatchObject({+ id: "Jobsync",+ label: "Jobsync",+ value: 28.1,+ });+ });++ it("appends a grey Other slice when there are leftover hours", () => {+ const slices = buildDonutSlices(activities, 17.5, "light");++ expect(slices).toHaveLength(4);+ expect(slices[3]).toEqual({+ id: OTHER_SLICE_ID,+ label: "Other",+ value: 17.5,+ color: "#94a3b8",+ });+ });++ it("omits the Other slice when there are no leftover hours", () => {+ const slices = buildDonutSlices(activities, 0, "light");++ expect(slices.some((s) => s.id === OTHER_SLICE_ID)).toBe(false);+ });++ it("drops activities with no logged hours", () => {+ const slices = buildDonutSlices(+ [+ { label: "Jobsync", hours: 4 },+ { label: "Learning", hours: 0 },+ ],+ 0,+ "light",+ );++ expect(slices.map((s) => s.label)).toEqual(["Jobsync"]);+ });++ it("returns nothing when there is no activity at all", () => {+ expect(buildDonutSlices([], 0, "light")).toEqual([]);+ });+});diff --git a/e2e/dashboard.spec.ts b/e2e/dashboard.spec.tsindex c88362f..3767fd6 100644--- a/e2e/dashboard.spec.ts+++ b/e2e/dashboard.spec.ts@@ -206,16 +206,10 @@ test.describe("Dashboard page", () => {test("should toggle the recent, weekly, jobs and activities cards", async ({page,}) => {- const numberToggle = page.getByTestId("number-card-toggle-group");- await numberToggle.getByRole("button", { name: "30d" }).click();+ const jobsActivityToggle = page.getByTestId("jobs-activity-toggle-group");+ await jobsActivityToggle.getByRole("button", { name: "30d" }).click();await expect(- numberToggle.getByRole("button", { name: "30d" }),- ).toHaveClass(/bg-primary/);-- const topActivitiesToggle = page.getByTestId("top-activities-toggle-group");- await topActivitiesToggle.getByRole("button", { name: "30d" }).click();- await expect(- topActivitiesToggle.getByRole("button", { name: "30d" }),+ jobsActivityToggle.getByRole("button", { name: "30d" }),).toHaveClass(/bg-primary/);const recentToggle = page.getByTestId("recent-card-toggle-group");diff --git a/package-lock.json b/package-lock.jsonindex 48ec048..d162b5a 100644--- a/package-lock.json+++ b/package-lock.json@@ -17,6 +17,7 @@"@nivo/bar": "^0.99.0","@nivo/calendar": "^0.99.0","@nivo/core": "^0.99.0",+ "@nivo/pie": "^0.99.0","@prisma/client": "^6.19.0","@radix-ui/react-alert-dialog": "^1.1.3","@radix-ui/react-avatar": "^1.1.2",@@ -2375,6 +2376,25 @@"react": "^16.14 || ^17.0 || ^18.0 || ^19.0"}},+ "node_modules/@nivo/arcs": {+ "version": "0.99.0",+ "resolved": "https://registry.npmjs.org/@nivo/arcs/-/arcs-0.99.0.tgz",+ "integrity": "sha512-UcvWLQPl+A3APk2Gm74N5xDfT+ATnVs2XkP73WxhYPWJk+dBzF00cndA5g/dptOwdFBvvo62VgcCsNiwUsjKTw==",+ "license": "MIT",+ "dependencies": {+ "@nivo/colors": "0.99.0",+ "@nivo/core": "0.99.0",+ "@nivo/text": "0.99.0",+ "@nivo/theming": "0.99.0",+ "@react-spring/core": "9.4.5 || ^9.7.2 || ^10.0",+ "@react-spring/web": "9.4.5 || ^9.7.2 || ^10.0",+ "@types/d3-shape": "^3.1.6",+ "d3-shape": "^3.2.0"+ },+ "peerDependencies": {+ "react": "^16.14 || ^17.0 || ^18.0 || ^19.0"+ }+ },"node_modules/@nivo/axes": {"version": "0.99.0","resolved": "https://registry.npmjs.org/@nivo/axes/-/axes-0.99.0.tgz",@@ -2523,6 +2543,25 @@"react": "^16.14 || ^17.0 || ^18.0 || ^19.0"}},+ "node_modules/@nivo/pie": {+ "version": "0.99.0",+ "resolved": "https://registry.npmjs.org/@nivo/pie/-/pie-0.99.0.tgz",+ "integrity": "sha512-zUbo8UdLndp2RMljrOqitAKKEnl7YypkJrOzjKLk8jQGU7qqUKtgFoJIPhiBsvNPs3xtX2KwgtS1+JKNTNns7A==",+ "license": "MIT",+ "dependencies": {+ "@nivo/arcs": "0.99.0",+ "@nivo/colors": "0.99.0",+ "@nivo/core": "0.99.0",+ "@nivo/legends": "0.99.0",+ "@nivo/theming": "0.99.0",+ "@nivo/tooltip": "0.99.0",+ "@types/d3-shape": "^3.1.6",+ "d3-shape": "^3.2.0"+ },+ "peerDependencies": {+ "react": "^16.14 || ^17.0 || ^18.0 || ^19.0"+ }+ },"node_modules/@nivo/scales": {"version": "0.99.0","resolved": "https://registry.npmjs.org/@nivo/scales/-/scales-0.99.0.tgz",diff --git a/package.json b/package.jsonindex 1b8433d..03c1c4c 100644--- a/package.json+++ b/package.json@@ -37,6 +37,7 @@"@nivo/bar": "^0.99.0","@nivo/calendar": "^0.99.0","@nivo/core": "^0.99.0",+ "@nivo/pie": "^0.99.0","@prisma/client": "^6.19.0","@radix-ui/react-alert-dialog": "^1.1.3","@radix-ui/react-avatar": "^1.1.2",diff --git a/src/actions/dashboard.actions.ts b/src/actions/dashboard.actions.tsindex 688d6f7..cb22e24 100644--- a/src/actions/dashboard.actions.ts+++ b/src/actions/dashboard.actions.ts@@ -3,11 +3,8 @@// "use server": these are plain server-side reads called from the dashboard// page, and TopActivityType is a type export a client component imports.-export {- getJobsAppliedForPeriod,- getTopActivityTypesByDuration,-} from "./dashboard/stats";-export type { TopActivityType } from "./dashboard/stats";+export { getJobsActivitySummary } from "./dashboard/stats";+export type { TopActivityType, JobsActivitySummary } from "./dashboard/stats";export { getRecentJobs, getRecentActivities } from "./dashboard/recent";diff --git a/src/actions/dashboard/stats.ts b/src/actions/dashboard/stats.tsindex 3050535..afdfd73 100644--- a/src/actions/dashboard/stats.ts+++ b/src/actions/dashboard/stats.ts@@ -1,7 +1,4 @@import prisma from "@/lib/db";-import { calculatePercentageDifference } from "@/lib/utils";-import { Prisma } from "@prisma/client";-import { subDays } from "date-fns";import { requireUser } from "../shared";import { getLocalDayRange } from "./shared";@@ -10,87 +7,76 @@ export interface TopActivityType {hours: number;}-// Auth guard sits outside the try so an unauthenticated call surfaces-// "Not authenticated" rather than this function's generic message.-export const getJobsAppliedForPeriod = async (- daysAgo: number,-): Promise<any | undefined> => {- const user = await requireUser();-- try {- const startDate1 = subDays(new Date(), daysAgo);- const startDate2 = subDays(new Date(), daysAgo * 2);- const endDate = new Date();- const query = (date: Date): Prisma.JobCountArgs => ({- where: {- userId: user.id,- applied: true,- appliedDate: {- gte: date,- lt: endDate,- },- },- });+export interface JobsActivitySummary {+ jobsApplied: number;+ topActivities: TopActivityType[];+ otherHours: number;+ totalHours: number;+}- const [count, count2] = await prisma.$transaction([- prisma.job.count(query(startDate1)),- prisma.job.count(query(startDate2)),- ]);- const difference = Math.abs(count2 - count);- const trend = calculatePercentageDifference(difference, count);- return { count, trend };- } catch (error) {- const msg = "Failed to calculate job count";- console.error(msg, error);- throw new Error(msg);- }-};+const roundToTenth = (hours: number) => Math.round(hours * 10) / 10;-// Auth guard sits outside the try, as above.-export const getTopActivityTypesByDuration = async (+// One read for the merged Jobs & Activity card. Both halves share+// getLocalDayRange so "7d" means the same window on each; the retired+// getJobsAppliedForPeriod counted a rolling 7x24h window instead.+// Auth guard sits outside the try so an unauthenticated call surfaces+// "Not authenticated" rather than this function's generic message.+export const getJobsActivitySummary = async (daysAgo: number,-): Promise<TopActivityType[]> => {+): Promise<JobsActivitySummary> => {const user = await requireUser();try {- const { start: startDate, end: today } = getLocalDayRange(daysAgo - 1);+ const { start, end } = getLocalDayRange(daysAgo - 1);- const activities = await prisma.activity.findMany({- where: {- userId: user.id,- startTime: {- gte: startDate,- lte: today,+ const [jobsApplied, activities] = await prisma.$transaction([+ prisma.job.count({+ where: {+ userId: user.id,+ applied: true,+ appliedDate: { gte: start, lte: end },},- },- select: {- duration: true,- activityType: {- select: {- label: true,- },+ }),+ prisma.activity.findMany({+ where: {+ userId: user.id,+ startTime: { gte: start, lte: end },},- },- });+ select: {+ duration: true,+ activityType: { select: { label: true } },+ },+ }),+ ]);const groupedByType = activities.reduce((acc: Record<string, number>, activity) => {const label = activity.activityType?.label || "Unknown";- const durationInHours = (activity.duration || 0) / 60;- acc[label] = (acc[label] || 0) + durationInHours;+ acc[label] = (acc[label] || 0) + (activity.duration || 0) / 60;return acc;},{},);const sorted = Object.entries(groupedByType)- .map(([label, hours]) => ({ label, hours: Math.round(hours * 10) / 10 }))- .sort((a, b) => b.hours - a.hours)- .slice(0, 3);+ .map(([label, hours]) => ({ label, hours }))+ .sort((a, b) => b.hours - a.hours);++ const topActivities = sorted+ .slice(0, 3)+ .map(({ label, hours }) => ({ label, hours: roundToTenth(hours) }));+ const otherHours = roundToTenth(+ sorted.slice(3).reduce((sum, entry) => sum + entry.hours, 0),+ );+ // Totalled from the rounded parts so the number in the donut's+ // center always equals the legend beside it.+ const totalHours = roundToTenth(+ topActivities.reduce((sum, entry) => sum + entry.hours, 0) + otherHours,+ );- return sorted;+ return { jobsApplied, topActivities, otherHours, totalHours };} catch (error) {- const msg = "Failed to fetch top activity types";+ const msg = "Failed to fetch jobs and activity summary";console.error(msg, error);throw new Error(msg);}diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsxindex 2617202..1d1ef96 100644--- a/src/app/dashboard/page.tsx+++ b/src/app/dashboard/page.tsx@@ -2,16 +2,14 @@ import {getActivityCalendarData,getActivityDataForPeriod,getJobsActivityForPeriod,- getJobsAppliedForPeriod,+ getJobsActivitySummary,getRecentActivities,getRecentJobs,- getTopActivityTypesByDuration,} from "@/actions/dashboard.actions";import ActivityCalendar from "@/components/dashboard/ActivityCalendar";+import JobsActivityCard from "@/components/dashboard/JobsActivityCard";import JobsApplied from "@/components/dashboard/JobsAppliedCard";-import NumberCardToggle from "@/components/dashboard/NumberCardToggle";import RecentCardToggle from "@/components/dashboard/RecentCardToggle";-import TopActivitiesCard from "@/components/dashboard/TopActivitiesCard";import WeeklyBarChartToggle from "@/components/dashboard/WeeklyBarChartToggle";import { Metadata } from "next";@@ -22,25 +20,21 @@ export const metadata: Metadata = {export default async function Dashboard() {const [- { count: jobsAppliedLast7Days, trend: trendFor7Days },- { count: jobsAppliedLast30Days, trend: trendFor30Days },+ summary7Days,+ summary30Days,recentJobs,recentActivities,weeklyData,activitiesData,activityCalendarData,- topActivities7Days,- topActivities30Days,] = await Promise.all([- getJobsAppliedForPeriod(7),- getJobsAppliedForPeriod(30),+ getJobsActivitySummary(7),+ getJobsActivitySummary(30),getRecentJobs(),getRecentActivities(),getJobsActivityForPeriod(),getActivityDataForPeriod(),getActivityCalendarData(),- getTopActivityTypesByDuration(7),- getTopActivityTypesByDuration(30),]);const activityCalendarDataKeys = Object.keys(activityCalendarData);const activitiesDataKeys = (data: string[]) =>@@ -56,24 +50,10 @@ export default async function Dashboard() {<div className="@container grid grid-cols-1 auto-rows-max items-start gap-2 md:gap-2 @3xl/main:col-span-2"><div className="grid gap-2 @lg:grid-cols-4"><JobsApplied />- <NumberCardToggle+ <JobsActivityCarddata={[- {- label: "7d",- num: jobsAppliedLast7Days,- trend: trendFor7Days,- },- {- label: "30d",- num: jobsAppliedLast30Days,- trend: trendFor30Days,- },- ]}- />- <TopActivitiesCard- data={[- { label: "7d", activities: topActivities7Days },- { label: "30d", activities: topActivities30Days },+ { label: "7d", summary: summary7Days },+ { label: "30d", summary: summary30Days },]}/></div>diff --git a/src/components/dashboard/JobsActivityCard.tsx b/src/components/dashboard/JobsActivityCard.tsxnew file mode 100644index 0000000..011d6ec--- /dev/null+++ b/src/components/dashboard/JobsActivityCard.tsx@@ -0,0 +1,157 @@+"use client";++import { ResponsivePie } from "@nivo/pie";+import { useTheme } from "next-themes";+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";+import { JobsActivitySummary } from "@/actions/dashboard.actions";+import { usePersistedTabIndex } from "@/hooks/usePersistedTabIndex";+import { APP_CONSTANTS } from "@/lib/constants";+import { cn } from "@/lib/utils";+import { buildDonutSlices, OTHER_SLICE_ID } from "./jobsActivityChart";++interface JobsActivityCardProps {+ data: {+ label: string;+ summary: JobsActivitySummary;+ }[];+}++export default function JobsActivityCard({ data }: JobsActivityCardProps) {+ const [activeIndex, selectTab] = usePersistedTabIndex(+ APP_CONSTANTS.DASHBOARD_JOBS_ACTIVITY_STORAGE_KEY,+ data.map((item) => item.label),+ );+ const { resolvedTheme } = useTheme();+ const current = data[activeIndex];+ const { jobsApplied, topActivities, otherHours, totalHours } =+ current.summary;+ const slices = buildDonutSlices(+ topActivities,+ otherHours,+ resolvedTheme === "light" ? "light" : "dark",+ );++ return (+ <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">+ Jobs & Activity+ </CardTitle>+ <div+ className="flex shrink-0 rounded-md border text-xs"+ data-testid="jobs-activity-toggle-group"+ >+ {data.map((item, index) => (+ <button+ key={item.label}+ onClick={() => selectTab(index)}+ className={cn(+ "px-2 py-1 transition-colors",+ index === 0 && "rounded-l-md",+ index === data.length - 1 && "rounded-r-md",+ activeIndex === index+ ? "bg-primary text-primary-foreground"+ : "hover:bg-muted",+ )}+ >+ {item.label}+ </button>+ ))}+ </div>+ </div>+ </CardHeader>+ <CardContent className="@container/jobsactivity">+ <div className="flex flex-col items-center gap-4 @sm/jobsactivity:flex-row @sm/jobsactivity:gap-6">+ <div className="relative h-[148px] w-[148px] shrink-0">+ {slices.length === 0 ? (+ <div className="h-full w-full rounded-full border-[20px] border-muted" />+ ) : (+ <ResponsivePie+ data={slices}+ margin={{ top: 0, right: 0, bottom: 0, left: 0 }}+ innerRadius={0.72}+ padAngle={2}+ cornerRadius={2}+ activeOuterRadiusOffset={4}+ colors={{ datum: "data.color" }}+ borderWidth={0}+ enableArcLabels={false}+ enableArcLinkLabels={false}+ theme={{+ tooltip: {+ container: { background: "#1e293b", color: "#fff" },+ },+ }}+ tooltip={({ datum }) => (+ <div+ style={{+ background: "#1e293b",+ color: "#fff",+ padding: "6px 12px",+ borderRadius: "4px",+ fontSize: "12px",+ whiteSpace: "nowrap",+ }}+ >+ <strong>{datum.data.label}</strong> — {datum.value}h+ </div>+ )}+ />+ )}+ <div+ 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">+ {totalHours}h+ </span>+ <span className="text-xs text-muted-foreground tabular-nums">+ {jobsApplied} {jobsApplied === 1 ? "job" : "jobs"}+ </span>+ </div>+ </div>++ <div+ className="flex w-full min-w-0 flex-col gap-2.5"+ data-testid="jobs-activity-legend"+ >+ {slices.length === 0 ? (+ <p className="text-sm text-muted-foreground">+ No activities recorded+ </p>+ ) : (+ slices.map((slice) => (+ <div+ key={slice.id}+ className="flex min-w-0 items-center gap-2.5 text-sm"+ >+ <span+ className="h-2.5 w-2.5 shrink-0 rounded-sm"+ style={{ backgroundColor: slice.color }}+ />+ <span+ className={cn(+ "min-w-0 truncate",+ slice.id === OTHER_SLICE_ID && "text-muted-foreground",+ )}+ >+ {slice.label}+ </span>+ <span+ className={cn(+ "ml-auto shrink-0 font-semibold tabular-nums",+ slice.id === OTHER_SLICE_ID && "text-muted-foreground",+ )}+ >+ {slice.value}h+ </span>+ </div>+ ))+ )}+ </div>+ </div>+ </CardContent>+ </Card>+ );+}diff --git a/src/components/dashboard/NumberCardToggle.tsx b/src/components/dashboard/NumberCardToggle.tsxdeleted file mode 100644index 4f1644c..0000000--- a/src/components/dashboard/NumberCardToggle.tsx+++ /dev/null@@ -1,79 +0,0 @@-"use client";--import { useState } from "react";-import {- Card,- CardContent,- CardFooter,- CardHeader,- CardTitle,-} from "@/components/ui/card";-import { Progress } from "@/components/ui/progress";-import { TrendingDown, TrendingUp } from "lucide-react";-import { cn } from "@/lib/utils";--interface NumberCardToggleProps {- data: {- label: string;- num: number;- trend: number;- }[];-}--export default function NumberCardToggle({ data }: NumberCardToggleProps) {- const [activeIndex, setActiveIndex] = useState(0);- const current = data[activeIndex];-- return (- <Card>- <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">- Jobs- </CardTitle>- <div- className="flex shrink-0 rounded-md border text-xs"- data-testid="number-card-toggle-group"- >- {data.map((item, index) => (- <button- key={item.label}- onClick={() => setActiveIndex(index)}- className={cn(- "px-2 py-1 transition-colors",- index === 0 && "rounded-l-md",- index === data.length - 1 && "rounded-r-md",- activeIndex === index- ? "bg-primary text-primary-foreground"- : "hover:bg-muted",- )}- >- {item.label.replace("Last ", "")}- </button>- ))}- </div>- </div>- <CardTitle className="text-4xl">- {current.num}{" "}- <span className="text-xs text-muted-foreground">Jobs Applied</span>- </CardTitle>- </CardHeader>- <CardContent>- <div className="flex gap-2 text-xs text-muted-foreground">- {current.trend}%{" "}- {current.trend > 0 ? (- <TrendingUp className="h-4 w-4" />- ) : (- <TrendingDown className="h-4 w-4" />- )}- </div>- </CardContent>- <CardFooter>- <Progress- value={current.trend}- aria-label={`${current.trend}% increase`}- />- </CardFooter>- </Card>- );-}diff --git a/src/components/dashboard/TopActivitiesCard.tsx b/src/components/dashboard/TopActivitiesCard.tsxdeleted file mode 100644index 073346a..0000000--- a/src/components/dashboard/TopActivitiesCard.tsx+++ /dev/null@@ -1,76 +0,0 @@-"use client";--import { useState } from "react";-import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";-import { cn } from "@/lib/utils";-import { TopActivityType } from "@/actions/dashboard.actions";--interface TopActivitiesCardProps {- data: {- label: string;- activities: TopActivityType[];- }[];-}--export default function TopActivitiesCard({ data }: TopActivitiesCardProps) {- const [activeIndex, setActiveIndex] = useState(0);- const current = data[activeIndex];-- return (- <Card>- <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">- Activities- </CardTitle>- <div- className="flex shrink-0 rounded-md border text-xs"- data-testid="top-activities-toggle-group"- >- {data.map((item, index) => (- <button- key={item.label}- onClick={() => setActiveIndex(index)}- className={cn(- "px-2 py-1 transition-colors",- index === 0 && "rounded-l-md",- index === data.length - 1 && "rounded-r-md",- activeIndex === index- ? "bg-primary text-primary-foreground"- : "hover:bg-muted",- )}- >- {item.label.replace("Last ", "")}- </button>- ))}- </div>- </div>- </CardHeader>- <CardContent>- {current.activities.length === 0 ? (- <p className="text-sm text-muted-foreground">- No activities recorded- </p>- ) : (- <div className="space-y-3">- {current.activities.map((activity, index) => (- <div key={activity.label} className="flex items-center gap-3 min-w-0">- <div className="flex-1 min-w-0">- <p className="text-sm font-medium truncate">- {activity.label}- </p>- <p className="text-xs text-muted-foreground tabular-nums xl:hidden">- {activity.hours}h- </p>- </div>- <span className="hidden xl:block text-sm font-semibold tabular-nums shrink-0">- {activity.hours}h- </span>- </div>- ))}- </div>- )}- </CardContent>- </Card>- );-}diff --git a/src/components/dashboard/jobsActivityChart.ts b/src/components/dashboard/jobsActivityChart.tsnew file mode 100644index 0000000..11324ef--- /dev/null+++ b/src/components/dashboard/jobsActivityChart.ts@@ -0,0 +1,48 @@+import { TopActivityType } from "@/actions/dashboard.actions";++// Donut hues, validated for colorblind separation against each theme's+// card surface. The app's own --chart-* tokens fail that check here:+// light --chart-3 (#274754) reads as near-black grey in a donut.+const SERIES_COLORS = {+ light: ["#2a9d90", "#c97e22", "#6d4fc7"],+ dark: ["#16a89a", "#c08438", "#8b72e8"],+} as const;++const OTHER_COLOR = { light: "#94a3b8", dark: "#64748b" } as const;++export const OTHER_SLICE_ID = "__other__";++export interface DonutSlice {+ id: string;+ label: string;+ value: number;+ color: string;+}++// Hues are assigned by rank and never cycled, so a slice keeps its color+// for as long as the activity keeps its position.+export function buildDonutSlices(+ topActivities: TopActivityType[],+ otherHours: number,+ theme: "light" | "dark",+): DonutSlice[] {+ const slices: DonutSlice[] = topActivities+ .filter((activity) => activity.hours > 0)+ .map((activity, index) => ({+ id: activity.label,+ label: activity.label,+ value: activity.hours,+ color: SERIES_COLORS[theme][index],+ }));++ if (otherHours > 0) {+ slices.push({+ id: OTHER_SLICE_ID,+ label: "Other",+ value: otherHours,+ color: OTHER_COLOR[theme],+ });+ }++ return slices;+}diff --git a/src/lib/constants.ts b/src/lib/constants.tsindex 39607b7..cd64189 100644--- a/src/lib/constants.ts+++ b/src/lib/constants.ts@@ -35,6 +35,7 @@ export const APP_CONSTANTS = {SIDEBAR_STORAGE_KEY: "sidebar-expanded",DASHBOARD_WEEKLY_CHART_STORAGE_KEY: "dashboard-weekly-chart-tab",DASHBOARD_RECENT_CARD_STORAGE_KEY: "dashboard-recent-card-tab",+ DASHBOARD_JOBS_ACTIVITY_STORAGE_KEY: "dashboard-jobs-activity-tab",LAST_JOB_LOCATION_STORAGE_KEY: "last-job-location",LAST_JOB_SOURCE_STORAGE_KEY: "last-job-source",JOBS_VIEW_MODE_STORAGE_KEY: "jobs-view-mode",