## Summary Complete sidebar redesign and comprehensive UI polish pass with performance optimizations, theme system refinements, and desktop integration improvements. ## Key Changes **Sidebar & Navigation Redesign** - Redesigned sessions sidebar layout with unified button primitives - Added activity sections with project grouping and improved session organization - Refined sidebar corners, spacing, and visual hierarchy - Removed NavRail component in favor of streamlined sidebar - Stabilized sessions bar toggle position in fullscreen mode **Performance Optimizations** - Reduced chat streaming CPU usage and storage churn - Optimized task tool polling and live timers with debouncing - Prevented chat state races and reduced background request load - Debounced draft writes and coalesced session reloads - Optimized message store updates and turn tracking **Theme & Visual System** - Added theme-aware window corners (desktop) and border radius tokens - Introduced glassmorphism effects on desktop sidebar - Added backdrop blur to UI elements **Chat Experience** - Added session-based permission auto-accept toggle in chat input - Polished permission shield UX with improved icon sizing and spacing - Fixed chat scroll-to-bottom behavior and timeline tracking - Enhanced tool output display with better path label detection - Removed duplicate draft context details in chat header - Added text selection menu to chat messages **Git Improvements** - Refreshed git history visual design with cleaner dividers - Added remote removal action in sync selector - Stabilized git polling to prevent excessive requests - Improved tool output rendering for git operations **Settings & Panels** - Fixed mobile scrolling on settings pages - Made outside-click settings close instantly - Reduced settings load churn and CPU spikes - Improved services dropdown layout and spacing - Softened panel resize handles **Desktop Integration** - Synced macOS window theme with app theme - Restored window dragging in sidebar header zones - Fixed system window corners on macOS - Improved header session metadata and action controls **Button & Component Standardization** - Unified button primitives across all components - Standardized destructive action patterns - Removed unused button variants (button-large, button-small) - Aligned context tab close hit areas --------- Co-authored-by: Iuliia Ivashko <yulia.ivashko@gmail.com>
168 lines
5.8 KiB
TypeScript
168 lines
5.8 KiB
TypeScript
import React from 'react';
|
|
import { cn } from '@/lib/utils';
|
|
import { ErrorBoundary } from '../ui/ErrorBoundary';
|
|
import { useUIStore } from '@/stores/useUIStore';
|
|
import { isDesktopShell } from '@/lib/desktop';
|
|
|
|
export const SIDEBAR_CONTENT_WIDTH = 250;
|
|
const SIDEBAR_MIN_WIDTH = 250;
|
|
const SIDEBAR_MAX_WIDTH = 500;
|
|
|
|
interface SidebarProps {
|
|
isOpen: boolean;
|
|
isMobile: boolean;
|
|
children: React.ReactNode;
|
|
className?: string;
|
|
}
|
|
|
|
export const Sidebar: React.FC<SidebarProps> = ({ isOpen, isMobile, children, className }) => {
|
|
const { sidebarWidth, setSidebarWidth } = useUIStore();
|
|
const isDesktopApp = React.useMemo(() => isDesktopShell(), []);
|
|
const [isResizing, setIsResizing] = React.useState(false);
|
|
const startXRef = React.useRef(0);
|
|
const startWidthRef = React.useRef(sidebarWidth || SIDEBAR_CONTENT_WIDTH);
|
|
const resizingWidthRef = React.useRef<number | null>(null);
|
|
const activeResizePointerIDRef = React.useRef<number | null>(null);
|
|
const sidebarRef = React.useRef<HTMLElement | null>(null);
|
|
|
|
const clampSidebarWidth = React.useCallback((value: number) => {
|
|
return Math.min(SIDEBAR_MAX_WIDTH, Math.max(SIDEBAR_MIN_WIDTH, value));
|
|
}, []);
|
|
|
|
const applyLiveWidth = React.useCallback((nextWidth: number) => {
|
|
const sidebar = sidebarRef.current;
|
|
if (!sidebar) {
|
|
return;
|
|
}
|
|
|
|
sidebar.style.setProperty('--oc-left-sidebar-width', `${nextWidth}px`);
|
|
}, []);
|
|
|
|
React.useEffect(() => {
|
|
if (isMobile && isResizing) {
|
|
setIsResizing(false);
|
|
}
|
|
}, [isMobile, isResizing]);
|
|
|
|
React.useEffect(() => {
|
|
if (!isResizing) {
|
|
resizingWidthRef.current = null;
|
|
activeResizePointerIDRef.current = null;
|
|
}
|
|
}, [isResizing]);
|
|
|
|
if (isMobile) {
|
|
return null;
|
|
}
|
|
|
|
const appliedWidth = isOpen ? Math.min(
|
|
SIDEBAR_MAX_WIDTH,
|
|
Math.max(SIDEBAR_MIN_WIDTH, sidebarWidth || SIDEBAR_CONTENT_WIDTH)
|
|
) : 0;
|
|
|
|
const handlePointerDown = (event: React.PointerEvent) => {
|
|
if (!isOpen) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
event.currentTarget.setPointerCapture(event.pointerId);
|
|
} catch {
|
|
// ignore
|
|
}
|
|
|
|
activeResizePointerIDRef.current = event.pointerId;
|
|
setIsResizing(true);
|
|
startXRef.current = event.clientX;
|
|
startWidthRef.current = appliedWidth;
|
|
resizingWidthRef.current = appliedWidth;
|
|
applyLiveWidth(appliedWidth);
|
|
event.preventDefault();
|
|
};
|
|
|
|
const handlePointerMove = (event: React.PointerEvent) => {
|
|
if (isMobile || !isResizing || activeResizePointerIDRef.current !== event.pointerId) {
|
|
return;
|
|
}
|
|
|
|
const delta = event.clientX - startXRef.current;
|
|
const nextWidth = clampSidebarWidth(startWidthRef.current + delta);
|
|
if (resizingWidthRef.current === nextWidth) {
|
|
return;
|
|
}
|
|
|
|
resizingWidthRef.current = nextWidth;
|
|
applyLiveWidth(nextWidth);
|
|
};
|
|
|
|
const handlePointerEnd = (event: React.PointerEvent) => {
|
|
if (activeResizePointerIDRef.current !== event.pointerId || isMobile) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
} catch {
|
|
// ignore
|
|
}
|
|
|
|
const finalWidth = clampSidebarWidth(resizingWidthRef.current ?? appliedWidth);
|
|
activeResizePointerIDRef.current = null;
|
|
resizingWidthRef.current = null;
|
|
setIsResizing(false);
|
|
setSidebarWidth(finalWidth);
|
|
};
|
|
|
|
return (
|
|
<aside
|
|
ref={sidebarRef}
|
|
className={cn(
|
|
'relative flex h-full overflow-hidden border-r border-border/40',
|
|
isDesktopApp
|
|
? 'bg-[color:var(--sidebar-overlay-strong)] backdrop-blur supports-[backdrop-filter]:bg-[color:var(--sidebar-overlay-soft)]'
|
|
: 'bg-sidebar',
|
|
isResizing ? 'transition-none' : 'transition-[width] duration-300 ease-in-out',
|
|
!isOpen && 'border-r-0',
|
|
className,
|
|
)}
|
|
style={{
|
|
width: 'var(--oc-left-sidebar-width)',
|
|
minWidth: 'var(--oc-left-sidebar-width)',
|
|
maxWidth: 'var(--oc-left-sidebar-width)',
|
|
['--oc-left-sidebar-width' as string]: `${isResizing ? (resizingWidthRef.current ?? appliedWidth) : appliedWidth}px`,
|
|
overflowX: 'clip',
|
|
}}
|
|
aria-hidden={!isOpen || appliedWidth === 0}
|
|
>
|
|
{isOpen && (
|
|
<div
|
|
className={cn(
|
|
'absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors',
|
|
isResizing && 'bg-[var(--interactive-border)]'
|
|
)}
|
|
onPointerDown={handlePointerDown}
|
|
onPointerMove={handlePointerMove}
|
|
onPointerUp={handlePointerEnd}
|
|
onPointerCancel={handlePointerEnd}
|
|
role="separator"
|
|
aria-orientation="vertical"
|
|
aria-label="Resize left panel"
|
|
/>
|
|
)}
|
|
<div
|
|
className={cn(
|
|
'relative z-10 flex h-full flex-col transition-opacity duration-300 ease-in-out',
|
|
isResizing && 'pointer-events-none',
|
|
!isOpen && 'pointer-events-none select-none opacity-0'
|
|
)}
|
|
style={{ width: 'var(--oc-left-sidebar-width)', overflowX: 'hidden' }}
|
|
aria-hidden={!isOpen}
|
|
>
|
|
<div className="flex-1 overflow-hidden">
|
|
<ErrorBoundary>{children}</ErrorBoundary>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
);
|
|
};
|