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): add monthly goal summary maths and placeholder streaks
Khuram Niaz116181635358
diff --git a/__tests__/dailyGoals.spec.ts b/__tests__/dailyGoals.spec.tsindex e4df99a..fe5b133 100644--- a/__tests__/dailyGoals.spec.ts+++ b/__tests__/dailyGoals.spec.ts@@ -1,5 +1,8 @@+import { DAILY_GOALS } from "@/lib/constants";import {buildGoalValues,+ buildMonthSummary,+ formatDays,goalMonthRange,isValidMonth,monthBounds,@@ -74,4 +77,128 @@ describe("dailyGoals helpers", () => {).toEqual({});});});++ describe("formatDays", () => {+ it("uses the singular only for one", () => {+ expect(formatDays(0)).toBe("0 days");+ expect(formatDays(1)).toBe("1 day");+ expect(formatDays(12)).toBe("12 days");+ });+ });++ describe("buildMonthSummary", () => {+ const met = { jobs: 5, hours: 4 };+ const stat = (summary: ReturnType<typeof buildMonthSummary>, label: string) =>+ summary.stats?.find((s) => s.label === label)?.value;++ it("rates a past month over all its days", () => {+ const summary = buildMonthSummary(+ "2026-09",+ {+ "2026-09-01": met,+ "2026-09-02": { jobs: 5, hours: 1 },+ "2026-09-03": { jobs: 0, hours: 4 },+ },+ "2026-10-05",+ );+ expect(summary.rings).toEqual({ jobs: 2 / 30, hours: 2 / 30 });+ expect(stat(summary, "Both goals met")).toBe("1 day");+ expect(stat(summary, "Nothing logged")).toBe("27 days");+ });++ it("counts a goal exceeded as met and below target as not", () => {+ const summary = buildMonthSummary(+ "2026-09",+ { "2026-09-01": { jobs: 9, hours: 3.9 } },+ "2026-10-05",+ );+ expect(summary.rings).toEqual({ jobs: 1 / 30, hours: 0 });+ });++ it("ignores days after today", () => {+ const summary = buildMonthSummary(+ "2026-10",+ { "2026-10-01": met, "2026-10-20": met },+ "2026-10-05",+ );+ // Oct 1–4 past, today not met+ expect(summary.rings).toEqual({ jobs: 1 / 4, hours: 1 / 4 });+ expect(stat(summary, "Both goals met")).toBe("1 day");+ expect(stat(summary, "Nothing logged")).toBe("3 days");+ });++ it("counts today per ring only when met", () => {+ const summary = buildMonthSummary(+ "2026-10",+ { "2026-10-05": { jobs: 5, hours: 1 } },+ "2026-10-05",+ );+ expect(summary.rings).toEqual({ jobs: 1 / 5, hours: 0 / 4 });+ expect(stat(summary, "Both goals met")).toBe("0 days");+ });++ it("counts today in both goals met once both are met", () => {+ const summary = buildMonthSummary(+ "2026-10",+ { "2026-10-05": met },+ "2026-10-05",+ );+ expect(summary.rings).toEqual({ jobs: 1 / 5, hours: 1 / 5 });+ expect(stat(summary, "Both goals met")).toBe("1 day");+ });++ it("never counts today as nothing logged", () => {+ const summary = buildMonthSummary("2026-10", {}, "2026-10-05");+ expect(stat(summary, "Nothing logged")).toBe("4 days");+ });++ it("first of the month with nothing met has no ring values", () => {+ const summary = buildMonthSummary("2026-10", {}, "2026-10-01");+ expect(summary.rings).toEqual({});+ expect(stat(summary, "Both goals met")).toBe("0 days");+ expect(stat(summary, "Nothing logged")).toBe("0 days");+ });++ it("uses the real month length", () => {+ expect(+ stat(buildMonthSummary("2024-02", {}, "2026-10-05"), "Nothing logged"),+ ).toBe("29 days");+ expect(+ stat(buildMonthSummary("2026-02", {}, "2026-10-05"), "Nothing logged"),+ ).toBe("28 days");+ });++ it("shows real zeros for a loaded month with no records", () => {+ const summary = buildMonthSummary("2026-08", {}, "2026-10-05");+ expect(summary.rings).toEqual({ jobs: 0, hours: 0 });+ expect(stat(summary, "Nothing logged")).toBe("31 days");+ });++ it("treats a day with only zeros as nothing logged", () => {+ const summary = buildMonthSummary(+ "2026-09",+ { "2026-09-01": { jobs: 0, hours: 0 }, "2026-09-02": { jobs: 1, hours: 0 } },+ "2026-10-05",+ );+ expect(stat(summary, "Nothing logged")).toBe("29 days");+ });++ it("lists the four rows in order with placeholder streaks", () => {+ const summary = buildMonthSummary("2026-09", {}, "2026-10-05");+ expect(summary.stats).toEqual([+ {+ label: "Current streak",+ value: formatDays(DAILY_GOALS.PLACEHOLDER_STREAKS.CURRENT),+ tone: "primary",+ },+ {+ label: "Best streak",+ value: formatDays(DAILY_GOALS.PLACEHOLDER_STREAKS.BEST),+ tone: "warning",+ },+ { label: "Both goals met", value: "0 days", tone: "success" },+ { label: "Nothing logged", value: "30 days", tone: "danger" },+ ]);+ });+ });});diff --git a/src/lib/constants.ts b/src/lib/constants.tsindex 2707597..882dd65 100644--- a/src/lib/constants.ts+++ b/src/lib/constants.ts@@ -455,4 +455,6 @@ export const DAILY_GOALS = {HOURS_TARGET: 4,// Months browsable before the current oneMONTHS_BACK: 11,+ // Shown until streaks are computed across months+ PLACEHOLDER_STREAKS: { CURRENT: 3, BEST: 7 },} as const;diff --git a/src/lib/dailyGoals.ts b/src/lib/dailyGoals.tsindex ba3905b..56b48ad 100644--- a/src/lib/dailyGoals.ts+++ b/src/lib/dailyGoals.ts@@ -1,4 +1,5 @@import { format } from "date-fns";+import type { GcMonthSummaryProps } from "react-goal-calendar";import { DAILY_GOALS } from "@/lib/constants";// Directive-free: imported by the server action and the client calendar.@@ -64,3 +65,70 @@ export function buildGoalValues(}return values;}++export type MonthSummary = NonNullable<GcMonthSummaryProps["data"]>[string];++export function formatDays(count: number): string {+ return `${count} ${count === 1 ? "day" : "days"}`;+}++// Typed wide: ids come from Object.keys, which yields string+const TARGETS: Record<string, number> = {+ [GOAL_IDS.JOBS]: DAILY_GOALS.JOBS_TARGET,+ [GOAL_IDS.HOURS]: DAILY_GOALS.HOURS_TARGET,+};++export function buildMonthSummary(+ month: string,+ values: GoalValues,+ today: string,+): MonthSummary {+ const ids = Object.keys(TARGETS);+ const hit: Record<string, number> = {};+ const counted: Record<string, number> = {};+ let bothMet = 0;+ let nothingLogged = 0;++ const { end } = monthBounds(month);+ for (let d = 1; d <= end.getDate(); d++) {+ const key = `${month}-${String(d).padStart(2, "0")}`;+ if (key > today) break;+ const day = values[key] ?? {};+ const isMet = (id: string) => (day[id] ?? 0) >= TARGETS[id];+ // Today counts only once met, so an unfinished day never drags it down+ for (const id of ids) {+ if (key === today && !isMet(id)) continue;+ counted[id] = (counted[id] ?? 0) + 1;+ if (isMet(id)) hit[id] = (hit[id] ?? 0) + 1;+ }+ if (ids.every(isMet)) bothMet++;+ if (key < today && ids.every((id) => !day[id])) nothingLogged++;+ }++ const rings: Record<string, number> = {};+ for (const id of ids) {+ if (counted[id]) rings[id] = (hit[id] ?? 0) / counted[id];+ }++ return {+ rings,+ stats: [+ {+ label: "Current streak",+ value: formatDays(DAILY_GOALS.PLACEHOLDER_STREAKS.CURRENT),+ tone: "primary",+ },+ {+ label: "Best streak",+ value: formatDays(DAILY_GOALS.PLACEHOLDER_STREAKS.BEST),+ tone: "warning",+ },+ { label: "Both goals met", value: formatDays(bothMet), tone: "success" },+ {+ label: "Nothing logged",+ value: formatDays(nothingLogged),+ tone: "danger",+ },+ ],+ };+}