From 4be7f67cac2b95535e789f3c5ed600455a4d12f8 Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Sun, 12 Oct 2025 21:46:39 +0000 Subject: [PATCH] cleanup v2 --- src/components/FullSystemImportDialog.tsx | 99 +++++++---------- src/components/ui/file-upload-area.tsx | 129 ++++++++++++++++++++++ src/lib/i18n.ts | 32 +++--- src/pages/StorageSettings.test.tsx | 4 +- src/pages/StorageSettings.tsx | 8 +- 5 files changed, 193 insertions(+), 79 deletions(-) create mode 100644 src/components/ui/file-upload-area.tsx diff --git a/src/components/FullSystemImportDialog.tsx b/src/components/FullSystemImportDialog.tsx index fbec7f3a..053ea382 100644 --- a/src/components/FullSystemImportDialog.tsx +++ b/src/components/FullSystemImportDialog.tsx @@ -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(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)} > - Import Full System + Import System )} @@ -213,59 +210,49 @@ export function FullSystemImportDialog({ - Import Complete System + Import System - Replace your entire workspace with a backup. This will permanently delete all current data. + Select a Shakespeare export file to replace your entire workspace.
- - - - Warning: This will completely wipe your current workspace and replace it with imported data. - - + {!state.isImporting && ( + + + + Warning: This action will completely replace your Shakespeare workspace with the imported data. + All current projects, AI settings, Git credentials, and preferences will be permanently deleted. + + + )} {!state.isImporting && !state.importComplete && ( <> -
- { - const files = e.target.files; - if (files && files.length > 0) { - handleFileSelect(files[0]); - } - }} - accept=".zip" - className="hidden" - disabled={state.isImporting} - /> -
{state.selectedFile ? ( state.validation?.isValid ? ( ) : ( - + ) ) : ( - + )}
@@ -298,7 +285,7 @@ export function FullSystemImportDialog({ )}
-
+ {state.validation && (
@@ -310,12 +297,6 @@ export function FullSystemImportDialog({ Files: {state.validation.totalFiles}
-
- Valid: - - {state.validation.isValid ? 'Yes' : 'No'} - -
{state.validation.errors.length > 0 && (
{state.validation.errors.slice(0, 2).join(', ')} @@ -341,7 +322,7 @@ export function FullSystemImportDialog({ variant="destructive" > - Replace System + Replace Entire System
@@ -387,7 +368,7 @@ export function FullSystemImportDialog({ - Confirm System Replacement + Confirm Complete System Replacement

@@ -397,23 +378,27 @@ export function FullSystemImportDialog({

This will permanently delete:

    -
  • All current projects and files
  • -
  • AI settings and API keys
  • -
  • Git credentials and preferences
  • -
  • All cached data
  • +
  • All current projects and their files
  • +
  • AI provider settings and API keys
  • +
  • Git credentials and repository settings
  • +
  • User preferences and theme settings
  • +
  • All cached data and temporary files
{state.validation && (
-

- Import will restore {state.validation.projectCount} projects and {state.validation.totalFiles} files -

+

Import will restore:

+
    +
  • {state.validation.projectCount} projects
  • +
  • {state.validation.totalFiles} total files
  • + {state.validation.hasConfig &&
  • Settings, themes, and preferences
  • } +
)}

- This action cannot be undone. Are you sure? + This action cannot be undone. Are you absolutely sure?

diff --git a/src/components/ui/file-upload-area.tsx b/src/components/ui/file-upload-area.tsx new file mode 100644 index 00000000..fa1079c8 --- /dev/null +++ b/src/components/ui/file-upload-area.tsx @@ -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(null); + + const handleClickUpload = () => { + fileInputRef.current?.click(); + }; + + const handleFileChange = (e: React.ChangeEvent) => { + const files = e.target.files; + if (files && files.length > 0) { + onFileSelect(files[0]); + } + }; + + return ( +
+ + + {children || ( +
+
+ {selectedFile ? ( + isValid ? ( +
+ + + +
+ ) : ( +
+ + + +
+ ) + ) : ( +
+ + + +
+ )} +
+ +
+ {selectedFile ? ( +
+

{selectedFile.name}

+

+ {(selectedFile.size / 1024 / 1024).toFixed(2)} MB +

+ +
+ ) : ( +
+

+ Drop file here or click to browse +

+

+ {accept === '.zip' ? 'ZIP files only' : `Accepted files: ${accept}`} +

+
+ )} +
+
+ )} +
+ ); +} \ No newline at end of file diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts index 68b6c8c2..c9b656f3 100644 --- a/src/lib/i18n.ts +++ b/src/lib/i18n.ts @@ -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', diff --git a/src/pages/StorageSettings.test.tsx b/src/pages/StorageSettings.test.tsx index dd04dcb4..90809ffd 100644 --- a/src/pages/StorageSettings.test.tsx +++ b/src/pages/StorageSettings.test.tsx @@ -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 diff --git a/src/pages/StorageSettings.tsx b/src/pages/StorageSettings.tsx index 2c5d4e33..cf61d9d7 100644 --- a/src/pages/StorageSettings.tsx +++ b/src/pages/StorageSettings.tsx @@ -380,10 +380,10 @@ export function StorageSettings() { - {t('exportFiles')} + {t('exportSystem')} - {t('exportFilesDescription')} + {t('exportSystemDescription')} @@ -412,10 +412,10 @@ export function StorageSettings() { - {t('importFullSystem')} + {t('importSystem')} - {t('importFullSystemDescription')} + {t('importSystemDescription')}