Files
openchamber/packages/ui/src/hooks/useProviderLogo.ts
T
Bohdan TriapitsynandIuliia Ivashko 321cc7252a Major UI refresh: sidebar redesign, theme expansion, and chat performance optimizations (#706)
## 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>
2026-03-20 01:01:03 +02:00

97 lines
3.0 KiB
TypeScript

import { useState, useCallback, useEffect } from 'react';
type LogoSource = 'local' | 'remote' | 'none';
interface UseProviderLogoReturn {
src: string | null;
onError: () => void;
hasLogo: boolean;
}
const localLogoModules = import.meta.glob<string>('../assets/provider-logos/*.svg', {
eager: true,
import: 'default',
});
const LOCAL_PROVIDER_LOGO_MAP = new Map<string, string>();
const LOGO_ALIAS = new Map<string, string>([
['codex', 'openai'],
['chatgpt', 'openai'],
['claude', 'anthropic'],
['gemini', 'google'],
['evroc-ai', 'evroc'],
['evrocai', 'evroc'],
['ollama-cloud', 'ollama'],
]);
const normalizeProviderId = (providerId: string | null | undefined) => {
return (providerId ?? '')
.toLowerCase()
.trim()
.replace(/^models\./, '')
.replace(/^provider\./, '')
.replace(/\s+/g, '-');
};
const buildLogoCandidates = (providerId: string | null | undefined) => {
const normalized = normalizeProviderId(providerId);
if (!normalized) {
return [] as string[];
}
const compact = normalized.replace(/[^a-z0-9_\-./:]/g, '');
const primary = compact.split(/[/:]/)[0] || compact;
const candidates = [LOGO_ALIAS.get(compact), LOGO_ALIAS.get(primary), compact, primary]
.filter((value): value is string => Boolean(value && value.length > 0));
return [...new Set(candidates)];
};
for (const [path, url] of Object.entries(localLogoModules)) {
const match = path.match(/provider-logos\/([^/]+)\.svg$/i);
if (match?.[1] && url) {
LOCAL_PROVIDER_LOGO_MAP.set(match[1].toLowerCase(), url);
}
}
export function useProviderLogo(providerId: string | null | undefined): UseProviderLogoReturn {
const candidates = buildLogoCandidates(providerId);
const localResolvedId = candidates.find((candidate) => LOCAL_PROVIDER_LOGO_MAP.has(candidate)) ?? null;
const remoteResolvedId = candidates[0] ?? null;
const hasLocalLogo = Boolean(localResolvedId);
const localLogoSrc = localResolvedId ? LOCAL_PROVIDER_LOGO_MAP.get(localResolvedId) ?? null : null;
const [source, setSource] = useState<LogoSource>(hasLocalLogo ? 'local' : 'remote');
useEffect(() => {
setSource(hasLocalLogo ? 'local' : 'remote');
}, [hasLocalLogo, localResolvedId, remoteResolvedId]);
const handleError = useCallback(() => {
setSource((current) => (current === 'local' && hasLocalLogo ? 'remote' : 'none'));
}, [hasLocalLogo]);
if (!localResolvedId && !remoteResolvedId) {
return { src: null, onError: handleError, hasLogo: false };
}
if (source === 'local' && localLogoSrc) {
return {
src: localLogoSrc,
onError: handleError,
hasLogo: true,
};
}
if (source === 'remote' && remoteResolvedId) {
return {
src: `https://models.dev/logos/${remoteResolvedId}.svg`,
onError: handleError,
hasLogo: true,
};
}
return { src: null, onError: handleError, hasLogo: false };
}