Compare commits

...

3 Commits
main ... pr-118

Author SHA1 Message Date
Jordan Bentley
703ae92030
Merge main into PR branch - fix duplicate context menus
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-24 19:41:23 -04:00
David Mieloch
3139662973 Fix duplicate right-click context menus
- Implement centralized ContextMenuContext for global menu state management
- Refactor SessionListItem and DraggableProjectTreeView to use context
- Add global click and ESC handlers to close menus
- Fix vite.config.js module resolution issue
- Ensure only one context menu can be open at a time
2025-07-24 14:56:59 -04:00
David Mieloch
afee696714 fix: Optimize performance to prevent UI freezing during git status loading
This minimal fix addresses the issue where project collapse/expand functionality
becomes unresponsive when multiple sessions are simultaneously loading git status.

Changes include:
- Backend: Throttle git status events to 100ms intervals
- Backend: Limit concurrent git operations to 3
- Backend: Batch multiple git status updates
- Backend: Add cancellation support for git operations
- Frontend: Batch store updates with 50ms window
- Frontend: Add React.memo to prevent unnecessary re-renders
- Frontend: Skip non-essential updates during heavy loading
- Frontend: Cancel git status when collapsing projects
- Frontend: Implement performance safeguards

The optimizations ensure the UI remains responsive even when many sessions
are actively fetching git status information. Collapsing a project now
cancels any pending git status operations for its sessions.
2025-07-24 13:51:54 -04:00
5 changed files with 213 additions and 106 deletions

View File

@ -16,6 +16,7 @@ import { DiscordPopup } from './components/DiscordPopup';
import { useErrorStore } from './stores/errorStore';
import { useSessionStore } from './stores/sessionStore';
import { API } from './utils/api';
import { ContextMenuProvider } from './contexts/ContextMenuContext';
interface PermissionRequest {
id: string;
@ -241,52 +242,54 @@ function App() {
};
return (
<div className="h-screen flex overflow-hidden bg-gray-50 dark:bg-gray-900">
<MainProcessLogger />
{/* Draggable title bar area */}
<div
className="fixed top-0 left-0 right-0 h-8 z-50 flex items-center justify-end pr-4"
style={{ WebkitAppRegion: 'drag' } as React.CSSProperties}
>
<ContextMenuProvider>
<div className="h-screen flex overflow-hidden bg-gray-50 dark:bg-gray-900">
<MainProcessLogger />
{/* Draggable title bar area */}
<div
className="fixed top-0 left-0 right-0 h-8 z-50 flex items-center justify-end pr-4"
style={{ WebkitAppRegion: 'drag' } as React.CSSProperties}
>
</div>
<Sidebar
onHelpClick={() => setIsHelpOpen(true)}
onAboutClick={() => setIsAboutOpen(true)}
onPromptHistoryClick={() => setIsPromptHistoryOpen(true)}
width={sidebarWidth}
onResize={startResize}
/>
<SessionView />
<Help isOpen={isHelpOpen} onClose={() => setIsHelpOpen(false)} />
<Welcome isOpen={isWelcomeOpen} onClose={() => setIsWelcomeOpen(false)} />
<AboutDialog isOpen={isAboutOpen} onClose={() => setIsAboutOpen(false)} />
<UpdateDialog
isOpen={isUpdateDialogOpen}
onClose={() => setIsUpdateDialogOpen(false)}
versionInfo={updateVersionInfo}
/>
<ErrorDialog
isOpen={!!currentError}
onClose={clearError}
title={currentError?.title}
error={currentError?.error || ''}
details={currentError?.details}
command={currentError?.command}
/>
<PermissionDialog
request={currentPermissionRequest}
onRespond={handlePermissionResponse}
session={currentPermissionRequest ? sessions.find(s => s.id === currentPermissionRequest.sessionId) : undefined}
/>
<DiscordPopup
isOpen={isDiscordOpen}
onClose={() => setIsDiscordOpen(false)}
/>
<PromptHistoryModal
isOpen={isPromptHistoryOpen}
onClose={() => setIsPromptHistoryOpen(false)}
/>
</div>
<Sidebar
onHelpClick={() => setIsHelpOpen(true)}
onAboutClick={() => setIsAboutOpen(true)}
onPromptHistoryClick={() => setIsPromptHistoryOpen(true)}
width={sidebarWidth}
onResize={startResize}
/>
<SessionView />
<Help isOpen={isHelpOpen} onClose={() => setIsHelpOpen(false)} />
<Welcome isOpen={isWelcomeOpen} onClose={() => setIsWelcomeOpen(false)} />
<AboutDialog isOpen={isAboutOpen} onClose={() => setIsAboutOpen(false)} />
<UpdateDialog
isOpen={isUpdateDialogOpen}
onClose={() => setIsUpdateDialogOpen(false)}
versionInfo={updateVersionInfo}
/>
<ErrorDialog
isOpen={!!currentError}
onClose={clearError}
title={currentError?.title}
error={currentError?.error || ''}
details={currentError?.details}
command={currentError?.command}
/>
<PermissionDialog
request={currentPermissionRequest}
onRespond={handlePermissionResponse}
session={currentPermissionRequest ? sessions.find(s => s.id === currentPermissionRequest.sessionId) : undefined}
/>
<DiscordPopup
isOpen={isDiscordOpen}
onClose={() => setIsDiscordOpen(false)}
/>
<PromptHistoryModal
isOpen={isPromptHistoryOpen}
onClose={() => setIsPromptHistoryOpen(false)}
/>
</div>
</ContextMenuProvider>
);
}

View File

@ -13,6 +13,7 @@ import { debounce } from '../utils/debounce';
import type { Session } from '../types/session';
import type { Project } from '../types/project';
import type { Folder } from '../types/folder';
import { useContextMenu } from '../contexts/ContextMenuContext';
interface ProjectWithSessions extends Project {
sessions: Session[];
@ -61,10 +62,8 @@ export function DraggableProjectTreeView() {
const [selectedProjectForFolder, setSelectedProjectForFolder] = useState<Project | null>(null);
const [newFolderName, setNewFolderName] = useState('');
const [parentFolderForCreate, setParentFolderForCreate] = useState<Folder | null>(null);
const [showFolderContextMenu, setShowFolderContextMenu] = useState(false);
const [folderContextMenuPosition, setFolderContextMenuPosition] = useState({ x: 0, y: 0 });
const [selectedFolderForMenu, setSelectedFolderForMenu] = useState<Folder | null>(null);
const { showError } = useErrorStore();
const { menuState, openMenu, closeMenu, isMenuOpen } = useContextMenu();
// Folder rename state
const [editingFolderId, setEditingFolderId] = useState<string | null>(null);
@ -519,28 +518,12 @@ export function DraggableProjectTreeView() {
setEditingFolderName(folder.name);
};
const handleFolderContextMenu = (e: React.MouseEvent, folder: Folder, _projectId: number) => {
const handleFolderContextMenu = (e: React.MouseEvent, folder: Folder, projectId: number) => {
e.preventDefault();
e.stopPropagation();
setSelectedFolderForMenu(folder);
setFolderContextMenuPosition({ x: e.clientX, y: e.clientY });
setShowFolderContextMenu(true);
openMenu('folder', { ...folder, projectId }, { x: e.clientX, y: e.clientY });
};
const closeFolderContextMenu = () => {
setShowFolderContextMenu(false);
setSelectedFolderForMenu(null);
};
// Close folder context menu when clicking outside
useEffect(() => {
if (showFolderContextMenu) {
const handleClick = () => closeFolderContextMenu();
document.addEventListener('click', handleClick);
return () => document.removeEventListener('click', handleClick);
}
}, [showFolderContextMenu]);
const handleSaveFolderEdit = async () => {
if (!editingFolderId || !editingFolderName.trim()) {
setEditingFolderId(null);
@ -2092,16 +2075,16 @@ export function DraggableProjectTreeView() {
)}
{/* Folder Context Menu */}
{showFolderContextMenu && selectedFolderForMenu && (
{isMenuOpen('folder') && menuState.payload && menuState.position && (
<div
className="fixed bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md shadow-lg py-1 z-50 min-w-[150px]"
style={{ top: folderContextMenuPosition.y, left: folderContextMenuPosition.x }}
className="context-menu fixed bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md shadow-lg py-1 z-50 min-w-[150px]"
style={{ top: menuState.position.y, left: menuState.position.x }}
onClick={(e) => e.stopPropagation()}
>
<button
onClick={() => {
closeFolderContextMenu();
handleStartFolderEdit(selectedFolderForMenu);
closeMenu();
handleStartFolderEdit(menuState.payload);
}}
className="w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 hover:text-gray-900 dark:hover:text-white"
>
@ -2109,10 +2092,10 @@ export function DraggableProjectTreeView() {
</button>
<button
onClick={() => {
closeFolderContextMenu();
closeMenu();
// Find the project that contains this folder
const project = projectsWithSessions.find(p =>
p.folders?.some(f => f.id === selectedFolderForMenu.id)
p.folders?.some(f => f.id === menuState.payload.id)
);
if (project) {
setSelectedProjectForCreate(project);
@ -2126,13 +2109,14 @@ export function DraggableProjectTreeView() {
<div className="border-t border-gray-200 dark:border-gray-700 my-1" />
<button
onClick={() => {
closeFolderContextMenu();
// Find the project that contains this folder
const project = projectsWithSessions.find(p =>
p.folders?.some(f => f.id === selectedFolderForMenu.id)
);
if (project) {
handleDeleteFolder(selectedFolderForMenu, project.id);
closeMenu();
// Find the project that contains this folder or use projectId from payload
const projectId = menuState.payload.projectId ||
projectsWithSessions.find(p =>
p.folders?.some(f => f.id === menuState.payload.id)
)?.id;
if (projectId) {
handleDeleteFolder(menuState.payload, projectId);
}
}}
className="w-full text-left px-4 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-gray-100 dark:hover:bg-gray-700 hover:text-red-700 dark:hover:text-red-300"

View File

@ -6,6 +6,7 @@ import { GitStatusIndicator } from './GitStatusIndicator';
import { API } from '../utils/api';
import { Star, Archive } from 'lucide-react';
import type { Session, GitStatus } from '../types/session';
import { useContextMenu } from '../contexts/ContextMenuContext';
interface SessionListItemProps {
session: Session;
@ -23,9 +24,8 @@ export const SessionListItem = memo(function SessionListItem({ session, isNested
const [isClosing, setIsClosing] = useState(false);
const [isEditing, setIsEditing] = useState(false);
const [editName, setEditName] = useState(session.name);
const [showContextMenu, setShowContextMenu] = useState(false);
const [contextMenuPosition, setContextMenuPosition] = useState({ x: 0, y: 0 });
const [gitStatus, setGitStatus] = useState<GitStatus | undefined>(session.gitStatus);
const { menuState, openMenu, closeMenu, isMenuOpen } = useContextMenu();
// Selective subscription for git status loading state
const gitStatusLoading = useSessionStore((state) => state.gitStatusLoading.has(session.id));
@ -299,31 +299,17 @@ export const SessionListItem = memo(function SessionListItem({ session, isNested
const handleContextMenu = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
setContextMenuPosition({ x: e.clientX, y: e.clientY });
setShowContextMenu(true);
openMenu('session', session, { x: e.clientX, y: e.clientY });
};
const closeContextMenu = () => {
setShowContextMenu(false);
};
// Close context menu when clicking outside
useEffect(() => {
if (showContextMenu) {
const handleClick = () => closeContextMenu();
document.addEventListener('click', handleClick);
return () => document.removeEventListener('click', handleClick);
}
}, [showContextMenu]);
const handleRename = () => {
closeContextMenu();
closeMenu();
setEditName(session.name);
setIsEditing(true);
};
const handleDeleteFromMenu = () => {
closeContextMenu();
closeMenu();
handleDelete({ stopPropagation: () => {} } as React.MouseEvent);
};
@ -449,10 +435,10 @@ export const SessionListItem = memo(function SessionListItem({ session, isNested
</div>
{/* Context Menu */}
{showContextMenu && (
{isMenuOpen('session', session.id) && menuState.position && (
<div
className="fixed bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md shadow-lg py-1 z-50 min-w-[150px]"
style={{ top: contextMenuPosition.y, left: contextMenuPosition.x }}
className="context-menu fixed bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md shadow-lg py-1 z-50 min-w-[150px]"
style={{ top: menuState.position.y, left: menuState.position.x }}
onClick={(e) => e.stopPropagation()}
>
<button
@ -463,7 +449,7 @@ export const SessionListItem = memo(function SessionListItem({ session, isNested
</button>
<button
onClick={() => {
closeContextMenu();
closeMenu();
if (isRunning) {
handleStopScript({ stopPropagation: () => {} } as React.MouseEvent);
} else {

View File

@ -0,0 +1,121 @@
import React, { createContext, useContext, useState, useEffect, useCallback, ReactNode } from 'react';
interface ContextMenuPosition {
x: number;
y: number;
}
interface ContextMenuState {
type: 'session' | 'folder' | null;
position: ContextMenuPosition | null;
payload: any;
}
interface ContextMenuContextType {
menuState: ContextMenuState;
openMenu: (type: 'session' | 'folder', payload: any, position: ContextMenuPosition) => void;
closeMenu: () => void;
isMenuOpen: (type: 'session' | 'folder', id?: string) => boolean;
}
const ContextMenuContext = createContext<ContextMenuContextType | undefined>(undefined);
export const useContextMenu = () => {
const context = useContext(ContextMenuContext);
if (!context) {
throw new Error('useContextMenu must be used within a ContextMenuProvider');
}
return context;
};
interface ContextMenuProviderProps {
children: ReactNode;
}
export const ContextMenuProvider: React.FC<ContextMenuProviderProps> = ({ children }) => {
const [menuState, setMenuState] = useState<ContextMenuState>({
type: null,
position: null,
payload: null,
});
const openMenu = useCallback((type: 'session' | 'folder', payload: any, position: ContextMenuPosition) => {
// Close any existing menu before opening a new one
setMenuState({
type,
position,
payload,
});
}, []);
const closeMenu = useCallback(() => {
setMenuState({
type: null,
position: null,
payload: null,
});
}, []);
const isMenuOpen = useCallback((type: 'session' | 'folder', id?: string) => {
if (menuState.type !== type) return false;
if (!id) return true;
// Check if the ID matches based on the menu type
if (type === 'session' && menuState.payload?.id === id) return true;
if (type === 'folder' && menuState.payload?.id === id) return true;
return false;
}, [menuState]);
// Global click handler to close menu when clicking outside
useEffect(() => {
const handleGlobalClick = (event: MouseEvent) => {
// Check if the click is on the context menu itself
const target = event.target as HTMLElement;
const isContextMenu = target.closest('.context-menu');
// If click is outside the context menu, close it
if (!isContextMenu && menuState.type !== null) {
closeMenu();
}
};
// Add slight delay to prevent immediate closing on right-click
const timeoutId = setTimeout(() => {
document.addEventListener('mousedown', handleGlobalClick);
}, 0);
return () => {
clearTimeout(timeoutId);
document.removeEventListener('mousedown', handleGlobalClick);
};
}, [menuState.type, closeMenu]);
// Global keyboard handler for ESC key
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape' && menuState.type !== null) {
closeMenu();
}
};
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, [menuState.type, closeMenu]);
const contextValue: ContextMenuContextType = {
menuState,
openMenu,
closeMenu,
isMenuOpen,
};
return (
<ContextMenuContext.Provider value={contextValue}>
{children}
</ContextMenuContext.Provider>
);
};

View File

@ -1,3 +1,16 @@
// Import and re-export configuration from TypeScript config file
// This ensures a single source of truth and avoids configuration conflicts
export { default } from './vite.config.ts';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
server: {
port: 4521,
strictPort: true
},
base: './',
build: {
// Ensure assets are copied and paths are relative
assetsDir: 'assets',
// Copy public files to dist
copyPublicDir: true
}
});