Skip to content

Commit 421bccc

Browse files
committed
feat: autofocus chat input in creation view
- Track creation chat input ref and focus on mount - Reuse derived project path for creation view rendering _Generated with `mux`_
1 parent 738a2c8 commit 421bccc

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/App.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useUnreadTracking } from "./hooks/useUnreadTracking";
1414
import { useAutoCompactContinue } from "./hooks/useAutoCompactContinue";
1515
import { useWorkspaceStoreRaw, useWorkspaceRecency } from "./stores/WorkspaceStore";
1616
import { ChatInput } from "./components/ChatInput/index";
17+
import type { ChatInputAPI } from "./components/ChatInput/types";
1718

1819
import { useStableReference, compareMaps } from "./hooks/useStableReference";
1920
import { CommandRegistryProvider, useCommandRegistry } from "./contexts/CommandRegistryContext";
@@ -55,12 +56,27 @@ function AppInner() {
5556
const isMobile = typeof window !== "undefined" && window.innerWidth <= 768;
5657
const [sidebarCollapsed, setSidebarCollapsed] = usePersistedState("sidebarCollapsed", isMobile);
5758
const defaultProjectPath = getFirstProjectPath(projects);
59+
const creationChatInputRef = useRef<ChatInputAPI | null>(null);
60+
const creationProjectPath = !selectedWorkspace
61+
? (pendingNewWorkspaceProject ?? (projects.size === 1 ? defaultProjectPath : null))
62+
: null;
63+
const handleCreationChatReady = useCallback((api: ChatInputAPI) => {
64+
creationChatInputRef.current = api;
65+
api.focus();
66+
}, []);
67+
5868
const startWorkspaceCreation = useStartWorkspaceCreation({
5969
projects,
6070
setPendingNewWorkspaceProject,
6171
setSelectedWorkspace,
6272
});
6373

74+
useEffect(() => {
75+
if (creationProjectPath) {
76+
creationChatInputRef.current?.focus();
77+
}
78+
}, [creationProjectPath]);
79+
6480
const handleToggleSidebar = useCallback(() => {
6581
setSidebarCollapsed((prev) => !prev);
6682
}, [setSidebarCollapsed]);
@@ -569,12 +585,9 @@ function AppInner() {
569585
}
570586
/>
571587
</ErrorBoundary>
572-
) : pendingNewWorkspaceProject || (projects.size === 1 && defaultProjectPath) ? (
588+
) : creationProjectPath ? (
573589
(() => {
574-
const projectPath = pendingNewWorkspaceProject ?? defaultProjectPath;
575-
if (!projectPath) {
576-
return null;
577-
}
590+
const projectPath = creationProjectPath;
578591
const projectName =
579592
projectPath.split("/").pop() ?? projectPath.split("\\").pop() ?? "Project";
580593
return (
@@ -584,6 +597,7 @@ function AppInner() {
584597
variant="creation"
585598
projectPath={projectPath}
586599
projectName={projectName}
600+
onReady={handleCreationChatReady}
587601
onWorkspaceCreated={(metadata) => {
588602
// Add to workspace metadata map
589603
setWorkspaceMetadata((prev) => new Map(prev).set(metadata.id, metadata));

0 commit comments

Comments
 (0)