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
fix(myjobs): gate the Match and Cover Letter actions on chat busy, and reload the jobs list when a match score lands
Khuram Niaz4b1549856ae2
diff --git a/__tests__/JobCard.spec.tsx b/__tests__/JobCard.spec.tsxindex 837fb27..4e7fc2d 100644--- a/__tests__/JobCard.spec.tsx+++ b/__tests__/JobCard.spec.tsx@@ -6,6 +6,11 @@ vi.mock("next/navigation", () => ({useRouter: () => ({ push: vi.fn() }),}));+const chat = { busy: false };+vi.mock("@/components/agent/AgentChatProvider", () => ({+ useAgentChat: () => chat,+}));+const mockStatuses: JobStatus[] = [{ id: "1", label: "Applied", value: "applied" },{ id: "2", label: "Interview", value: "interview" },diff --git a/__tests__/MyJobsGrid.spec.tsx b/__tests__/MyJobsGrid.spec.tsxindex 1bad55f..11e1312 100644--- a/__tests__/MyJobsGrid.spec.tsx+++ b/__tests__/MyJobsGrid.spec.tsx@@ -7,6 +7,10 @@ vi.mock("next/navigation", () => ({useRouter: () => ({ push: vi.fn() }),}));+vi.mock("@/components/agent/AgentChatProvider", () => ({+ useAgentChat: () => ({ busy: false }),+}));+const mockStatuses: JobStatus[] = [{ id: "1", label: "Applied", value: "applied" },{ id: "2", label: "Interview", value: "interview" },diff --git a/__tests__/MyJobsTable.spec.tsx b/__tests__/MyJobsTable.spec.tsxindex 1d0e2b0..3c9b321 100644--- a/__tests__/MyJobsTable.spec.tsx+++ b/__tests__/MyJobsTable.spec.tsx@@ -8,6 +8,11 @@ vi.mock("next/navigation", () => ({useRouter: () => ({ push: mockPush }),}));+const chat = { busy: false };+vi.mock("@/components/agent/AgentChatProvider", () => ({+ useAgentChat: () => chat,+}));+window.HTMLElement.prototype.scrollIntoView = vi.fn();window.HTMLElement.prototype.hasPointerCapture = vi.fn();window.HTMLElement.prototype.releasePointerCapture = vi.fn();@@ -117,6 +122,19 @@ describe("MyJobsTable", () => {);});+ it("disables the Match button while the assistant is busy", () => {+ chat.busy = true;+ try {+ renderTable([makeJob({ matchScore: null })]);+ expect(+ screen.queryByRole("link", { name: /match/i }),+ ).not.toBeInTheDocument();+ expect(screen.getByRole("button", { name: /match/i })).toBeDisabled();+ } finally {+ chat.busy = false;+ }+ });+it("shows a notes count badge only when the job has notes", () => {const { rerender } = renderTable([makeJob({ _count: { Notes: 3 } })]);expect(screen.getByText("3")).toBeInTheDocument();diff --git a/src/components/agent/AgentChatProvider.tsx b/src/components/agent/AgentChatProvider.tsxindex b624789..c505dfb 100644--- a/src/components/agent/AgentChatProvider.tsx+++ b/src/components/agent/AgentChatProvider.tsx@@ -17,6 +17,7 @@ import {getToolName,isToolUIPart,lastAssistantMessageIsCompleteWithApprovalResponses,+ type ToolUIPart,type UIMessage,} from "ai";import { hasPendingApproval, stubConsumedPastes } from "@/lib/agent/paste";@@ -120,8 +121,9 @@ function useAgentChatValue(initialMessages: UIMessage[]) {// keyed by toolCallId so two nested calls cannot collide.const [toolStreams, setToolStreams] = useState<Record<string, string>>({});- // The jobs list is client state loaded by a server action, so router.refresh- // cannot reach it — pages that hold their own rows subscribe to this counter.+ // Job rows changed server-side. The jobs list is client state loaded by a+ // server action, so router.refresh cannot reach it — pages that hold their+ // own rows subscribe to this counter.const [jobWrites, setJobWrites] = useState(0);// Which writes have already been announced. Seeded from the persisted@@ -156,13 +158,18 @@ function useAgentChatValue(initialMessages: UIMessage[]) {const finishedParts = message?.parts ?? [];const wrote = createdJobToolCallIds(message ? [message] : []).length > 0;+ const finishedTools = finishedParts+ .filter((part) => isToolUIPart(part) && part.state === "output-available")+ .map((part) => getToolName(part as ToolUIPart));// Any nested tool that saves server-side leaves the page behind the// panel stale — the saved review card, the job's match score, or the// job's cover-letter button flipping to "Regenerate Letter".- const generated = finishedParts.some((part) => {- if (!isToolUIPart(part) || part.state !== "output-available") return false;- return isNestedTool(getToolName(part));- });+ const generated = finishedTools.some(isNestedTool);+ // The score it just saved sits in a JOB row, which a jobs list holding+ // its own rows can only pick up from the counter. review_resume writes+ // to the resume and the list renders no cover-letter state, so neither+ // of the other two nested tools belongs here.+ const scored = finishedTools.includes("match_job");// The route stubs the paste on its way into the DB, but that copy is// not the one the client POSTs next turn — so without this the browser@@ -179,6 +186,7 @@ function useAgentChatValue(initialMessages: UIMessage[]) {// is a wasted request, not a bug; a stale saved review or match score// right after watching one land reads as one.if (generated) router.refresh();+ if (scored) setJobWrites((n) => n + 1);},});@@ -370,10 +378,16 @@ function useAgentChatValue(initialMessages: UIMessage[]) {const dismissInterrupted = useCallback(() => setInterruptedTurn(false), []);+ // A turn in flight, or one parked on an approval. Read by every surface+ // that starts a chat from outside the panel, so a second one cannot clear+ // the conversation the first is still streaming into.+ const busy = streamingRef.current || approvalPending;+return {isOpen,open,close,+ busy,messages: chat.messages,toolStreams,jobWrites,diff --git a/src/components/myjobs/JobDetails.tsx b/src/components/myjobs/JobDetails.tsxindex f5e3d19..bf75167 100644--- a/src/components/myjobs/JobDetails.tsx+++ b/src/components/myjobs/JobDetails.tsx@@ -66,6 +66,7 @@ function JobDetails({clear: clearChat,sendMessage,approvalPending,+ busy: chatBusy,} = useAgentChat();const [showClearChatConfirm, setShowClearChatConfirm] = useState(false);const [pendingChatMessage, setPendingChatMessage] = useState("");@@ -126,10 +127,14 @@ function JobDetails({useAutoMatch(onMatch);+ // Doubles as the busy gate: the header button, the empty state and+ // Regenerate all key on this one reason.const coverLetterBlockedReason =job.descriptionCompleteness === "title-only"? "Add a job description first"- : undefined;+ : chatBusy+ ? "The assistant is busy"+ : undefined;const onEditJob = () => {setEditJobTarget({ ...job, Status: currentStatus });@@ -170,6 +175,7 @@ function JobDetails({jobStatuses={jobStatuses}currentStatus={currentStatus}coverLetterBlockedReason={coverLetterBlockedReason}+ chatBusy={chatBusy}onBack={goBack}onMatch={onMatch}onCoverLetter={onCoverLetter}@@ -215,6 +221,8 @@ function JobDetails({description="Run an AI match to see how your resume lines up with this posting, and where the gaps are."actionLabel="Match with AI"onAction={onMatch}+ actionDisabled={chatBusy}+ actionTitle={chatBusy ? "The assistant is busy" : undefined}/>)}</Card>diff --git a/src/components/myjobs/MatchJobButton.tsx b/src/components/myjobs/MatchJobButton.tsxindex fb2012c..575ae95 100644--- a/src/components/myjobs/MatchJobButton.tsx+++ b/src/components/myjobs/MatchJobButton.tsx@@ -2,10 +2,30 @@import Link from "next/link";import { Sparkles } from "lucide-react";import { Button } from "../ui/button";+import { useAgentChat } from "@/components/agent/AgentChatProvider";// Shown in place of the score when a job has none. The match flag is read by// useAutoMatch on the details page, which fires the AI match on arrival.export function MatchJobButton({ jobId }: { jobId: string }) {+ const { busy } = useAgentChat();++ // One shared conversation: a second match would clear the running one, so+ // the link is swapped for a dead button rather than left navigable.+ if (busy) {+ return (+ <Button+ size="sm"+ variant="outline"+ className="shrink-0"+ disabled+ title="The assistant is busy"+ >+ <Sparkles className="h-3.5 w-3.5 mr-1" />+ Match+ </Button>+ );+ }+return (<Button asChild size="sm" variant="outline" className="shrink-0"><Link href={`/dashboard/myjobs/${jobId}?tab=match&match=1`}>diff --git a/src/components/myjobs/job-details/JobDetailsHeader.tsx b/src/components/myjobs/job-details/JobDetailsHeader.tsxindex c1a2d67..ed5e3eb 100644--- a/src/components/myjobs/job-details/JobDetailsHeader.tsx+++ b/src/components/myjobs/job-details/JobDetailsHeader.tsx@@ -39,6 +39,7 @@ type JobDetailsHeaderProps = {jobStatuses: JobStatus[];currentStatus: JobStatus;coverLetterBlockedReason?: string;+ chatBusy: boolean;onBack: () => void;onMatch: () => void;onCoverLetter: () => void;@@ -53,6 +54,7 @@ export function JobDetailsHeader({jobStatuses,currentStatus,coverLetterBlockedReason,+ chatBusy,onBack,onMatch,onCoverLetter,@@ -86,7 +88,13 @@ export function JobDetailsHeader({</div></div><div className="flex flex-wrap justify-end gap-2">- <Button variant="outline" className="cursor-pointer" onClick={onMatch}>+ <Button+ variant="outline"+ className="cursor-pointer"+ disabled={chatBusy}+ title={chatBusy ? "The assistant is busy" : undefined}+ onClick={onMatch}+ ><Sparkles className="h-4 w-4 sm:mr-2" /><span className="sr-only sm:not-sr-only sm:whitespace-nowrap">Match with AIdiff --git a/src/components/myjobs/jobs-container/useJobsList.ts b/src/components/myjobs/jobs-container/useJobsList.tsindex 1664bb8..34a3c4b 100644--- a/src/components/myjobs/jobs-container/useJobsList.ts+++ b/src/components/myjobs/jobs-container/useJobsList.ts@@ -11,7 +11,7 @@ import {import { useAgentChat } from "@/components/agent/AgentChatProvider";// Owns the job list itself: pagination, search, view mode, infinite scroll,-// and the reload triggered when the agent chat writes a new job.+// and the reload triggered when the agent chat writes job data.export function useJobsList({companyFilter,appliedFilter,@@ -100,9 +100,9 @@ export function useJobsList({(async () => await loadJobs(1))();}, [loadJobs]);- // The agent saves the job server-side, so only this counter tells us a row- // appeared. Deps are the counter alone: reloadJobs changes with every filter- // and keystroke, and the effects above already cover those.+ // The agent saves server-side, so only this counter tells us a row appeared+ // or a match score landed. Deps are the counter alone: reloadJobs changes+ // with every filter and keystroke, and the effects above already cover those.useEffect(() => {if (jobWrites === 0) return;void reloadJobs();