import React from 'react'; import { Button } from '@/components/ui/button'; import { toast } from 'sonner'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { RiAddLine, RiGitBranchLine, RiMore2Line, RiDeleteBinLine, RiBriefcaseLine, RiHomeLine, RiGraduationCapLine, RiCodeLine, RiHeartLine, } from '@remixicon/react'; import { useGitIdentitiesStore } from '@/stores/useGitIdentitiesStore'; import { useUIStore } from '@/stores/useUIStore'; import { useDeviceInfo } from '@/lib/device'; import { ScrollableOverlay } from '@/components/ui/ScrollableOverlay'; import { cn } from '@/lib/utils'; import type { GitIdentityProfile } from '@/stores/useGitIdentitiesStore'; const ICON_MAP: Record> = { branch: RiGitBranchLine, briefcase: RiBriefcaseLine, house: RiHomeLine, graduation: RiGraduationCapLine, code: RiCodeLine, heart: RiHeartLine, }; const COLOR_MAP: Record = { keyword: 'var(--syntax-keyword)', error: 'var(--status-error)', string: 'var(--syntax-string)', function: 'var(--syntax-function)', type: 'var(--syntax-type)', }; export const GitIdentitiesSidebar: React.FC = () => { const { selectedProfileId, profiles, globalIdentity, setSelectedProfile, deleteProfile, loadProfiles, loadGlobalIdentity, } = useGitIdentitiesStore(); const { setSidebarOpen } = useUIStore(); const { isMobile } = useDeviceInfo(); React.useEffect(() => { loadProfiles(); loadGlobalIdentity(); }, [loadProfiles, loadGlobalIdentity]); const handleCreateProfile = () => { setSelectedProfile('new'); if (isMobile) { setSidebarOpen(false); } }; const handleDeleteProfile = async (profile: GitIdentityProfile) => { if (window.confirm(`Are you sure you want to delete profile "${profile.name}"?`)) { const success = await deleteProfile(profile.id); if (success) { toast.success(`Profile "${profile.name}" deleted successfully`); } else { toast.error('Failed to delete profile'); } } }; return (

Git Profiles

{profiles.length}
{} {globalIdentity && ( <>
System Default
{ setSelectedProfile('global'); if (isMobile) { setSidebarOpen(false); } }} onDelete={undefined} isReadOnly /> )} {} {profiles.length > 0 && (
Custom Profiles
)} {profiles.length === 0 && !globalIdentity ? (

No profiles configured

Use the + button above to create one

) : ( <> {profiles.map((profile) => ( { setSelectedProfile(profile.id); if (isMobile) { setSidebarOpen(false); } }} onDelete={() => handleDeleteProfile(profile)} /> ))} )}
); }; interface ProfileListItemProps { profile: GitIdentityProfile; isSelected: boolean; onSelect: () => void; onDelete?: () => void; isReadOnly?: boolean; } const ProfileListItem: React.FC = ({ profile, isSelected, onSelect, onDelete, isReadOnly = false, }) => { const IconComponent = ICON_MAP[profile.icon || 'branch'] || RiGitBranchLine; const iconColor = COLOR_MAP[profile.color || '']; return (
{!isReadOnly && onDelete && ( { e.stopPropagation(); onDelete(); }} className="text-destructive focus:text-destructive" > Delete )}
); };