AI media harness for planning, generating, and editing locally
TypeScript
Cap the agent pane at a third of the window; hide the empty library heading
Bittif67ea3070a33
diff --git a/src/App.test.tsx b/src/App.test.tsxindex df84447..8799042 100644--- a/src/App.test.tsx+++ b/src/App.test.tsx@@ -7,6 +7,7 @@ import App from "./App";import { ProjectCard, relativeDate } from "./components/ProjectCard";import { chooseOption, comboValue, optionNames } from "./components/workspace/comboTestUtils";import { installBrowserGuards } from "./lib/nativeShell";+import { agentPaneMax } from "./components/ProjectWorkspace";import { createProjectConfig, STORY_TRACK_ID } from "./lib/project";describe("how long ago a project was edited", () => {@@ -269,6 +270,14 @@ describe("project library controls", () => {expect(screen.getByRole("button", { name: "Agent" })).toHaveFocus();});+ it("keeps the agent pane to about a third of the window", () => {+ // At the 900px window minimum the 360px default would take 40% of it.+ expect(agentPaneMax(900)).toBe(315);+ expect(agentPaneMax(1600)).toBe(560);+ expect(agentPaneMax(2560)).toBe(640);+ expect(agentPaneMax(600)).toBe(280);+ });+it("creates an empty project when the new-project form is left blank", async () => {render(<App />);await screen.findByText("Northern Light — Brand Film");diff --git a/src/App.tsx b/src/App.tsxindex a07dbb1..88364c9 100644--- a/src/App.tsx+++ b/src/App.tsx@@ -191,6 +191,8 @@ function App() {);}, [projects, query]);+ const showLibraryHeading = projects.length > 0;+const openProject = (project: ProjectRecord, view: ProjectView = "timeline") => {setWorkQueueOpen(false);setSelectedKey(projectQueueKey(project));@@ -320,7 +322,7 @@ function App() {The screen behind it stays mounted and hidden, so an open project keepsits unsaved edits, the agent its draft, and the library its search. */const settingsPage = settingsOpen ? (- <div className="app-screen app-screen--settings">+ <div className="app-screen"><TitleBar title="Settings" actions={queueTrigger(settingsQueueButton)} /><div className="app-screen__content"><SettingsView onClose={closeSettings} updates={updatePanel} initialTab={settingsInitialTab} />@@ -418,10 +420,12 @@ function App() {<CommandBarButton icon={<List size={16} />} label="List view" pressed={projectLayout === "list"} onClick={() => setProjectLayout("list")} /></CommandBar>- <section className="library__section" aria-labelledby="all-projects-heading">- <h2 id="all-projects-heading" className="library__subtitle">+ {/* An empty library says so in its empty state; a heading counting+ "0 projects" above it would only repeat that. */}+ <section className="library__section" {...(showLibraryHeading ? { "aria-labelledby": "all-projects-heading" } : { "aria-label": "All projects" })}>+ {showLibraryHeading && <h2 id="all-projects-heading" className="library__subtitle">{query.trim() ? "Results" : "All projects"} <span className="library__count">{filteredProjects.length} {filteredProjects.length === 1 ? "project" : "projects"}</span>- </h2>+ </h2>}{loading ? (<div className={`project-grid project-grid--${projectLayout}`} aria-busy="true">{[0, 1, 2].map((item) => <div className="project-skeleton" key={item}><i /><span /><small /></div>)}</div>) : filteredProjects.length ? (diff --git a/src/WorkQueue.integration.test.tsx b/src/WorkQueue.integration.test.tsxindex 36b7466..483011a 100644--- a/src/WorkQueue.integration.test.tsx+++ b/src/WorkQueue.integration.test.tsx@@ -106,6 +106,10 @@ it("keeps the application queue alive while switching projects and saves resultsit("opens an empty queue from the library and closes it with Escape", async () => {vi.mocked(listRecentProjects).mockResolvedValue({ projects: [], unreadable: [] });render(<App />);+ // An empty library shows its empty state without a "0 projects" heading over it.+ expect(await screen.findByRole("heading", { name: "No projects yet" })).toBeInTheDocument();+ expect(screen.queryByRole("heading", { name: /All projects/ })).toBeNull();+ expect(screen.getByRole("region", { name: "All projects" })).toBeInTheDocument();const trigger = screen.getByRole("button", { name: "Work queue" });trigger.focus(); fireEvent.click(trigger);const flyout = screen.getByRole("dialog", { name: "Work queue" });diff --git a/src/components/ProjectWorkspace.tsx b/src/components/ProjectWorkspace.tsxindex 2f62129..b369502 100644--- a/src/components/ProjectWorkspace.tsx+++ b/src/components/ProjectWorkspace.tsx@@ -47,6 +47,22 @@ const VIEW_LABELS: Record<ShownView, string> = {timeline: "Timeline", generator: "Generator", references: "References", export: "Export", editor: "Editor",};+const AGENT_PANE_MIN = 280;+const AGENT_PANE_MAX = 640;+/** The widest the agent pane may be in a window this wide: 35% of it. */+export const agentPaneMax = (windowWidth: number) =>+ Math.max(AGENT_PANE_MIN, Math.min(AGENT_PANE_MAX, Math.round(windowWidth * 0.35)));++function useWindowWidth(): number {+ const [width, setWidth] = useState(() => (typeof window === "undefined" ? 1280 : window.innerWidth));+ useEffect(() => {+ const onResize = () => setWidth(window.innerWidth);+ window.addEventListener("resize", onResize);+ return () => window.removeEventListener("resize", onResize);+ }, []);+ return width;+}+/* The project window.[←] [icon] Project name Timeline Generator References Export [↶][↷] [Save] [Agent][Queue][⚙] [– □ ×]@@ -103,7 +119,13 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =});const [agentOpen, setAgentOpenState] = useState(() => initialView === "agent" || readAgentPane());const setAgentOpen = (open: boolean) => { setAgentOpenState(open); writeAgentPane(open); };- const agentPane = usePaneSize("workspace.agent", 360, { min: 280, max: 640 });+ /* 360px is a comfortable conversation column, but at the 900px window+ minimum it would take 40% of the width from the editor. The pane gives+ way instead: never more than about a third of the window (and never+ under 280px). A wider size the user dragged to comes back as the window+ grows. */+ const windowWidth = useWindowWidth();+ const agentPane = usePaneSize("workspace.agent", 360, { min: AGENT_PANE_MIN, max: agentPaneMax(windowWidth) });const agentPaneRef = useRef<HTMLElement>(null);const agentToggle = useRef<HTMLButtonElement>(null);const [leaving, setLeaving] = useState(false);diff --git a/src/components/ui/Layout.test.tsx b/src/components/ui/Layout.test.tsxindex b95a915..9baa895 100644--- a/src/components/ui/Layout.test.tsx+++ b/src/components/ui/Layout.test.tsx@@ -79,6 +79,21 @@ describe("Splitter + usePaneSize", () => {expect(separator).toHaveAttribute("aria-valuenow", "358");});+ it("follows a moving maximum without forgetting the size the user chose", () => {+ function Squeezed({ max }: { max: number }) {+ const pane = usePaneSize("test.agent", 360, { min: 280, max });+ return <div data-testid="grid" style={pane.style}><Splitter {...pane.splitterProps} aria-label="Resize agent" /></div>;+ }+ localStorage.setItem("slopus.pane.test.agent", "500");+ const view = render(<Squeezed max={315} />);+ expect(screen.getByTestId("grid").style.getPropertyValue("--pane-test-agent")).toBe("315px");+ expect(screen.getByRole("separator")).toHaveAttribute("aria-valuemax", "315");+ // The preference is kept: widen the window and the pane is 500 again.+ expect(localStorage.getItem("slopus.pane.test.agent")).toBe("500");+ view.rerender(<Squeezed max={640} />);+ expect(screen.getByTestId("grid").style.getPropertyValue("--pane-test-agent")).toBe("500px");+ });+it("survives unusable storage", () => {const get = vi.spyOn(Storage.prototype, "getItem").mockImplementation(() => { throw new Error("denied"); });const set = vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => { throw new Error("denied"); });diff --git a/src/components/ui/Splitter.tsx b/src/components/ui/Splitter.tsxindex 4254077..9cf5d68 100644--- a/src/components/ui/Splitter.tsx+++ b/src/components/ui/Splitter.tsx@@ -69,7 +69,7 @@ export function usePaneSize(key: string, defaultSize: number, options: PaneSizeOconst persist = options.persist !== false;const cssVar = options.cssVar ?? `--pane-${key.replace(/[^a-zA-Z0-9-]+/g, "-")}`;const clampSize = useCallback((value: number) => Math.round(Math.min(max, Math.max(min, value))), [min, max]);- const [size, setRaw] = useState(() => clampSize((persist ? readStored(key) : undefined) ?? defaultSize));+ const [size, setRaw] = useState(() => Math.round((persist ? readStored(key) : undefined) ?? defaultSize));useEffect(() => {if (!persist) return;@@ -78,17 +78,22 @@ export function usePaneSize(key: string, defaultSize: number, options: PaneSizeOconst setSize = useCallback((value: number) => setRaw(clampSize(value)), [clampSize]);const reset = useCallback(() => setRaw(clampSize(defaultSize)), [clampSize, defaultSize]);+ /* The limits may move (a max that follows the window width). What is shown+ is clamped to the limits of the moment; the stored preference is not+ touched, so a pane squeezed by a narrow window comes back to its size+ when the window grows again. */+ const shown = clampSize(size);return useMemo(() => ({- size,+ size: shown,setSize,reset,min,max,cssVar,- style: { [cssVar]: `${size}px` } as CSSProperties,- splitterProps: { value: size, min, max, onChange: setSize, onReset: reset },- }), [size, setSize, reset, min, max, cssVar]);+ style: { [cssVar]: `${shown}px` } as CSSProperties,+ splitterProps: { value: shown, min, max, onChange: setSize, onReset: reset },+ }), [shown, setSize, reset, min, max, cssVar]);}export interface SplitterProps extends SplitterValueProps {