Fix linter issues

This commit is contained in:
Alex Gleason committed 2025-10-14 16:31:34 -05:00
1 parent f0f40894d2
commit f31ca89b4f
7 files changed
+520 -569

No files matched your search

+11 -11
View File
@@ -3810,8 +3810,8 @@
"version": "1.26.5",
"resolved": "https://registry.npmjs.org/@types/prismjs/-/prismjs-1.26.5.tgz",
"integrity": "sha512-AUZTa7hQ2KY5L7AmtSiqxlhWxb4ina0yd8hNbl4TWuqnv/pFP0nDMb3YrfSBf4hJVGLh2YEIBfKaBW/9UEl6IQ==",
"license": "MIT",
"dev": true
"dev": true,
"license": "MIT"
},
"node_modules/@types/prop-types": {
"version": "15.7.14",
@@ -9835,6 +9835,15 @@
"url": "https://github.com/sponsors/dcastil"
}
},
"node_modules/string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"license": "MIT",
"dependencies": {
"safe-buffer": "~5.2.0"
}
},
"node_modules/string-width": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
@@ -9894,15 +9903,6 @@
"node": ">=8"
}
},
"node_modules/string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"license": "MIT",
"dependencies": {
"safe-buffer": "~5.2.0"
}
},
"node_modules/stringify-entities": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz",
+383 -384
View File
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useCallback } from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { Button } from '@/components/ui/button';
import {
@@ -21,7 +21,6 @@ import { ScrollArea } from '@/components/ui/scroll-area';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import {
Select,
SelectContent,
@@ -104,14 +103,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
}
}, [gitStatus?.remotes]);
// Load branches when dialog opens
useEffect(() => {
if (open && gitStatus?.isGitRepo) {
loadBranches();
}
}, [open, gitStatus?.isGitRepo]);
const loadBranches = async () => {
const loadBranches = useCallback(async () => {
setIsLoadingBranches(true);
try {
const localBranches = await git.listBranches({ dir: projectPath });
@@ -121,7 +113,14 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
} finally {
setIsLoadingBranches(false);
}
};
}, [git, projectPath]);
// Load branches when dialog opens
useEffect(() => {
if (open && gitStatus?.isGitRepo) {
loadBranches();
}
}, [open, gitStatus?.isGitRepo, loadBranches]);
const handleSwitchBranch = async (branchName: string) => {
setIsSwitchingBranch(true);
@@ -706,390 +705,390 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
</div>
</DialogHeader>
<div className="flex-1 min-h-0 overflow-hidden px-6 pb-6">
<ScrollArea className="h-full">
<div className="space-y-4 pr-4">
{/* URL Configuration */}
{gitStatus?.isGitRepo && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Git URL</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex gap-2">
<div className="flex-1">
<Label htmlFor="origin-url" className="sr-only">
<div className="flex-1 min-h-0 overflow-hidden px-6 pb-6">
<ScrollArea className="h-full">
<div className="space-y-4 pr-4">
{/* URL Configuration */}
{gitStatus?.isGitRepo && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Git URL</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex gap-2">
<div className="flex-1">
<Label htmlFor="origin-url" className="sr-only">
URL
</Label>
<Input
id="origin-url"
placeholder="https://github.com/username/repository.git"
value={originUrl}
onChange={(e) => setOriginUrl(e.target.value)}
disabled={isSavingOrigin}
/>
</div>
<Button
onClick={handleSaveOrigin}
disabled={isSavingOrigin}
variant="outline"
size="sm"
className="h-10 shrink-0"
>
{isSavingOrigin ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Save className="h-4 w-4 mr-2" />
)}
{isSavingOrigin ? 'Saving...' : 'Save'}
</Button>
</div>
{/* 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 (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
Invalid URL format. Enter an https URL.
</AlertDescription>
</Alert>
);
}
// Check for unsupported protocols
if (protocol !== 'https:' && protocol !== 'nostr:') {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
The {protocol.replace(':', '')} URL type is not supported. Enter an https URL.
</AlertDescription>
</Alert>
);
}
// For nostr protocol, only show warning if user is not logged in
if (protocol === 'nostr:' && !user) {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
You are not logged into Nostr. Push & pull might not work unless you{' '}
<button
onClick={() => navigate('/settings/nostr')}
className="underline hover:no-underline font-medium text-amber-700 dark:text-amber-300"
>
log in
</button>.
</AlertDescription>
</Alert>
);
}
// For https protocol, show warning if no credentials
if (protocol === 'https:') {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
You are not logged into {hostname}. Push & pull might not work unless you{' '}
<button
onClick={() => navigate('/settings/git')}
className="underline hover:no-underline font-medium text-amber-700 dark:text-amber-300"
>
log in
</button>.
</AlertDescription>
</Alert>
);
}
return null;
})()
)}
</CardContent>
</Card>
)}
{/* Branch Selector */}
{gitStatus?.isGitRepo && gitStatus.currentBranch && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Current Branch</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex gap-2">
<Select
value={gitStatus.currentBranch}
onValueChange={handleSwitchBranch}
disabled={isSwitchingBranch || isLoadingBranches}
>
<SelectTrigger className="flex-1">
<SelectValue>
{isSwitchingBranch ? (
<span className="flex items-center gap-2">
<Loader2 className="h-4 w-4 animate-spin" />
Switching...
</span>
) : (
<span className="flex items-center gap-2">
<GitBranch className="h-4 w-4" />
{gitStatus.currentBranch}
</span>
)}
</SelectValue>
</SelectTrigger>
<SelectContent>
{branches.map((branch) => (
<SelectItem key={branch} value={branch}>
<span className="flex items-center gap-2">
{branch === gitStatus.currentBranch && (
<CheckCircle className="h-4 w-4 text-primary" />
)}
{branch}
</span>
</SelectItem>
))}
</SelectContent>
</Select>
<Button
variant="outline"
size="sm"
className="shrink-0"
onClick={() => setIsCreateBranchDialogOpen(true)}
disabled={isSwitchingBranch}
>
<Plus className="h-4 w-4 mr-2" />
New
</Button>
</div>
</CardContent>
</Card>
)}
{/* Sync Status */}
{gitStatus?.isGitRepo && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Sync Status</CardTitle>
</CardHeader>
<CardContent>
<div className="flex items-center gap-2 mb-4">
<syncStatus.icon className={cn("h-4 w-4", syncStatus.color)} />
<span className={cn("text-sm font-medium", syncStatus.color)}>
{syncStatus.text}
</span>
</div>
{gitStatus.remotes.length > 0 && (
<div className="flex gap-2">
<Button
onClick={handlePull}
disabled={isPulling || isPushing || isPushingToNostr}
variant="outline"
size="sm"
className="flex-1"
>
{isPulling ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Download className="h-4 w-4 mr-2" />
)}
{isPulling ? 'Pulling...' : 'Pull'}
</Button>
<Button
onClick={handlePush}
disabled={isPushing || isPulling || isPushingToNostr || gitStatus.ahead === 0}
variant="outline"
size="sm"
className="flex-1"
>
{isPushing ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Upload className="h-4 w-4 mr-2" />
)}
{isPushing ? 'Pushing...' : 'Push'}
</Button>
</div>
)}
{/* Push to Nostr button when no remote is configured and user is logged in */}
{gitStatus.remotes.length === 0 && user && (
<div className="flex gap-2">
<Button
onClick={handlePushToNostr}
disabled={isPushingToNostr || isPushing || isPulling}
variant="outline"
size="sm"
className="flex-1"
>
{isPushingToNostr ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Zap className="h-4 w-4 mr-2" />
)}
{isPushingToNostr ? 'Publishing to Nostr...' : 'Push to Nostr'}
</Button>
</div>
)}
</CardContent>
</Card>
)}
{/* Branch Operations */}
{gitStatus?.isGitRepo && gitStatus.currentBranch && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Branch Operations</CardTitle>
</CardHeader>
<CardContent className="flex gap-2">
<MergeDialog
projectId={projectId}
currentBranch={gitStatus.currentBranch}
onMergeComplete={() => refetchGitStatus()}
/>
{gitStatus.remotes.length > 0 && originUrl && (
<PullRequestDialog
projectId={projectId}
currentBranch={gitStatus.currentBranch}
remoteUrl={originUrl}
/>
)}
</CardContent>
</Card>
)}
{/* Working Directory Changes */}
{gitStatus?.isGitRepo && gitStatus.changedFiles.length > 0 && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Working Directory Changes</CardTitle>
<CardDescription>
{gitStatus.changedFiles.length} file{gitStatus.changedFiles.length !== 1 ? 's' : ''} with changes
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-2">
{gitStatus.changedFiles.map((file, index) => (
<div
key={index}
className="flex items-center gap-2 p-2 rounded-md border bg-muted/20"
>
{getFileStatusIcon(file.status)}
<span className="font-mono text-sm flex-1 truncate">
{file.filepath}
</span>
<Badge
</Label>
<Input
id="origin-url"
placeholder="https://github.com/username/repository.git"
value={originUrl}
onChange={(e) => setOriginUrl(e.target.value)}
disabled={isSavingOrigin}
/>
</div>
<Button
onClick={handleSaveOrigin}
disabled={isSavingOrigin}
variant="outline"
className={cn("text-xs", getFileStatusColor(file.status))}
size="sm"
className="h-10 shrink-0"
>
{file.status}
</Badge>
{isSavingOrigin ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Save className="h-4 w-4 mr-2" />
)}
{isSavingOrigin ? 'Saving...' : 'Save'}
</Button>
</div>
))}
</div>
</CardContent>
</Card>
)}
{/* Clean Working Directory */}
{gitStatus?.isGitRepo && gitStatus.changedFiles.length === 0 && (
<Card>
<CardContent className="py-6">
<div className="text-center text-muted-foreground">
<CheckCircle className="h-8 w-8 mx-auto mb-2 text-green-500" />
<p>Working directory is clean</p>
<p className="text-xs">No uncommitted changes</p>
</div>
</CardContent>
</Card>
)}
</div>
</ScrollArea>
</div>
{/* 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 (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
Invalid URL format. Enter an https URL.
</AlertDescription>
</Alert>
);
}
// Check for unsupported protocols
if (protocol !== 'https:' && protocol !== 'nostr:') {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
The {protocol.replace(':', '')} URL type is not supported. Enter an https URL.
</AlertDescription>
</Alert>
);
}
// For nostr protocol, only show warning if user is not logged in
if (protocol === 'nostr:' && !user) {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
You are not logged into Nostr. Push & pull might not work unless you{' '}
<button
onClick={() => navigate('/settings/nostr')}
className="underline hover:no-underline font-medium text-amber-700 dark:text-amber-300"
>
log in
</button>.
</AlertDescription>
</Alert>
);
}
// For https protocol, show warning if no credentials
if (protocol === 'https:') {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
You are not logged into {hostname}. Push & pull might not work unless you{' '}
<button
onClick={() => navigate('/settings/git')}
className="underline hover:no-underline font-medium text-amber-700 dark:text-amber-300"
>
log in
</button>.
</AlertDescription>
</Alert>
);
}
return null;
})()
)}
</CardContent>
</Card>
)}
{/* Branch Selector */}
{gitStatus?.isGitRepo && gitStatus.currentBranch && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Current Branch</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex gap-2">
<Select
value={gitStatus.currentBranch}
onValueChange={handleSwitchBranch}
disabled={isSwitchingBranch || isLoadingBranches}
>
<SelectTrigger className="flex-1">
<SelectValue>
{isSwitchingBranch ? (
<span className="flex items-center gap-2">
<Loader2 className="h-4 w-4 animate-spin" />
Switching...
</span>
) : (
<span className="flex items-center gap-2">
<GitBranch className="h-4 w-4" />
{gitStatus.currentBranch}
</span>
)}
</SelectValue>
</SelectTrigger>
<SelectContent>
{branches.map((branch) => (
<SelectItem key={branch} value={branch}>
<span className="flex items-center gap-2">
{branch === gitStatus.currentBranch && (
<CheckCircle className="h-4 w-4 text-primary" />
)}
{branch}
</span>
</SelectItem>
))}
</SelectContent>
</Select>
<Button
variant="outline"
size="sm"
className="shrink-0"
onClick={() => setIsCreateBranchDialogOpen(true)}
disabled={isSwitchingBranch}
>
<Plus className="h-4 w-4 mr-2" />
New
</Button>
</div>
</CardContent>
</Card>
)}
{/* Sync Status */}
{gitStatus?.isGitRepo && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Sync Status</CardTitle>
</CardHeader>
<CardContent>
<div className="flex items-center gap-2 mb-4">
<syncStatus.icon className={cn("h-4 w-4", syncStatus.color)} />
<span className={cn("text-sm font-medium", syncStatus.color)}>
{syncStatus.text}
</span>
</div>
{gitStatus.remotes.length > 0 && (
<div className="flex gap-2">
<Button
onClick={handlePull}
disabled={isPulling || isPushing || isPushingToNostr}
variant="outline"
size="sm"
className="flex-1"
>
{isPulling ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Download className="h-4 w-4 mr-2" />
)}
{isPulling ? 'Pulling...' : 'Pull'}
</Button>
<Button
onClick={handlePush}
disabled={isPushing || isPulling || isPushingToNostr || gitStatus.ahead === 0}
variant="outline"
size="sm"
className="flex-1"
>
{isPushing ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Upload className="h-4 w-4 mr-2" />
)}
{isPushing ? 'Pushing...' : 'Push'}
</Button>
</div>
)}
{/* Push to Nostr button when no remote is configured and user is logged in */}
{gitStatus.remotes.length === 0 && user && (
<div className="flex gap-2">
<Button
onClick={handlePushToNostr}
disabled={isPushingToNostr || isPushing || isPulling}
variant="outline"
size="sm"
className="flex-1"
>
{isPushingToNostr ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Zap className="h-4 w-4 mr-2" />
)}
{isPushingToNostr ? 'Publishing to Nostr...' : 'Push to Nostr'}
</Button>
</div>
)}
</CardContent>
</Card>
)}
{/* Branch Operations */}
{gitStatus?.isGitRepo && gitStatus.currentBranch && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Branch Operations</CardTitle>
</CardHeader>
<CardContent className="flex gap-2">
<MergeDialog
projectId={projectId}
currentBranch={gitStatus.currentBranch}
onMergeComplete={() => refetchGitStatus()}
/>
{gitStatus.remotes.length > 0 && originUrl && (
<PullRequestDialog
projectId={projectId}
currentBranch={gitStatus.currentBranch}
remoteUrl={originUrl}
/>
)}
</CardContent>
</Card>
)}
{/* Working Directory Changes */}
{gitStatus?.isGitRepo && gitStatus.changedFiles.length > 0 && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Working Directory Changes</CardTitle>
<CardDescription>
{gitStatus.changedFiles.length} file{gitStatus.changedFiles.length !== 1 ? 's' : ''} with changes
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-2">
{gitStatus.changedFiles.map((file, index) => (
<div
key={index}
className="flex items-center gap-2 p-2 rounded-md border bg-muted/20"
>
{getFileStatusIcon(file.status)}
<span className="font-mono text-sm flex-1 truncate">
{file.filepath}
</span>
<Badge
variant="outline"
className={cn("text-xs", getFileStatusColor(file.status))}
>
{file.status}
</Badge>
</div>
))}
</div>
</CardContent>
</Card>
)}
{/* Clean Working Directory */}
{gitStatus?.isGitRepo && gitStatus.changedFiles.length === 0 && (
<Card>
<CardContent className="py-6">
<div className="text-center text-muted-foreground">
<CheckCircle className="h-8 w-8 mx-auto mb-2 text-green-500" />
<p>Working directory is clean</p>
<p className="text-xs">No uncommitted changes</p>
</div>
</CardContent>
</Card>
)}
</div>
</ScrollArea>
</div>
</DialogContent>
</Dialog>
{/* Advanced Git Management Dialog */}
<GitManagementDialog
projectId={projectId}
open={isGitManagementOpen}
onOpenChange={setIsGitManagementOpen}
/>
{/* Advanced Git Management Dialog */}
<GitManagementDialog
projectId={projectId}
open={isGitManagementOpen}
onOpenChange={setIsGitManagementOpen}
/>
{/* Create Branch Dialog */}
<Dialog open={isCreateBranchDialogOpen} onOpenChange={setIsCreateBranchDialogOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>Create New Branch</DialogTitle>
<DialogDescription>
{/* Create Branch Dialog */}
<Dialog open={isCreateBranchDialogOpen} onOpenChange={setIsCreateBranchDialogOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>Create New Branch</DialogTitle>
<DialogDescription>
Create a new branch from {gitStatus?.currentBranch || 'current HEAD'}
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-2">
<Label htmlFor="new-branch-name">Branch Name</Label>
<Input
id="new-branch-name"
placeholder="feature/my-new-feature"
value={newBranchName}
onChange={(e) => setNewBranchName(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' && !isCreatingBranch) {
handleCreateBranch();
}
}}
autoFocus
/>
</div>
{gitStatus?.currentBranch && (
<div className="text-sm text-muted-foreground">
Creating from: <span className="font-medium">{gitStatus.currentBranch}</span>
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-2">
<Label htmlFor="new-branch-name">Branch Name</Label>
<Input
id="new-branch-name"
placeholder="feature/my-new-feature"
value={newBranchName}
onChange={(e) => setNewBranchName(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' && !isCreatingBranch) {
handleCreateBranch();
}
}}
autoFocus
/>
</div>
)}
</div>
<div className="flex justify-end gap-2">
<Button
variant="outline"
onClick={() => {
setIsCreateBranchDialogOpen(false);
setNewBranchName('');
}}
disabled={isCreatingBranch}
>
Cancel
</Button>
<Button onClick={handleCreateBranch} disabled={isCreatingBranch}>
{isCreatingBranch ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
Creating...
</>
) : (
<>
<Plus className="h-4 w-4 mr-2" />
Create Branch
</>
{gitStatus?.currentBranch && (
<div className="text-sm text-muted-foreground">
Creating from: <span className="font-medium">{gitStatus.currentBranch}</span>
</div>
)}
</Button>
</div>
</DialogContent>
</Dialog>
</>
</div>
<div className="flex justify-end gap-2">
<Button
variant="outline"
onClick={() => {
setIsCreateBranchDialogOpen(false);
setNewBranchName('');
}}
disabled={isCreatingBranch}
>
Cancel
</Button>
<Button onClick={handleCreateBranch} disabled={isCreatingBranch}>
{isCreatingBranch ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
Creating...
</>
) : (
<>
<Plus className="h-4 w-4 mr-2" />
Create Branch
</>
)}
</Button>
</div>
</DialogContent>
</Dialog>
</>
);
}
+7 -10
View File
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useCallback } from 'react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
@@ -20,14 +20,11 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Badge } from '@/components/ui/badge';
import {
GitBranch,
Plus,
Trash2,
GitMerge,
GitCompare,
Check,
Loader2,
ArrowUpRight,
@@ -65,11 +62,7 @@ export function BranchManager({ projectId, currentBranch, onBranchChange }: Bran
const { toast } = useToast();
const projectPath = `/projects/${projectId}`;
useEffect(() => {
loadBranches();
}, [projectId, currentBranch]);
const loadBranches = async () => {
const loadBranches = useCallback(async () => {
setIsLoading(true);
try {
// Get local branches
@@ -150,7 +143,11 @@ export function BranchManager({ projectId, currentBranch, onBranchChange }: Bran
} finally {
setIsLoading(false);
}
};
}, [git, projectPath, toast]);
useEffect(() => {
loadBranches();
}, [projectId, currentBranch, loadBranches]);
const handleCreateBranch = async () => {
if (!newBranchName.trim()) {
+15 -18
View File
@@ -1,5 +1,4 @@
import { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import { useState, useEffect, useCallback } from 'react';
import {
Select,
SelectContent,
@@ -8,13 +7,11 @@ import {
SelectValue,
} from '@/components/ui/select';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { GitCompare, Loader2, GitCommit, FileIcon } from 'lucide-react';
import { useGit } from '@/hooks/useGit';
import { useToast } from '@/hooks/useToast';
import { DiffViewer } from './DiffViewer';
import { cn } from '@/lib/utils';
interface CompareViewProps {
projectId: string;
@@ -44,17 +41,7 @@ export function CompareView({ projectId }: CompareViewProps) {
const { toast } = useToast();
const projectPath = `/projects/${projectId}`;
useEffect(() => {
loadReferences();
}, [projectId]);
useEffect(() => {
if (baseRef && compareRef && baseRef !== compareRef) {
performComparison();
}
}, [baseRef, compareRef]);
const loadReferences = async () => {
const loadReferences = useCallback(async () => {
setIsLoading(true);
try {
// Get all branches
@@ -85,9 +72,9 @@ export function CompareView({ projectId }: CompareViewProps) {
} finally {
setIsLoading(false);
}
};
}, [git, projectPath, toast]);
const performComparison = async () => {
const performComparison = useCallback(async () => {
if (!baseRef || !compareRef) return;
setIsComparing(true);
@@ -158,7 +145,17 @@ export function CompareView({ projectId }: CompareViewProps) {
} finally {
setIsComparing(false);
}
};
}, [baseRef, compareRef, git, projectPath, toast]);
useEffect(() => {
loadReferences();
}, [projectId, loadReferences]);
useEffect(() => {
if (baseRef && compareRef && baseRef !== compareRef) {
performComparison();
}
}, [baseRef, compareRef, performComparison]);
const formatDate = (timestamp: number) => {
const date = new Date(timestamp * 1000);
+56 -94
View File
@@ -1,15 +1,8 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useCallback } from 'react';
import { Button } from '@/components/ui/button';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Badge } from '@/components/ui/badge';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
import {
FileIcon,
Plus,
@@ -25,14 +18,6 @@ import { useGit } from '@/hooks/useGit';
import { useFS } from '@/hooks/useFS';
import { useToast } from '@/hooks/useToast';
import { cn } from '@/lib/utils';
import Prism from 'prismjs';
import 'prismjs/components/prism-typescript';
import 'prismjs/components/prism-javascript';
import 'prismjs/components/prism-jsx';
import 'prismjs/components/prism-tsx';
import 'prismjs/components/prism-css';
import 'prismjs/components/prism-json';
import 'prismjs/components/prism-markdown';
interface DiffHunk {
oldStart: number;
@@ -76,58 +61,7 @@ export function DiffViewer({ projectId, compareFrom = 'HEAD', compareTo, filepat
const { toast } = useToast();
const projectPath = `/projects/${projectId}`;
useEffect(() => {
loadDiffs();
}, [projectId, compareFrom, compareTo, filepath]);
const loadDiffs = async () => {
setIsLoading(true);
try {
let files: string[] = [];
if (filepath) {
files = [filepath];
} else if (compareTo) {
// Compare two commits/branches
files = await getChangedFilesBetweenRefs(compareFrom, compareTo);
} else {
// Compare against working directory
const statusMatrix = await git.statusMatrix({ dir: projectPath });
files = statusMatrix
.filter(([, head, workdir]) => head !== workdir)
.map(([file]) => file);
}
const fileDiffs: FileDiff[] = [];
for (const file of files) {
try {
const diff = await generateFileDiff(file, compareFrom, compareTo);
if (diff) {
fileDiffs.push(diff);
}
} catch (error) {
console.warn(`Failed to generate diff for ${file}:`, error);
}
}
setDiffs(fileDiffs);
if (fileDiffs.length > 0 && !selectedFile) {
setSelectedFile(fileDiffs[0].filepath);
}
} catch (error) {
console.error('Failed to load diffs:', error);
toast({
title: 'Failed to load diffs',
description: error instanceof Error ? error.message : 'Unknown error',
variant: 'destructive',
});
} finally {
setIsLoading(false);
}
};
const getChangedFilesBetweenRefs = async (from: string, to: string): Promise<string[]> => {
const getChangedFilesBetweenRefs = useCallback(async (from: string, to: string): Promise<string[]> => {
// Get list of files from both refs and find differences
const filesFrom = await git.listFiles({ dir: projectPath, ref: from });
const filesTo = await git.listFiles({ dir: projectPath, ref: to });
@@ -158,9 +92,9 @@ export function DiffViewer({ projectId, compareFrom = 'HEAD', compareTo, filepat
}
return Array.from(changedFiles);
};
}, [git, projectPath]);
const generateFileDiff = async (
const generateFileDiff = useCallback(async (
file: string,
from: string,
to?: string
@@ -210,7 +144,7 @@ export function DiffViewer({ projectId, compareFrom = 'HEAD', compareTo, filepat
console.error(`Error generating diff for ${file}:`, error);
return null;
}
};
}, [git, projectPath, fs]);
const generateDiffHunks = (oldContent: string, newContent: string): DiffHunk[] => {
const oldLines = oldContent.split('\n');
@@ -342,28 +276,56 @@ export function DiffViewer({ projectId, compareFrom = 'HEAD', compareTo, filepat
return hunks;
};
const getLanguageFromFilepath = (filepath: string): string => {
const ext = filepath.split('.').pop()?.toLowerCase();
const languageMap: Record<string, string> = {
ts: 'typescript',
tsx: 'tsx',
js: 'javascript',
jsx: 'jsx',
css: 'css',
json: 'json',
md: 'markdown',
};
return languageMap[ext || ''] || 'javascript';
};
const highlightCode = (code: string, filepath: string): string => {
const loadDiffs = useCallback(async () => {
setIsLoading(true);
try {
const language = getLanguageFromFilepath(filepath);
return Prism.highlight(code, Prism.languages[language] || Prism.languages.javascript, language);
} catch {
return code;
let files: string[] = [];
if (filepath) {
files = [filepath];
} else if (compareTo) {
// Compare two commits/branches
files = await getChangedFilesBetweenRefs(compareFrom, compareTo);
} else {
// Compare against working directory
const statusMatrix = await git.statusMatrix({ dir: projectPath });
files = statusMatrix
.filter(([, head, workdir]) => head !== workdir)
.map(([file]) => file);
}
const fileDiffs: FileDiff[] = [];
for (const file of files) {
try {
const diff = await generateFileDiff(file, compareFrom, compareTo);
if (diff) {
fileDiffs.push(diff);
}
} catch (error) {
console.warn(`Failed to generate diff for ${file}:`, error);
}
}
setDiffs(fileDiffs);
if (fileDiffs.length > 0 && !selectedFile) {
setSelectedFile(fileDiffs[0].filepath);
}
} catch (error) {
console.error('Failed to load diffs:', error);
toast({
title: 'Failed to load diffs',
description: error instanceof Error ? error.message : 'Unknown error',
variant: 'destructive',
});
} finally {
setIsLoading(false);
}
};
}, [compareFrom, compareTo, filepath, git, projectPath, selectedFile, toast, getChangedFilesBetweenRefs, generateFileDiff]);
useEffect(() => {
loadDiffs();
}, [projectId, compareFrom, compareTo, filepath, loadDiffs]);
const copyHunkToClipboard = async (hunk: DiffHunk, index: number) => {
const hunkText = hunk.lines.map(line => line.content).join('\n');
@@ -504,7 +466,7 @@ export function DiffViewer({ projectId, compareFrom = 'HEAD', compareTo, filepat
);
}
function SplitDiffView({ hunk, filepath }: { hunk: DiffHunk; filepath: string }) {
function SplitDiffView({ hunk }: { hunk: DiffHunk; filepath: string }) {
return (
<div className="grid grid-cols-2 divide-x font-mono text-sm">
{/* Old (left) side */}
@@ -560,7 +522,7 @@ function SplitDiffView({ hunk, filepath }: { hunk: DiffHunk; filepath: string })
);
}
function UnifiedDiffView({ hunk, filepath }: { hunk: DiffHunk; filepath: string }) {
function UnifiedDiffView({ hunk }: { hunk: DiffHunk; filepath: string }) {
return (
<div className="font-mono text-sm">
{hunk.lines.map((line, i) => (
+20 -23
View File
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useCallback } from 'react';
import { Button } from '@/components/ui/button';
import {
Dialog,
@@ -26,13 +26,11 @@ import {
AlertCircle,
CheckCircle,
GitCommit,
FileIcon,
AlertTriangle,
} from 'lucide-react';
import { useGit } from '@/hooks/useGit';
import { useToast } from '@/hooks/useToast';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { cn } from '@/lib/utils';
import { useSearchParams } from 'react-router-dom';
interface MergeDialogProps {
projectId: string;
@@ -76,7 +74,6 @@ export function MergeDialog({
const { git } = useGit();
const { toast } = useToast();
const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams();
const projectPath = `/projects/${projectId}`;
@@ -86,21 +83,7 @@ export function MergeDialog({
}
}, [open]);
useEffect(() => {
if (isOpen) {
loadBranches();
}
}, [isOpen]);
useEffect(() => {
if (sourceBranch && currentBranch && sourceBranch !== currentBranch) {
loadMergePreview();
} else {
setMergePreview(null);
}
}, [sourceBranch, currentBranch]);
const loadBranches = async () => {
const loadBranches = useCallback(async () => {
setIsLoadingBranches(true);
try {
const localBranches = await git.listBranches({ dir: projectPath });
@@ -122,9 +105,9 @@ export function MergeDialog({
} finally {
setIsLoadingBranches(false);
}
};
}, [git, projectPath, currentBranch, toast]);
const loadMergePreview = async () => {
const loadMergePreview = useCallback(async () => {
if (!sourceBranch || !currentBranch) return;
setIsLoadingPreview(true);
@@ -200,7 +183,21 @@ export function MergeDialog({
} finally {
setIsLoadingPreview(false);
}
};
}, [sourceBranch, currentBranch, git, projectPath]);
useEffect(() => {
if (isOpen) {
loadBranches();
}
}, [isOpen, loadBranches]);
useEffect(() => {
if (sourceBranch && currentBranch && sourceBranch !== currentBranch) {
loadMergePreview();
} else {
setMergePreview(null);
}
}, [sourceBranch, currentBranch, loadMergePreview]);
const performMerge = async () => {
if (!sourceBranch || !currentBranch) return;
+28 -29
View File
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useCallback } from 'react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
@@ -33,7 +33,6 @@ import {
import { useGit } from '@/hooks/useGit';
import { useGitSettings } from '@/hooks/useGitSettings';
import { useToast } from '@/hooks/useToast';
import { cn } from '@/lib/utils';
import { findCredentialsForRepo } from '@/lib/gitCredentials';
interface PullRequestDialogProps {
@@ -80,12 +79,38 @@ export function PullRequestDialog({
}
}, [open]);
const loadRemoteBranches = useCallback(async () => {
setIsLoadingBranches(true);
try {
const branches = await git.listBranches({
dir: projectPath,
remote: 'origin',
});
setRemoteBranches(branches);
// Set default target branch
if (branches.includes('main')) {
setTargetBranch('main');
} else if (branches.includes('master')) {
setTargetBranch('master');
} else if (branches.length > 0) {
setTargetBranch(branches[0]);
}
} catch (err) {
console.warn('Failed to load remote branches:', err);
// Set default branches if we can't fetch
setRemoteBranches(['main', 'master', 'develop']);
} finally {
setIsLoadingBranches(false);
}
}, [git, projectPath]);
useEffect(() => {
if (isOpen && remoteUrl) {
parseRemoteUrl(remoteUrl);
loadRemoteBranches();
}
}, [isOpen, remoteUrl]);
}, [isOpen, remoteUrl, loadRemoteBranches]);
const parseRemoteUrl = (url: string) => {
setError(null);
@@ -161,32 +186,6 @@ export function PullRequestDialog({
}
};
const loadRemoteBranches = async () => {
setIsLoadingBranches(true);
try {
const branches = await git.listBranches({
dir: projectPath,
remote: 'origin',
});
setRemoteBranches(branches);
// Set default target branch
if (branches.includes('main')) {
setTargetBranch('main');
} else if (branches.includes('master')) {
setTargetBranch('master');
} else if (branches.length > 0) {
setTargetBranch(branches[0]);
}
} catch (err) {
console.warn('Failed to load remote branches:', err);
// Set default branches if we can't fetch
setRemoteBranches(['main', 'master', 'develop']);
} finally {
setIsLoadingBranches(false);
}
};
const createPullRequest = async () => {
if (!remoteInfo || !currentBranch) return;