Skip to content

Commit c06300d

Browse files
committed
🤖 refactor: move modal constant to module scope, remove wrapper callbacks
Simplifications in App.tsx for net negative LoC: - Moved INITIAL_WORKSPACE_MODAL_STATE to module scope (prevents recreation) - Removed thin wrapper callbacks (handleAddProjectCallback, etc.) - Directly pass functions to LeftSidebar (addProject, handleAddWorkspace, handleRemoveProject) Net impact: 774 → 757 lines (-17 LoC) Generated with `cmux`
1 parent 94eb764 commit c06300d

File tree

1 file changed

+14
-33
lines changed

1 file changed

+14
-33
lines changed

‎src/App.tsx‎

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ import { parseRuntimeString } from "./utils/chatCommands";
3232

3333
const THINKING_LEVELS: ThinkingLevel[] = ["off", "low", "medium", "high"];
3434

35+
const INITIAL_WORKSPACE_MODAL_STATE = {
36+
isOpen: false,
37+
projectPath: null as string | null,
38+
projectName: "",
39+
branches: [] as string[],
40+
defaultTrunk: undefined as string | undefined,
41+
loadError: null as string | null,
42+
startMessage: undefined as string | undefined,
43+
model: undefined as string | undefined,
44+
};
45+
3546
function AppInner() {
3647
// Get app-level state from context
3748
const {
@@ -47,17 +58,6 @@ function AppInner() {
4758
setSelectedWorkspace,
4859
} = useApp();
4960

50-
const INITIAL_WORKSPACE_MODAL_STATE = {
51-
isOpen: false,
52-
projectPath: null as string | null,
53-
projectName: "",
54-
branches: [] as string[],
55-
defaultTrunk: undefined as string | undefined,
56-
loadError: null as string | null,
57-
startMessage: undefined as string | undefined,
58-
model: undefined as string | undefined,
59-
};
60-
6161
const [workspaceModalState, setWorkspaceModalState] = useState(INITIAL_WORKSPACE_MODAL_STATE);
6262
const workspaceModalProjectRef = useRef<string | null>(null);
6363

@@ -236,25 +236,6 @@ function AppInner() {
236236
[]
237237
);
238238

239-
// Memoize callbacks to prevent LeftSidebar/ProjectSidebar re-renders
240-
const handleAddProjectCallback = useCallback(() => {
241-
void addProject();
242-
}, [addProject]);
243-
244-
const handleAddWorkspaceCallback = useCallback(
245-
(projectPath: string) => {
246-
void handleAddWorkspace(projectPath);
247-
},
248-
[handleAddWorkspace]
249-
);
250-
251-
const handleRemoveProjectCallback = useCallback(
252-
(path: string) => {
253-
void handleRemoveProject(path);
254-
},
255-
[handleRemoveProject]
256-
);
257-
258239
const handleCreateWorkspace = async (
259240
branchName: string,
260241
trunkBranch: string,
@@ -686,9 +667,9 @@ function AppInner() {
686667
<div className="bg-bg-dark flex h-screen overflow-hidden [@media(max-width:768px)]:flex-col">
687668
<LeftSidebar
688669
onSelectWorkspace={handleWorkspaceSwitch}
689-
onAddProject={handleAddProjectCallback}
690-
onAddWorkspace={handleAddWorkspaceCallback}
691-
onRemoveProject={handleRemoveProjectCallback}
670+
onAddProject={addProject}
671+
onAddWorkspace={handleAddWorkspace}
672+
onRemoveProject={handleRemoveProject}
692673
lastReadTimestamps={lastReadTimestamps}
693674
onToggleUnread={onToggleUnread}
694675
collapsed={sidebarCollapsed}

0 commit comments

Comments
 (0)