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: enhance AgentChat functionality with panel expansion and sidebar integration
Khuram Niaz7329b02aca51
diff --git a/__tests__/AgentChatProvider.spec.tsx b/__tests__/AgentChatProvider.spec.tsxindex e344fb2..7fa30e5 100644--- a/__tests__/AgentChatProvider.spec.tsx+++ b/__tests__/AgentChatProvider.spec.tsx@@ -20,9 +20,10 @@ vi.mock("@ai-sdk/react", () => ({const chatInit = (call = 0) => useChatSpy.mock.calls[call][0] as any;const refresh = vi.fn();+let currentPathname = "/dashboard/myjobs";vi.mock("next/navigation", () => ({useRouter: () => ({ refresh }),- usePathname: () => "/dashboard/myjobs",+ usePathname: () => currentPathname,}));vi.mock("@/actions/agentChat.actions", () => ({@@ -57,29 +58,33 @@ import { saveResumeReviewResult } from "@/actions/profile.actions";function Probe() {const c = useAgentChat();const { holder } = useRightRail();- const { expanded } = useSidebar();+ const { expanded, toggle } = useSidebar();return (<div><button onClick={c.open}>open</button><button onClick={c.close}>close</button><button onClick={c.clear}>clear</button>+ <button onClick={c.togglePanelExpand}>togglePanelExpand</button>+ <button onClick={toggle}>toggleSidebar</button><span data-testid="sidebar">{String(expanded)}</span><span data-testid="state">{`${c.isOpen}|${c.approvalPending}|${c.interruptedTurn}|${holder}|${c.preflight.ok}`}</span><span data-testid="composer-nonce">{c.composerNonce}</span>+ <span data-testid="panel-expanded">{String(c.isPanelExpanded)}</span></div>);}-const setup = (initialMessages: any[] = []) =>- render(- <SidebarProvider initialExpanded>- <RightRailProvider>- <AgentChatProvider initialMessages={initialMessages}>- <Probe />- </AgentChatProvider>- </RightRailProvider>- </SidebarProvider>,- );+const tree = (initialMessages: any[] = []) => (+ <SidebarProvider initialExpanded>+ <RightRailProvider>+ <AgentChatProvider initialMessages={initialMessages}>+ <Probe />+ </AgentChatProvider>+ </RightRailProvider>+ </SidebarProvider>+);++const setup = (initialMessages: any[] = []) => render(tree(initialMessages));const reviewMessage = {id: "a2",@@ -134,6 +139,7 @@ describe("AgentChatProvider", () => {chat.messages = [];chat.status = "ready";chat.error = undefined;+ currentPathname = "/dashboard/myjobs";});it("seeds useChat with the persisted transcript", () => {@@ -307,6 +313,28 @@ describe("AgentChatProvider", () => {});expect(saveResumeReviewResult).not.toHaveBeenCalled();});++ it("restores an expanded panel when the sidebar re-expands", async () => {+ setup();+ await userEvent.click(screen.getByText("open"));+ await userEvent.click(screen.getByText("togglePanelExpand"));+ expect(screen.getByTestId("panel-expanded").textContent).toBe("true");+ await userEvent.click(screen.getByText("toggleSidebar"));+ expect(screen.getByTestId("panel-expanded").textContent).toBe("false");+ });++ // The docked-flush width only makes sense on the page it was expanded on;+ // navigating away (e.g. clicking Dashboard/Jobs in the sidebar) leaves the+ // sidebar collapsed, so only a pathname change can catch this case.+ it("restores an expanded panel when the page navigates to a different route", async () => {+ const { rerender } = setup();+ await userEvent.click(screen.getByText("open"));+ await userEvent.click(screen.getByText("togglePanelExpand"));+ expect(screen.getByTestId("panel-expanded").textContent).toBe("true");+ currentPathname = "/dashboard/jobs";+ rerender(tree());+ expect(screen.getByTestId("panel-expanded").textContent).toBe("false");+ });});describe("pageContextFor", () => {diff --git a/src/components/SidebarInset.tsx b/src/components/SidebarInset.tsxindex 7fa62e3..46a0270 100644--- a/src/components/SidebarInset.tsx+++ b/src/components/SidebarInset.tsx@@ -29,7 +29,9 @@ function SidebarInset({ children }: { children: React.ReactNode }) {style={isOpen? ({- "--agent-chat-offset": `min(${panelWidth}px, ${APP_CONSTANTS.RESIZABLE_PANEL_MAX_WIDTH_RATIO * 100}vw)`,+ // 100vw, not the drag-resize ratio cap: expanding docks the+ // panel flush against the sidebar, which can exceed that ratio.+ "--agent-chat-offset": `min(${panelWidth}px, 100vw)`,} as React.CSSProperties): undefined}diff --git a/src/components/agent/AgentChatPanel.tsx b/src/components/agent/AgentChatPanel.tsxindex 2774626..fd8e452 100644--- a/src/components/agent/AgentChatPanel.tsx+++ b/src/components/agent/AgentChatPanel.tsx@@ -1,13 +1,12 @@"use client";-import { X } from "lucide-react";+import { Scan, X } from "lucide-react";import { Sheet, SheetContent, SheetTitle } from "@/components/ui/sheet";import { Button } from "@/components/ui/button";import { AgentChatEmptyState } from "@/components/agent/AgentChatEmptyState";import { AgentChatInput } from "@/components/agent/AgentChatInput";import { AgentChatMessages } from "@/components/agent/AgentChatMessages";import { useAgentChat } from "@/components/agent/AgentChatProvider";-import { APP_CONSTANTS } from "@/lib/constants";export function AgentChatPanel() {const {@@ -17,6 +16,8 @@ export function AgentChatPanel() {messages,panelWidth: width,startResize,+ isPanelExpanded,+ togglePanelExpand,} = useAgentChat();return (@@ -38,7 +39,9 @@ export function AgentChatPanel() {style={{"--agent-chat-w": `${width}px`,- "--agent-chat-max": `${APP_CONSTANTS.RESIZABLE_PANEL_MAX_WIDTH_RATIO * 100}vw`,+ // 100vw, not the drag-resize ratio cap: expanding docks the panel+ // flush against the sidebar, which can exceed that ratio.+ "--agent-chat-max": "100vw",} as React.CSSProperties}>@@ -67,6 +70,15 @@ export function AgentChatPanel() {>Clear</Button>+ <Button+ aria-label={isPanelExpanded ? "Restore panel" : "Expand panel"}+ className="h-6 w-6 shrink-0 rounded-sm opacity-70 hover:opacity-100 hidden lg:inline-flex"+ onClick={togglePanelExpand}+ size="icon"+ variant="ghost"+ >+ <Scan className="h-3.5 w-3.5" />+ </Button><Buttonaria-label="Close chat"className="h-6 w-6 shrink-0 rounded-sm opacity-70 hover:opacity-100"diff --git a/src/components/agent/AgentChatProvider.tsx b/src/components/agent/AgentChatProvider.tsxindex 9e7a7cb..ac17672 100644--- a/src/components/agent/AgentChatProvider.tsx+++ b/src/components/agent/AgentChatProvider.tsx@@ -61,7 +61,7 @@ function useAgentChatValue(initialMessages: UIMessage[]) {const router = useRouter();const pathname = usePathname();const { holder, requestOpen, close: releaseRail } = useRightRail();- const { collapse: collapseSidebar } = useSidebar();+ const { expanded: sidebarExpanded, collapse: collapseSidebar } = useSidebar();const [isOpen, setIsOpen] = useState(false);// Lives here, not in the panel: SidebarInset offsets page content by this@@ -72,7 +72,20 @@ function useAgentChatValue(initialMessages: UIMessage[]) {width: panelWidth,handleMouseDown: startResize,isDragging: isResizing,+ isExpanded: isPanelExpanded,+ toggleExpand: togglePanelExpand,} = useResizablePanel(APP_CONSTANTS.AGENT_CHAT_PANEL_WIDTH_KEY);++ // The maximized width only makes sense on the page it was expanded on: if+ // the sidebar re-expands it would overlap, and navigating away (sidebar nav+ // links leave the sidebar collapsed) leaves it flush against a new page.+ const lastPathnameRef = useRef(pathname);+ useEffect(() => {+ const navigated = lastPathnameRef.current !== pathname;+ lastPathnameRef.current = pathname;+ if (isPanelExpanded && (sidebarExpanded || navigated)) togglePanelExpand();+ }, [sidebarExpanded, isPanelExpanded, pathname, togglePanelExpand]);+const [interruptedTurn, setInterruptedTurn] = useState(false);const [preflight, setPreflight] = useState<Preflight>({checked: false,@@ -257,6 +270,8 @@ function useAgentChatValue(initialMessages: UIMessage[]) {panelWidth,startResize,isResizing,+ isPanelExpanded,+ togglePanelExpand,};}diff --git a/src/hooks/useResizablePanel.ts b/src/hooks/useResizablePanel.tsindex f7d004b..aa98646 100644--- a/src/hooks/useResizablePanel.ts+++ b/src/hooks/useResizablePanel.ts@@ -15,6 +15,8 @@ export function useResizablePanel(storageKey: string) {const isDragging = useRef(false);// Mirrored into state so consumers can suppress width transitions mid-drag.const [dragging, setDragging] = useState(false);+ // Manual dragging always takes control back from the expand toggle.+ const [isExpanded, setIsExpanded] = useState(false);const startX = useRef(0);const startWidth = useRef(0);const widthRef = useRef(width);@@ -26,6 +28,7 @@ export function useResizablePanel(storageKey: string) {const handleMouseDown = useCallback((e: React.MouseEvent) => {isDragging.current = true;setDragging(true);+ setIsExpanded(false);startX.current = e.clientX;startWidth.current = widthRef.current;document.body.style.userSelect = "none";@@ -33,6 +36,21 @@ export function useResizablePanel(storageKey: string) {e.preventDefault();}, []);+ const toggleExpand = useCallback(() => {+ let next: number;+ if (isExpanded) {+ next = DEFAULT_WIDTH;+ } else {+ const sidebarWidth =+ document.getElementById(APP_CONSTANTS.SIDEBAR_DOM_ID)?.offsetWidth ?? 0;+ next = window.innerWidth - sidebarWidth;+ }+ widthRef.current = next;+ setWidth(next);+ setIsExpanded(!isExpanded);+ saveToLocalStorage(storageKey, next);+ }, [isExpanded, storageKey]);+useEffect(() => {const onMouseMove = (e: MouseEvent) => {if (!isDragging.current) return;@@ -60,5 +78,5 @@ export function useResizablePanel(storageKey: string) {};}, [storageKey]);- return { width, handleMouseDown, isDragging: dragging };+ return { width, handleMouseDown, isDragging: dragging, isExpanded, toggleExpand };}