import React, { useState } from 'react'; import { motion } from 'framer-motion'; import { useGitLabConnection } from '~/lib/hooks'; import GitLabConnection from './components/GitLabConnection'; import { StatsDisplay } from './components/StatsDisplay'; import { RepositoryList } from './components/RepositoryList'; // GitLab logo SVG component const GitLabLogo = () => ( ); interface ConnectionTestResult { status: 'success' | 'error' | 'testing'; message: string; timestamp?: number; } export default function GitLabTab() { const { connection, isConnected, isLoading, error, testConnection, refreshStats } = useGitLabConnection(); const [connectionTest, setConnectionTest] = useState(null); const [isRefreshingStats, setIsRefreshingStats] = 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.username}`, 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 (

GitLab Integration

Loading...
); } // Error state for connection issues if (error && !connection) { return (

GitLab Integration

{error}
); } // Not connected state if (!isConnected || !connection) { return (

GitLab Integration

Connect your GitLab account to enable advanced repository management features, statistics, and seamless integration.

); } return (
{/* Header */}

GitLab Integration

{connection?.rateLimit && (
API: {connection.rateLimit.remaining}/{connection.rateLimit.limit}
)}

Manage your GitLab integration with advanced repository features and comprehensive statistics

{/* Connection Test Results */} {connectionTest && (
{connectionTest.status === 'success' ? (
) : connectionTest.status === 'error' ? (
) : (
)}
{connectionTest.message}
)} {/* GitLab Connection Component */} {/* User Profile Section */} {connection?.user && (
{connection.user.avatar_url && connection.user.avatar_url !== 'null' && connection.user.avatar_url !== '' ? ( {connection.user.username} { const target = e.target as HTMLImageElement; target.style.display = 'none'; const parent = target.parentElement; if (parent) { parent.innerHTML = (connection.user?.name || connection.user?.username || 'U') .charAt(0) .toUpperCase(); parent.classList.add( 'text-white', 'font-semibold', 'text-sm', 'flex', 'items-center', 'justify-center', ); } }} /> ) : (
{(connection.user?.name || connection.user?.username || 'U').charAt(0).toUpperCase()}
)}

{connection.user?.name || connection.user?.username}

{connection.user?.username}

)} {/* GitLab Stats Section */} {connection?.stats && (

Statistics

{ setIsRefreshingStats(true); try { await refreshStats(); } catch (error) { console.error('Failed to refresh stats:', error); } finally { setIsRefreshingStats(false); } }} isRefreshing={isRefreshingStats} />
)} {/* GitLab Repositories Section */} {connection?.stats?.projects && ( { setIsRefreshingStats(true); try { await refreshStats(); } catch (error) { console.error('Failed to refresh repositories:', error); } finally { setIsRefreshingStats(false); } }} isRefreshing={isRefreshingStats} /> )}
); }