diff --git a/src/components/Shakespeare/FileEditor.tsx b/src/components/Shakespeare/FileEditor.tsx index a106bab5..88133d0c 100644 --- a/src/components/Shakespeare/FileEditor.tsx +++ b/src/components/Shakespeare/FileEditor.tsx @@ -1,140 +1,38 @@ import { useState, useEffect } from 'react'; -import { useTranslation } from 'react-i18next'; -import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; -import { CardContent, CardHeader, CardTitle } from '@/components/ui/card'; -import { Save, Loader2, ImageOff } from 'lucide-react'; +import { ImageOff } from 'lucide-react'; import { cn } from '@/lib/utils'; -import { useGitStatus } from '@/hooks/useGitStatus'; import { isMediaFile } from '@/lib/fileUtils'; interface FileEditorProps { filePath: string; content: string; - onSave: (content: string) => void; + onContentChange: (content: string) => void; isLoading: boolean; projectId?: string; } -export function FileEditor({ filePath, content, onSave, isLoading, projectId }: FileEditorProps) { - const { t } = useTranslation(); +export function FileEditor({ filePath, content, onContentChange, isLoading, projectId }: FileEditorProps) { const [editedContent, setEditedContent] = useState(content); - const [isSaving, setIsSaving] = useState(false); - const [hasChanges, setHasChanges] = useState(false); - const { data: gitStatus } = useGitStatus(projectId || null); + const isMedia = isMediaFile(filePath); useEffect(() => { setEditedContent(content); - setHasChanges(false); }, [content, filePath]); - useEffect(() => { - setHasChanges(editedContent !== content); - }, [editedContent, content]); - - const handleSave = async () => { - setIsSaving(true); - try { - await onSave(editedContent); - setHasChanges(false); - } catch (error) { - console.error('Failed to save file:', error); - } finally { - setIsSaving(false); - } - }; - - const getLanguageFromPath = (path: string): string => { - const extension = path.split('.').pop()?.toLowerCase(); - const languageMap: Record = { - js: 'javascript', - jsx: 'javascript', - ts: 'typescript', - tsx: 'typescript', - html: 'html', - css: 'css', - json: 'json', - md: 'markdown', - py: 'python', - java: 'java', - cpp: 'cpp', - c: 'c', - sh: 'bash', - yml: 'yaml', - yaml: 'yaml', - }; - return languageMap[extension || ''] || 'text'; + const handleChange = (e: React.ChangeEvent) => { + const newContent = e.target.value; + setEditedContent(newContent); + onContentChange(newContent); }; const getMonospaceFont = () => { return 'font-mono text-sm'; }; - // Helper function to get git status for the current file - const getFileGitStatus = (filePath: string) => { - if (!gitStatus?.changedFiles) return null; - const fileChange = gitStatus.changedFiles.find(change => change.filepath === filePath); - return fileChange?.status || null; - }; - - // Helper function to get styling classes based on git status - const getGitStatusClasses = (status: string | null) => { - switch (status) { - case 'added': - case 'untracked': - return 'text-green-600 dark:text-green-400'; - case 'modified': - case 'staged': - return 'text-yellow-600 dark:text-yellow-400'; - default: - return ''; - } - }; - - // Get git status for the current file - const currentFileGitStatus = getFileGitStatus(filePath); - const gitStatusClasses = getGitStatusClasses(currentFileGitStatus); - const isMedia = isMediaFile(filePath); - return (
- -
- {filePath} -
- {hasChanges && !isMedia && ( - {t('unsavedChanges')} - )} - {!isMedia && ( - - )} -
-
- {!isMedia && ( -
- {t('languageLabel')}: {getLanguageFromPath(filePath)} -
- )} -
- - +
{isLoading ? (
@@ -146,7 +44,7 @@ export function FileEditor({ filePath, content, onSave, isLoading, projectId }: ) : (