diff --git a/src/components/GitDialog.tsx b/src/components/GitDialog.tsx index 7431e436..b73e5239 100644 --- a/src/components/GitDialog.tsx +++ b/src/components/GitDialog.tsx @@ -715,234 +715,223 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
- {/* URL Configuration */} + {/* Section 1: Git URL, Current Branch, Sync Status, Merge Branch */} {gitStatus?.isGitRepo && ( - Git URL + Repository Info - -
-
- + + {/* Git URL */} +
+ +
setOriginUrl(e.target.value)} disabled={isSavingOrigin} + className="flex-1" /> +
- + + {/* Credentials Warning */} + {gitStatus.remotes.length > 0 && ( + (() => { + const remoteWithoutCredentials = gitStatus.remotes.find((remote) => !findCredentialsForRepo(remote.url, settings.credentials)); + if (!remoteWithoutCredentials) return null; + + let protocol = ''; + let hostname = 'the remote host'; + try { + const url = new URL(remoteWithoutCredentials.url); + protocol = url.protocol; + hostname = url.hostname; + } catch { + return ( + + + + Invalid URL format. Enter an https URL. + + + ); + } + + if (protocol !== 'https:' && protocol !== 'nostr:') { + return ( + + + + The {protocol.replace(':', '')} URL type is not supported. Enter an https URL. + + + ); + } + + if (protocol === 'nostr:' && !user) { + return ( + + + + You are not logged into Nostr. Push & pull might not work unless you{' '} + . + + + ); + } + + if (protocol === 'https:') { + return ( + + + + You are not logged into {hostname}. Push & pull might not work unless you{' '} + . + + + ); + } + + return null; + })() + )}
- {/* Credentials Warning */} - {gitStatus.remotes.length > 0 && ( - (() => { - const remoteWithoutCredentials = gitStatus.remotes.find((remote) => !findCredentialsForRepo(remote.url, settings.credentials)); - if (!remoteWithoutCredentials) return null; - - let protocol = ''; - let hostname = 'the remote host'; - try { - const url = new URL(remoteWithoutCredentials.url); - protocol = url.protocol; - hostname = url.hostname; - } catch { - // Invalid URL - return ( - - - - Invalid URL format. Enter an https URL. - - - ); - } - - // Check for unsupported protocols - if (protocol !== 'https:' && protocol !== 'nostr:') { - return ( - - - - The {protocol.replace(':', '')} URL type is not supported. Enter an https URL. - - - ); - } - - // For nostr protocol, only show warning if user is not logged in - if (protocol === 'nostr:' && !user) { - return ( - - - - You are not logged into Nostr. Push & pull might not work unless you{' '} - . - - - ); - } - - // For https protocol, show warning if no credentials - if (protocol === 'https:') { - return ( - - - - You are not logged into {hostname}. Push & pull might not work unless you{' '} - . - - - ); - } - - return null; - })() - )} -
- - )} - - {/* Branch Selector */} - {gitStatus?.isGitRepo && gitStatus.currentBranch && ( - - - Current Branch - - -
- + + + {isSwitchingBranch ? ( + + + Switching... + + ) : ( + + + {gitStatus.currentBranch} + )} - {branch} - - - ))} - - - -
-
-
- )} - - {/* Sync Status */} - {gitStatus?.isGitRepo && ( - - - Sync Status - - -
- - - {syncStatus.text} - -
- - {gitStatus.remotes.length > 0 && ( -
- - - + + + + {branches.map((branch) => ( + + + {branch === gitStatus.currentBranch && ( + + )} + {branch} + + + ))} + + + +
)} - {/* Push to Nostr button when no remote is configured and user is logged in */} - {gitStatus.remotes.length === 0 && user && ( -
+ {/* Sync Status */} +
+ +
+ + + {syncStatus.text} + +
+ + {gitStatus.remotes.length > 0 && ( +
+ + + +
+ )} + + {gitStatus.remotes.length === 0 && user && ( + )} +
+ + {/* Merge Branch Action */} + {gitStatus.currentBranch && ( +
+ refetchGitStatus()} + />
)} )} - {/* Pull Requests Card */} + {/* Section 2: Your Open PRs and Create PR Button */} {gitStatus?.isGitRepo && gitStatus.remotes.length > 0 && originUrl && ( @@ -972,7 +972,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog - {/* Open Pull Requests List (only for non-Nostr repos) */} + {/* Open Pull Requests List */} {!originUrl.startsWith('nostr://') && isLoadingPRs && (
@@ -980,7 +980,8 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
)} {!originUrl.startsWith('nostr://') && !isLoadingPRs && pullRequests && pullRequests.length > 0 && ( -
+
+
Your Open PRs
{pullRequests.map((pr) => (
)} - {!originUrl.startsWith('nostr://') && !isLoadingPRs && (!pullRequests || pullRequests.length === 0) && ( -
- You have no open pull requests -
- )} - {/* Create PR Button - Works for all repo types */} + {/* Create PR Button */} )} - {/* Branch Operations */} - {gitStatus?.isGitRepo && gitStatus.currentBranch && ( + {/* Section 3: Working Directory */} + {gitStatus?.isGitRepo && ( - Branch Operations - - - refetchGitStatus()} - /> - - - )} - - {/* Working Directory Changes */} - {gitStatus?.isGitRepo && gitStatus.changedFiles.length > 0 && ( - - - Working Directory Changes - - {gitStatus.changedFiles.length} file{gitStatus.changedFiles.length !== 1 ? 's' : ''} with changes - + Working Directory + {gitStatus.changedFiles.length > 0 && ( + + {gitStatus.changedFiles.length} file{gitStatus.changedFiles.length !== 1 ? 's' : ''} with changes + + )} -
- {gitStatus.changedFiles.map((file, index) => ( -
- {getFileStatusIcon(file.status)} - - {file.filepath} - - 0 ? ( +
+ {gitStatus.changedFiles.map((file, index) => ( +
- {file.status} - -
- ))} -
- - - )} - - {/* Clean Working Directory */} - {gitStatus?.isGitRepo && gitStatus.changedFiles.length === 0 && ( - - -
- -

Working directory is clean

-

No uncommitted changes

-
+ {getFileStatusIcon(file.status)} + + {file.filepath} + + + {file.status} + +
+ ))} +
+ ) : ( +
+ +

Working directory is clean

+

No uncommitted changes

+
+ )}
)} diff --git a/src/components/git/GitManagementDialog.tsx b/src/components/git/GitManagementDialog.tsx index 5d77e02b..6e52ae65 100644 --- a/src/components/git/GitManagementDialog.tsx +++ b/src/components/git/GitManagementDialog.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useCallback } from 'react'; +import { useState } from 'react'; import { Dialog, DialogContent, @@ -6,31 +6,21 @@ import { DialogTitle, DialogTrigger, } from '@/components/ui/dialog'; +import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { Button } from '@/components/ui/button'; -import { Badge } from '@/components/ui/badge'; -import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; -import { Separator } from '@/components/ui/separator'; import { GitBranch, - GitMerge, + GitCompare, + Settings, GitPullRequest, - ExternalLink, - Loader2, - RefreshCw, - CheckCircle, - XCircle, - Clock, } from 'lucide-react'; +import { BranchManager } from './BranchManager'; +import { CompareView } from './CompareView'; import { DiffViewer } from './DiffViewer'; -import { MergeDialog } from './MergeDialog'; import { PullRequestForm } from './PullRequestForm'; import { useGitStatus } from '@/hooks/useGitStatus'; import { useGit } from '@/hooks/useGit'; -import { useGitSettings } from '@/hooks/useGitSettings'; -import { useToast } from '@/hooks/useToast'; -import { findCredentialsForRepo } from '@/lib/gitCredentials'; -import { BranchManager } from './BranchManager'; +import { useState, useEffect } from 'react'; interface GitManagementDialogProps { projectId: string; @@ -40,37 +30,16 @@ interface GitManagementDialogProps { defaultTab?: string; } -interface PullRequest { - number: number; - title: string; - state: 'open' | 'closed' | 'merged'; - html_url: string; - created_at: string; - head: { - ref: string; - }; - base: { - ref: string; - }; -} - export function GitManagementDialog({ projectId, children, open, onOpenChange, + defaultTab = 'branches', }: GitManagementDialogProps) { + const [activeTab, setActiveTab] = useState(defaultTab); const [remoteUrl, setRemoteUrl] = useState(null); - const [isSyncing, setIsSyncing] = useState(false); - const [isMergeDialogOpen, setIsMergeDialogOpen] = useState(false); - const [showPRForm, setShowPRForm] = useState(false); - const [pullRequests, setPullRequests] = useState([]); - const [isLoadingPRs, setIsLoadingPRs] = useState(false); - const [showBranchManager, setShowBranchManager] = useState(false); - const { git } = useGit(); - const { settings } = useGitSettings(); - const { toast } = useToast(); const projectPath = `/projects/${projectId}`; const { data: gitStatus, refetch: refetchGitStatus } = useGitStatus(projectId); @@ -89,140 +58,11 @@ export function GitManagementDialog({ } }, [open, git, projectPath]); - const loadPullRequests = useCallback(async () => { - if (!remoteUrl) return; - - setIsLoadingPRs(true); - try { - const credentials = findCredentialsForRepo(remoteUrl, settings.credentials); - if (!credentials) { - setPullRequests([]); - return; - } - - // Parse GitHub/GitLab URL - let match; - let owner = ''; - let repo = ''; - let apiUrl = ''; - - const normalizedUrl = remoteUrl.replace(/\.git$/, ''); - - // GitHub - match = normalizedUrl.match(/git@github\.com:([^/]+)\/(.+)$/) || - normalizedUrl.match(/https?:\/\/github\.com\/([^/]+)\/(.+)$/); - if (match) { - owner = match[1]; - repo = match[2]; - apiUrl = `https://api.github.com/repos/${owner}/${repo}/pulls`; - } - - // GitLab - if (!match) { - match = normalizedUrl.match(/git@gitlab\.com:([^/]+)\/(.+)$/) || - normalizedUrl.match(/https?:\/\/gitlab\.com\/([^/]+)\/(.+)$/); - if (match) { - owner = match[1]; - repo = match[2]; - apiUrl = `https://gitlab.com/api/v4/projects/${encodeURIComponent(`${owner}/${repo}`)}/merge_requests`; - } - } - - if (!apiUrl) { - setPullRequests([]); - return; - } - - // Get current user to filter PRs - const response = await fetch(`${apiUrl}?state=open`, { - headers: { - 'Authorization': `token ${credentials.password}`, - }, - }); - - if (!response.ok) { - throw new Error('Failed to fetch pull requests'); - } - - const data = await response.json(); - - // Filter PRs authored by current user (based on credentials username) - const userPRs = Array.isArray(data) - ? data.filter((pr: any) => - pr.user?.login === credentials.username || - pr.author?.username === credentials.username - ) - : []; - - setPullRequests(userPRs); - } catch (err) { - console.error('Failed to load pull requests:', err); - setPullRequests([]); - } finally { - setIsLoadingPRs(false); - } - }, [remoteUrl, settings.credentials]); - - useEffect(() => { - if (open && remoteUrl) { - loadPullRequests(); - } - }, [open, remoteUrl, loadPullRequests]); - - const handleSync = async () => { - setIsSyncing(true); - try { - const credentials = findCredentialsForRepo(remoteUrl || '', settings.credentials); - - // Pull - await git.pull({ - dir: projectPath, - author: { - name: credentials?.username || 'shakespeare.diy', - email: credentials?.email || 'assistant@shakespeare.diy', - }, - onAuth: () => credentials || undefined, - }); - - // Push - await git.push({ - dir: projectPath, - onAuth: () => credentials || undefined, - }); - - toast({ - title: 'Sync successful', - description: 'Your changes have been synchronized', - }); - - refetchGitStatus(); - } catch (err) { - toast({ - title: 'Sync failed', - description: err instanceof Error ? err.message : 'Unknown error', - variant: 'destructive', - }); - } finally { - setIsSyncing(false); - } - }; - const handleBranchChange = () => { + // Refetch git status when branches change refetchGitStatus(); }; - const formatDate = (dateStr: string) => { - const date = new Date(dateStr); - const now = new Date(); - const diffMs = now.getTime() - date.getTime(); - const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24)); - - if (diffDays === 0) return 'today'; - if (diffDays === 1) return 'yesterday'; - if (diffDays < 7) return `${diffDays} days ago`; - return date.toLocaleDateString(); - }; - return ( <> @@ -232,201 +72,94 @@ export function GitManagementDialog({ - Repository + Git Management - -
- {/* Section 1: Git URL, Current Branch, Sync Status, Merge Branch */} - - - Repository Info - - - {/* Git URL */} -
-
Git URL
-
- {remoteUrl || 'No remote configured'} -
-
- - {/* Current Branch */} -
-
Current Branch
-
- - {gitStatus?.currentBranch || 'Unknown'} - - -
-
- - {/* Branch Manager (collapsible) */} - {showBranchManager && ( -
- -
- )} - - {/* Sync Status */} + {/* Tabs Container - takes remaining space */} +
+ + {/* Fixed Tab List */} +
+ + + + Branches + + + + Changes + + + + Compare + {remoteUrl && ( -
-
Sync Status
-
- - {gitStatus && ( -
- {gitStatus.modified + gitStatus.added + gitStatus.deleted > 0 - ? `${gitStatus.modified + gitStatus.added + gitStatus.deleted} changes` - : 'Up to date'} -
- )} -
-
+ + + Pull Request + )} +
+
- {/* Merge Branch Action */} -
- + +
+ { - refetchGitStatus(); - setIsMergeDialogOpen(false); - }} + onBranchChange={handleBranchChange} />
- - +
+ - {/* Section 2: Pull Requests */} - {remoteUrl && ( - - -
- Pull Requests - -
-
- - {/* PR Form (collapsible) */} - {showPRForm && ( -
- -
- )} - - {/* Your Open PRs */} -
-
Your Open PRs
- {isLoadingPRs ? ( -
- -
- ) : pullRequests.length > 0 ? ( -
- {pullRequests.map((pr) => ( -
-
- {pr.state === 'open' && } - {pr.state === 'merged' && } - {pr.state === 'closed' && } -
-
-
{pr.title}
-
- #{pr.number} - • - {pr.head.ref} → {pr.base.ref} - • - {formatDate(pr.created_at)} -
-
- -
- ))} -
- ) : ( -
- -

No open pull requests

-
- )} -
-
-
- )} - - {/* Section 3: Working Directory */} - - - Working Directory - - + +
- - -
- +
+ + + + +
+ +
+
+
+ + {remoteUrl && ( + + +
+ +
+
+
+ )} +
+