cleanup v2

This commit is contained in:
Chad Curtis committed 2025-10-21 14:40:06 +00:00
1 parent e1da355392
commit 4be7f67cac
5 files changed
+193 -79

No files matched your search

+42 -57
View File
@@ -1,14 +1,15 @@
import React, { useState, useRef, useCallback } from 'react';
import React, { useState, useCallback } from 'react';
import { Button } from '@/components/ui/button';
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
import { Progress } from '@/components/ui/progress';
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
import { Upload, AlertTriangle, Trash2, CheckCircle, XCircle, Loader2, HardDrive } from 'lucide-react';
import { AlertTriangle, Trash2, CheckCircle, Loader2, HardDrive } from 'lucide-react';
import { useToast } from '@/hooks/useToast';
import { useFS } from '@/hooks/useFS';
import { cn } from '@/lib/utils';
import { importFullSystem, validateExportFile, type ImportProgress, type ImportValidation } from '@/lib/fullSystemImport';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { FileUploadArea } from '@/components/ui/file-upload-area';
interface FullSystemImportDialogProps {
onImport?: () => void;
@@ -53,7 +54,7 @@ export function FullSystemImportDialog({
importComplete: false
});
const fileInputRef = useRef<HTMLInputElement>(null);
const { toast } = useToast();
const { fs } = useFS();
@@ -116,10 +117,6 @@ export function FullSystemImportDialog({
}
}, []);
const handleClickUpload = () => {
fileInputRef.current?.click();
};
const handleFileRemove = () => {
updateState({ selectedFile: null, validation: null, error: null, importComplete: false });
};
@@ -204,7 +201,7 @@ export function FullSystemImportDialog({
className={cn("gap-2 text-destructive border-destructive hover:bg-destructive hover:text-destructive-foreground", className)}
>
<HardDrive className="h-4 w-4" />
Import Full System
Import System
</Button>
</DialogTrigger>
)}
@@ -213,59 +210,49 @@ export function FullSystemImportDialog({
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<HardDrive className="h-5 w-5 text-destructive" />
Import Complete System
Import System
</DialogTitle>
<DialogDescription>
Replace your entire workspace with a backup. This will permanently delete all current data.
Select a Shakespeare export file to replace your entire workspace.
</DialogDescription>
</DialogHeader>
<div className="space-y-4">
<Alert className="border-destructive/50 bg-destructive/5">
<AlertTriangle className="h-4 w-4 text-destructive" />
<AlertDescription className="text-destructive">
<strong>Warning:</strong> This will completely wipe your current workspace and replace it with imported data.
</AlertDescription>
</Alert>
{!state.isImporting && (
<Alert className="border-destructive/50 bg-destructive/5">
<AlertTriangle className="h-4 w-4 text-destructive" />
<AlertDescription className="text-destructive">
<strong>Warning:</strong> This action will <strong>completely replace</strong> your Shakespeare workspace with the imported data.
All current projects, AI settings, Git credentials, and preferences will be <strong>permanently deleted</strong>.
</AlertDescription>
</Alert>
)}
{!state.isImporting && !state.importComplete && (
<>
<div
className={cn(
"relative border-2 border-dashed rounded-lg p-6 text-center transition-colors cursor-pointer",
state.isDragOver ? "border-primary bg-primary/5" : "border-muted-foreground/25 hover:border-primary/50",
state.selectedFile && state.validation?.isValid && "border-green-500/50 bg-green-500/5",
state.selectedFile && state.validation && !state.validation.isValid && "border-destructive/50 bg-destructive/5"
)}
onClick={handleClickUpload}
<FileUploadArea
selectedFile={state.selectedFile}
isDragOver={state.isDragOver}
isValid={state.validation?.isValid ?? false}
onFileSelect={handleFileSelect}
onFileRemove={handleFileRemove}
onDragOver={handleDragOver}
onDragLeave={handleDragLeave}
onDrop={handleDrop}
disabled={state.isImporting}
accept=".zip"
className="mb-4"
>
<input
ref={fileInputRef}
type="file"
onChange={(e) => {
const files = e.target.files;
if (files && files.length > 0) {
handleFileSelect(files[0]);
}
}}
accept=".zip"
className="hidden"
disabled={state.isImporting}
/>
<div className="space-y-3">
<div className="flex justify-center">
{state.selectedFile ? (
state.validation?.isValid ? (
<CheckCircle className="h-8 w-8 text-green-600" />
) : (
<XCircle className="h-8 w-8 text-destructive" />
<Trash2 className="h-8 w-8 text-destructive" />
)
) : (
<Upload className="h-8 w-8 text-muted-foreground" />
<HardDrive className="h-8 w-8 text-muted-foreground" />
)}
</div>
@@ -298,7 +285,7 @@ export function FullSystemImportDialog({
)}
</div>
</div>
</div>
</FileUploadArea>
{state.validation && (
<div className="text-sm space-y-2 p-3 bg-muted rounded">
@@ -310,12 +297,6 @@ export function FullSystemImportDialog({
<span>Files:</span>
<span className="font-medium">{state.validation.totalFiles}</span>
</div>
<div className="flex justify-between">
<span>Valid:</span>
<span className={cn("font-medium", state.validation.isValid ? "text-green-600" : "text-destructive")}>
{state.validation.isValid ? 'Yes' : 'No'}
</span>
</div>
{state.validation.errors.length > 0 && (
<div className="text-xs text-destructive">
{state.validation.errors.slice(0, 2).join(', ')}
@@ -341,7 +322,7 @@ export function FullSystemImportDialog({
variant="destructive"
>
<Trash2 className="mr-2 h-4 w-4" />
Replace System
Replace Entire System
</Button>
</div>
</>
@@ -387,7 +368,7 @@ export function FullSystemImportDialog({
<AlertDialogHeader>
<AlertDialogTitle className="flex items-center gap-2">
<AlertTriangle className="h-5 w-5 text-destructive" />
Confirm System Replacement
Confirm Complete System Replacement
</AlertDialogTitle>
<AlertDialogDescription className="space-y-3">
<p>
@@ -397,23 +378,27 @@ export function FullSystemImportDialog({
<div className="bg-destructive/10 border border-destructive/20 rounded p-3">
<p className="text-sm font-medium text-destructive mb-2">This will permanently delete:</p>
<ul className="list-disc list-inside text-sm text-destructive space-y-1">
<li>All current projects and files</li>
<li>AI settings and API keys</li>
<li>Git credentials and preferences</li>
<li>All cached data</li>
<li>All current projects and their files</li>
<li>AI provider settings and API keys</li>
<li>Git credentials and repository settings</li>
<li>User preferences and theme settings</li>
<li>All cached data and temporary files</li>
</ul>
</div>
{state.validation && (
<div className="bg-green-50 dark:bg-green-950/20 border border-green-200 dark:border-green-800 rounded p-3">
<p className="text-sm font-medium text-green-800 dark:text-green-200">
Import will restore {state.validation.projectCount} projects and {state.validation.totalFiles} files
</p>
<p className="text-sm font-medium text-green-800 dark:text-green-200 mb-2">Import will restore:</p>
<ul className="list-disc list-inside text-sm text-green-700 dark:text-green-300 space-y-1">
<li>{state.validation.projectCount} projects</li>
<li>{state.validation.totalFiles} total files</li>
{state.validation.hasConfig && <li>Settings, themes, and preferences</li>}
</ul>
</div>
)}
<p className="text-destructive font-medium">
This action cannot be undone. Are you sure?
This action cannot be undone. Are you absolutely sure?
</p>
</AlertDialogDescription>
</AlertDialogHeader>
+129
View File
@@ -0,0 +1,129 @@
import React, { useRef } from 'react';
import { cn } from '@/lib/utils';
interface FileUploadAreaProps {
selectedFile: File | null;
isDragOver: boolean;
isValid: boolean;
onFileSelect: (file: File) => void;
onFileRemove: () => void;
onDragOver: (e: React.DragEvent) => void;
onDragLeave: (e: React.DragEvent) => void;
onDrop: (e: React.DragEvent) => void;
disabled?: boolean;
accept?: string;
className?: string;
children?: React.ReactNode;
}
export function FileUploadArea({
selectedFile,
isDragOver,
isValid,
onFileSelect,
onFileRemove,
onDragOver,
onDragLeave,
onDrop,
disabled = false,
accept = '.zip',
className,
children
}: FileUploadAreaProps) {
const fileInputRef = useRef<HTMLInputElement>(null);
const handleClickUpload = () => {
fileInputRef.current?.click();
};
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const files = e.target.files;
if (files && files.length > 0) {
onFileSelect(files[0]);
}
};
return (
<div
className={cn(
"relative border-2 border-dashed rounded-lg p-6 text-center transition-colors cursor-pointer",
isDragOver ? "border-primary bg-primary/5" : "border-muted-foreground/25 hover:border-primary/50",
selectedFile && isValid && "border-green-500/50 bg-green-500/5",
selectedFile && !isValid && "border-destructive/50 bg-destructive/5",
disabled && "opacity-50 cursor-not-allowed",
className
)}
onClick={!disabled ? handleClickUpload : undefined}
onDragOver={onDragOver}
onDragLeave={onDragLeave}
onDrop={onDrop}
>
<input
ref={fileInputRef}
type="file"
onChange={handleFileChange}
accept={accept}
className="hidden"
disabled={disabled}
/>
{children || (
<div className="space-y-3">
<div className="flex justify-center">
{selectedFile ? (
isValid ? (
<div className="h-8 w-8 rounded-full bg-green-100 flex items-center justify-center">
<svg className="h-4 w-4 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
</div>
) : (
<div className="h-8 w-8 rounded-full bg-red-100 flex items-center justify-center">
<svg className="h-4 w-4 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</div>
)
) : (
<div className="h-8 w-8 rounded-full bg-muted flex items-center justify-center">
<svg className="h-4 w-4 text-muted-foreground" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
</svg>
</div>
)}
</div>
<div>
{selectedFile ? (
<div className="space-y-2">
<p className="text-sm font-medium">{selectedFile.name}</p>
<p className="text-xs text-muted-foreground">
{(selectedFile.size / 1024 / 1024).toFixed(2)} MB
</p>
<button
onClick={(e) => {
e.stopPropagation();
onFileRemove();
}}
className="text-xs text-destructive hover:underline"
disabled={disabled}
>
Remove file
</button>
</div>
) : (
<div className="space-y-1">
<p className="text-sm font-medium">
Drop file here or click to browse
</p>
<p className="text-xs text-muted-foreground">
{accept === '.zip' ? 'ZIP files only' : `Accepted files: ${accept}`}
</p>
</div>
)}
</div>
</div>
)}
</div>
);
}
+16 -16
View File
@@ -236,10 +236,10 @@ const resources = {
// Data Settings
dataSettingsDescriptionLong: 'Export files and manage local data.',
exportFiles: 'Export Files',
exportFilesDescription: 'Download all your projects and files as a ZIP archive. This includes all project files, settings, and data stored locally.',
importFullSystem: 'Import Full System',
importFullSystemDescription: 'Replace your entire Shakespeare workspace with a previously exported backup. This will permanently delete all current data.',
exportSystem: 'Export System',
exportSystemDescription: 'Download your complete Shakespeare workspace as a ZIP archive. This includes all projects, settings, and data.',
importSystem: 'Import System',
importSystemDescription: 'Replace your entire Shakespeare workspace with a previously exported backup. This will permanently delete all current data.',
exportAllFiles: 'Export All Files',
exporting: 'Exporting...',
clearAllData: 'Clear All Data',
@@ -565,10 +565,10 @@ const resources = {
// Data Settings
dataSettingsDescriptionLong: 'Exporte arquivos e gerencie dados locais.',
exportFiles: 'Exportar Arquivos',
exportFilesDescription: 'Baixe todos os seus projetos e arquivos como um arquivo ZIP. Isso inclui todos os arquivos de projeto, configurações e dados armazenados localmente.',
importFullSystem: 'Importar Sistema Completo',
importFullSystemDescription: 'Substitua todo o seu espaço de trabalho do Shakespeare por um backup exportado anteriormente. Isso excluirá permanentemente todos os dados atuais.',
exportSystem: 'Exportar Sistema',
exportSystemDescription: 'Baixe seu espaço de trabalho completo do Shakespeare como um arquivo ZIP. Isso inclui todos os projetos, configurações e dados.',
importSystem: 'Importar Sistema',
importSystemDescription: 'Substitua todo o seu espaço de trabalho do Shakespeare por um backup exportado anteriormente. Isso excluirá permanentemente todos os dados atuais.',
exportAllFiles: 'Exportar Todos os Arquivos',
exporting: 'Exportando...',
clearAllData: 'Limpar Todos os Dados',
@@ -903,10 +903,10 @@ const resources = {
// Data Settings
dataSettingsDescriptionLong: '导出文件和管理本地数据。',
exportFiles: '导出文件',
exportFilesDescription: '将您的所有项目和文件下载为ZIP存档。这包括所有项目文件、设置和本地存储的数据。',
importFullSystem: '导入完整系统',
importFullSystemDescription: '用之前导出的备份替换整个Shakespeare工作空间。这将永久删除所有当前数据。',
exportSystem: '导出系统',
exportSystemDescription: '将您的完整Shakespeare工作空间下载为ZIP存档。这包括所有项目、设置和数据。',
importSystem: '导入系统',
importSystemDescription: '用之前导出的备份替换整个Shakespeare工作空间。这将永久删除所有当前数据。',
exportAllFiles: '导出所有文件',
exporting: '导出中...',
clearAllData: '清除所有数据',
@@ -1238,10 +1238,10 @@ const resources = {
// Data Settings
dataSettingsDescriptionLong: 'Fitar da fayiloli da sarrafa bayanan gida.',
exportFiles: 'Fitar da Fayiloli',
exportFilesDescription: 'Sauke duk ayyukanku da fayiloli azaman ajiyar ZIP. Wannan ya haɗa da duk fayilolin aikin, saitunan, da bayanan da aka adana a gida.',
importFullSystem: 'Shigo da Cikakken Tsarin',
importFullSystemDescription: 'Maye gurbin dukkan wurin aikin Shakespeare ɗinku da backup da aka fitar a baya. Wannan zai share duk bayanan yanzu har abada.',
exportSystem: 'Fitar da Tsarin',
exportSystemDescription: 'Sauke cikakken wurin aikin Shakespeare ɗinka azaman ajiyar ZIP. Wannan ya haɗa da duk ayyuka, saituna, da bayanai.',
importSystem: 'Shigo da Tsarin',
importSystemDescription: 'Maye gurbin cikakken wurin aikin Shakespeare ɗinka da backup da aka fitar a baya. Wannan zai share duk bayanan yanzu har abada.',
exportAllFiles: 'Fitar da Duk Fayiloli',
exporting: 'Ana fitarwa...',
clearAllData: 'Share Duk Bayanai',
+2 -2
View File
@@ -20,8 +20,8 @@ describe('StorageSettings', () => {
// Check for Persist Data section
expect(screen.getByText('Persist Data')).toBeInTheDocument();
// Check for Export Files section
expect(screen.getByText('Export Files')).toBeInTheDocument();
// Check for Export System section
expect(screen.getByText('Export System')).toBeInTheDocument();
expect(screen.getByText('Export All Files')).toBeInTheDocument();
// Check for Clear All Data section
+4 -4
View File
@@ -380,10 +380,10 @@ export function StorageSettings() {
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Download className="h-5 w-5" />
{t('exportFiles')}
{t('exportSystem')}
</CardTitle>
<CardDescription>
{t('exportFilesDescription')}
{t('exportSystemDescription')}
</CardDescription>
</CardHeader>
<CardContent>
@@ -412,10 +412,10 @@ export function StorageSettings() {
<CardHeader>
<CardTitle className="flex items-center gap-2 text-amber-700 dark:text-amber-400">
<HardDrive className="h-5 w-5" />
{t('importFullSystem')}
{t('importSystem')}
</CardTitle>
<CardDescription>
{t('importFullSystemDescription')}
{t('importSystemDescription')}
</CardDescription>
</CardHeader>
<CardContent>