mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Enhance download options and improve git error handling (#100)
* Fix download dialog to show gitignored paths with opt-in selection - Add getIgnoredPathsList API to detect gitignored files from git root - Fix git check-ignore to run from proper git root directory - Add ignored paths checkboxes in download dialog for opt-in inclusion - Support includeGit and includePaths options in download endpoints - Fix dialog button event handling to prevent page reload * Add clone timeout and improve git error handling * Refactor path extraction in download-zip endpoint
This commit is contained in:
1 parent
a02f7a2e98
commit
eccd49e877
12 files changed
+542
-121
No files matched your search
@@ -33,15 +33,15 @@ export const FileBrowserSheet = memo(function FileBrowserSheet({ isOpen, onClose
|
||||
const [currentPath, setCurrentPath] = useState<string>(basePath || '.')
|
||||
const [downloadDialog, setDownloadDialog] = useState<{ type: 'directory' | 'repository' } | null>(null)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
|
||||
const { bind, swipeStyles } = useSwipeBack(onClose, {
|
||||
enabled: isOpen && !isEditing,
|
||||
})
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
return bind(containerRef.current)
|
||||
}, [bind])
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
setShouldRender(true)
|
||||
@@ -75,14 +75,14 @@ export const FileBrowserSheet = memo(function FileBrowserSheet({ isOpen, onClose
|
||||
}
|
||||
}, [repoName, basePath])
|
||||
|
||||
const handleDownloadDirectory = useCallback(async () => {
|
||||
const handleDownloadDirectory = useCallback(async (options: { includeGit?: boolean, includePaths?: string[] }) => {
|
||||
if (!currentPath) return
|
||||
await downloadDirectoryAsZip(currentPath)
|
||||
await downloadDirectoryAsZip(currentPath, options)
|
||||
}, [currentPath])
|
||||
|
||||
const handleDownloadRepo = useCallback(async () => {
|
||||
const handleDownloadRepo = useCallback(async (options: { includeGit?: boolean, includePaths?: string[] }) => {
|
||||
if (!repoId || !repoName) return
|
||||
await downloadRepo(repoId, repoName)
|
||||
await downloadRepo(repoId, repoName, options)
|
||||
}, [repoId, repoName])
|
||||
|
||||
const handleOpenDownloadDialog = (type: 'directory' | 'repository') => {
|
||||
@@ -116,7 +116,7 @@ export const FileBrowserSheet = memo(function FileBrowserSheet({ isOpen, onClose
|
||||
if (!isOpen && !shouldRender) return null
|
||||
|
||||
return (
|
||||
<div
|
||||
<div
|
||||
ref={containerRef}
|
||||
className="fixed inset-0 z-50"
|
||||
style={{
|
||||
@@ -193,6 +193,7 @@ export const FileBrowserSheet = memo(function FileBrowserSheet({ isOpen, onClose
|
||||
? 'This will create a ZIP archive of the current directory and all its contents.'
|
||||
: 'This will create a ZIP archive of the entire repository.'}
|
||||
itemName={downloadDialog?.type === 'directory' ? currentPath.split('/').pop() || 'Directory' : repoName || 'Repository'}
|
||||
targetPath={downloadDialog?.type === 'directory' ? currentPath : basePath}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -20,6 +20,7 @@ interface RepoCardProps {
|
||||
cloneStatus: string;
|
||||
isWorktree?: boolean;
|
||||
isLocal?: boolean;
|
||||
fullPath?: string;
|
||||
};
|
||||
onDelete: (id: number) => void;
|
||||
isDeleting: boolean;
|
||||
@@ -39,8 +40,8 @@ export function RepoCard({
|
||||
const navigate = useNavigate();
|
||||
const [showDownloadDialog, setShowDownloadDialog] = useState(false);
|
||||
const [showSourceControl, setShowSourceControl] = useState(false);
|
||||
|
||||
const repoName = repo.repoUrl
|
||||
|
||||
const repoName = repo.repoUrl
|
||||
? repo.repoUrl.split("/").slice(-1)[0].replace(".git", "")
|
||||
: repo.localPath || "Local Repo";
|
||||
const branchToDisplay = gitStatus?.branch || repo.currentBranch || repo.branch;
|
||||
@@ -64,9 +65,9 @@ export function RepoCard({
|
||||
action();
|
||||
};
|
||||
|
||||
const handleDownload = async () => {
|
||||
const handleDownload = async (options: { includeGit?: boolean, includePaths?: string[] }) => {
|
||||
try {
|
||||
await downloadRepo(repo.id, repoName);
|
||||
await downloadRepo(repo.id, repoName, options);
|
||||
showToast.success("Download complete");
|
||||
} catch (error: unknown) {
|
||||
showToast.error(error instanceof Error ? error.message : "Download failed");
|
||||
@@ -88,7 +89,7 @@ export function RepoCard({
|
||||
<div>
|
||||
<div className="flex items-start gap-3 mb-1">
|
||||
{onSelect && (
|
||||
<div
|
||||
<div
|
||||
onClick={(e) => handleActionClick(e, () => onSelect(repo.id, !isSelected))}
|
||||
>
|
||||
<Checkbox
|
||||
@@ -206,6 +207,7 @@ export function RepoCard({
|
||||
title="Download Repository"
|
||||
description="This will create a ZIP archive of the entire repository."
|
||||
itemName={repoName}
|
||||
targetPath={repo.fullPath}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react'
|
||||
import { useState, useEffect } from 'react'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -8,15 +8,18 @@ import {
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Download, Loader2, Archive } from 'lucide-react'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { Download, Loader2, Archive, Folder } from 'lucide-react'
|
||||
import { getIgnoredPaths } from '@/api/files'
|
||||
|
||||
interface DownloadDialogProps {
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
onDownload: () => Promise<void>
|
||||
onDownload: (options: { includeGit?: boolean, includePaths?: string[] }) => Promise<void>
|
||||
title: string
|
||||
description: string
|
||||
itemName: string
|
||||
targetPath?: string
|
||||
}
|
||||
|
||||
export function DownloadDialog({
|
||||
@@ -26,15 +29,66 @@ export function DownloadDialog({
|
||||
title,
|
||||
description,
|
||||
itemName,
|
||||
targetPath,
|
||||
}: DownloadDialogProps) {
|
||||
const [isDownloading, setIsDownloading] = useState(false)
|
||||
const [isConfirmed, setIsConfirmed] = useState(false)
|
||||
const [isLoadingIgnored, setIsLoadingIgnored] = useState(false)
|
||||
const [ignoredPaths, setIgnoredPaths] = useState<string[]>([])
|
||||
const [ignoredPathsError, setIgnoredPathsError] = useState<string | null>(null)
|
||||
const [includeAll, setIncludeAll] = useState(false)
|
||||
const [selectedPaths, setSelectedPaths] = useState<Set<string>>(new Set())
|
||||
|
||||
const handleConfirm = async () => {
|
||||
useEffect(() => {
|
||||
if (open && targetPath) {
|
||||
setIsLoadingIgnored(true)
|
||||
setIgnoredPathsError(null)
|
||||
getIgnoredPaths(targetPath)
|
||||
.then(response => {
|
||||
setIgnoredPaths(response.ignoredPaths)
|
||||
setIsLoadingIgnored(false)
|
||||
})
|
||||
.catch((error) => {
|
||||
setIgnoredPathsError(error.message || 'Failed to load ignored paths')
|
||||
setIsLoadingIgnored(false)
|
||||
})
|
||||
}
|
||||
}, [open, targetPath])
|
||||
|
||||
useEffect(() => {
|
||||
if (includeAll) {
|
||||
setSelectedPaths(new Set(ignoredPaths))
|
||||
}
|
||||
}, [includeAll, ignoredPaths])
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedPaths.size === ignoredPaths.length && !includeAll) {
|
||||
setIncludeAll(true)
|
||||
} else if (selectedPaths.size < ignoredPaths.length && includeAll) {
|
||||
setIncludeAll(false)
|
||||
}
|
||||
}, [selectedPaths.size, ignoredPaths.length, includeAll])
|
||||
|
||||
const handleCheckboxChange = (path: string, checked: boolean) => {
|
||||
const newSelected = new Set(selectedPaths)
|
||||
if (checked) {
|
||||
newSelected.add(path)
|
||||
} else {
|
||||
newSelected.delete(path)
|
||||
}
|
||||
setSelectedPaths(newSelected)
|
||||
setIncludeAll(newSelected.size === ignoredPaths.length)
|
||||
}
|
||||
|
||||
const handleConfirm = async (e: React.MouseEvent) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
setIsConfirmed(true)
|
||||
setIsDownloading(true)
|
||||
try {
|
||||
await onDownload()
|
||||
const includeGit = selectedPaths.has('.git/')
|
||||
const includePaths = Array.from(selectedPaths).filter(p => p !== '.git/')
|
||||
await onDownload({ includeGit, includePaths })
|
||||
} catch (error) {
|
||||
console.error('Download failed:', error)
|
||||
} finally {
|
||||
@@ -44,15 +98,23 @@ export function DownloadDialog({
|
||||
}
|
||||
}
|
||||
|
||||
const handleCancel = () => {
|
||||
const handleCancel = (e?: React.MouseEvent) => {
|
||||
e?.preventDefault()
|
||||
e?.stopPropagation()
|
||||
if (isDownloading) return
|
||||
onOpenChange(false)
|
||||
setIsConfirmed(false)
|
||||
}
|
||||
|
||||
const handleDialogOpenChange = (open: boolean) => {
|
||||
if (!open) {
|
||||
handleCancel()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleCancel}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<Dialog open={open} onOpenChange={handleDialogOpenChange}>
|
||||
<DialogContent className="sm:max-w-md max-h-[80vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
{isDownloading ? (
|
||||
@@ -70,6 +132,62 @@ export function DownloadDialog({
|
||||
</DialogDescription>
|
||||
)}
|
||||
|
||||
{!isDownloading && !isLoadingIgnored && ignoredPaths.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<div
|
||||
className="flex items-center space-x-2 cursor-pointer"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
setIncludeAll(!includeAll)
|
||||
}}
|
||||
>
|
||||
<Checkbox
|
||||
id="download-all"
|
||||
checked={includeAll}
|
||||
onCheckedChange={() => {}}
|
||||
/>
|
||||
<span className="text-sm font-medium">
|
||||
Download All
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2 pl-6">
|
||||
{ignoredPaths.map(path => (
|
||||
<div
|
||||
key={path}
|
||||
className="flex items-center space-x-2 cursor-pointer"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleCheckboxChange(path, !selectedPaths.has(path))
|
||||
}}
|
||||
>
|
||||
<Checkbox
|
||||
id={`path-${path}`}
|
||||
checked={selectedPaths.has(path)}
|
||||
onCheckedChange={() => {}}
|
||||
/>
|
||||
<span className="text-sm text-muted-foreground flex items-center gap-2">
|
||||
<Folder className="w-4 h-4" />
|
||||
{path}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isDownloading && isLoadingIgnored && (
|
||||
<div className="flex items-center justify-center py-4">
|
||||
<Loader2 className="w-5 h-5 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isDownloading && ignoredPathsError && (
|
||||
<div className="p-3 bg-destructive/10 rounded-md">
|
||||
<p className="text-sm text-destructive">{ignoredPathsError}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-3 p-3 bg-muted rounded-md">
|
||||
<Archive className="w-8 h-8 text-muted-foreground" />
|
||||
<div className="flex-1 min-w-0">
|
||||
@@ -96,10 +214,10 @@ export function DownloadDialog({
|
||||
<DialogFooter >
|
||||
{!isDownloading && !isConfirmed && (
|
||||
<div className='flex gap-2 w-full'>
|
||||
<Button variant="outline" onClick={handleCancel} className="flex-1">
|
||||
<Button type="button" variant="outline" onClick={handleCancel} className="flex-1">
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={handleConfirm} className="gap-2 flex-1">
|
||||
<Button type="button" onClick={handleConfirm} className="gap-2 flex-1">
|
||||
<Download className="w-4 h-4" />
|
||||
Download
|
||||
</Button>
|
||||
|
||||
Reference in new issue
Block a user