import React, { useState } from 'react'; import { motion } from 'framer-motion'; import { useGitHubConnection, useGitHubStats } from '~/lib/hooks'; import { LoadingState, ErrorState, ConnectionTestIndicator, RepositoryCard } from './components/shared'; import { GitHubConnection } from './components/GitHubConnection'; import { GitHubUserProfile } from './components/GitHubUserProfile'; import { GitHubStats } from './components/GitHubStats'; import { Button } from '~/components/ui/Button'; import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '~/components/ui/Collapsible'; import { classNames } from '~/utils/classNames'; import { ChevronDown } from 'lucide-react'; import { GitHubErrorBoundary } from './components/GitHubErrorBoundary'; import { GitHubProgressiveLoader } from './components/GitHubProgressiveLoader'; import { GitHubCacheManager } from './components/GitHubCacheManager'; interface ConnectionTestResult { status: 'success' | 'error' | 'testing'; message: string; timestamp?: number; } // GitHub logo SVG component const GithubLogo = () => ( ); export default function GitHubTab() { const { connection, isConnected, isLoading, error, testConnection } = useGitHubConnection(); const { stats, isLoading: isStatsLoading, error: statsError, } = useGitHubStats( connection, { autoFetch: true, cacheTimeout: 30 * 60 * 1000, // 30 minutes }, isConnected && connection ? !connection.token : false, ); // Use server-side when no token but connected const [connectionTest, setConnectionTest] = useState(null); const [isStatsExpanded, setIsStatsExpanded] = useState(false); const [isReposExpanded, setIsReposExpanded] = useState(false); const handleTestConnection = async () => { if (!connection?.user) { setConnectionTest({ status: 'error', message: 'No connection established', timestamp: Date.now(), }); return; } setConnectionTest({ status: 'testing', message: 'Testing connection...', }); try { const isValid = await testConnection(); if (isValid) { setConnectionTest({ status: 'success', message: `Connected successfully as ${connection.user.login}`, timestamp: Date.now(), }); } else { setConnectionTest({ status: 'error', message: 'Connection test failed', timestamp: Date.now(), }); } } catch (error) { setConnectionTest({ status: 'error', message: `Connection failed: ${error instanceof Error ? error.message : 'Unknown error'}`, timestamp: Date.now(), }); } }; // Loading state for initial connection check if (isLoading) { return ( GitHub Integration ); } // Error state for connection issues if (error && !connection) { return ( GitHub Integration window.location.reload()} retryLabel="Reload Page" /> ); } // Not connected state if (!isConnected || !connection) { return ( GitHub Integration Connect your GitHub account to enable advanced repository management features, statistics, and seamless integration. ); } return ( {/* Header */} GitHub Integration {connection?.rateLimit && ( API: {connection.rateLimit.remaining}/{connection.rateLimit.limit} )} Manage your GitHub integration with advanced repository features and comprehensive statistics {/* Connection Test Results */} {/* Connection Component */} {/* User Profile */} {connection.user && } {/* Stats Section */} {/* Repositories Section */} {stats?.repos && stats.repos.length > 0 && ( All Repositories ({stats.repos.length}) {(isReposExpanded ? stats.repos : stats.repos.slice(0, 12)).map((repo) => ( window.open(repo.html_url, '_blank', 'noopener,noreferrer')} /> ))} {stats.repos.length > 12 && !isReposExpanded && ( setIsReposExpanded(true)} className="text-bolt-elements-textSecondary hover:text-bolt-elements-textPrimary" > Show {stats.repos.length - 12} more repositories )} )} {/* Stats Error State */} {statsError && !stats && ( window.location.reload()} retryLabel="Retry" /> )} {/* Stats Loading State */} {isStatsLoading && !stats && ( )} {/* Cache Management Section - Only show when connected */} {isConnected && connection && ( )} ); }
Connect your GitHub account to enable advanced repository management features, statistics, and seamless integration.
Manage your GitHub integration with advanced repository features and comprehensive statistics