mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
Compare commits
6
Commits
v9.16.1
...
terminalPane
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1a48647f0 | ||
|
|
a150ec62a2 | ||
|
|
4623bccc5f | ||
|
|
d03c092ec9 | ||
|
|
92ef8fb3f3 | ||
|
|
d0896e6746 |
No files matched your search
@@ -170,17 +170,17 @@ export function BranchSwitcher({ projectId, className }: BranchSwitcherProps) {
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className={cn("gap-1 sm:gap-2 hover:bg-secondary/10 hover:border-secondary/20", className)}
|
||||
className={cn("h-7 text-xs gap-1.5", className)}
|
||||
disabled={isSwitching}
|
||||
>
|
||||
{isSwitching ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
<Loader2 className="h-3 w-3 animate-spin" />
|
||||
) : (
|
||||
<GitBranch className="h-4 w-4" />
|
||||
<GitBranch className="h-3 w-3" />
|
||||
)}
|
||||
<span className=" max-w-[120px] truncate">{currentBranch}</span>
|
||||
<span className="max-w-[120px] truncate">{currentBranch}</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-56">
|
||||
|
||||
@@ -1,140 +1,37 @@
|
||||
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 }: 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<string, string> = {
|
||||
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<HTMLTextAreaElement>) => {
|
||||
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 (
|
||||
<div className="h-full flex flex-col">
|
||||
<CardHeader className="border-b py-2 sm:py-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle className={cn("text-sm sm:text-base truncate flex-1 mr-2", gitStatusClasses)}>{filePath}</CardTitle>
|
||||
<div className="flex items-center space-x-1 sm:space-x-2">
|
||||
{hasChanges && !isMedia && (
|
||||
<span className="text-xs sm:text-sm text-muted-foreground hidden sm:inline">{t('unsavedChanges')}</span>
|
||||
)}
|
||||
{!isMedia && (
|
||||
<Button
|
||||
onClick={handleSave}
|
||||
disabled={!hasChanges || isSaving || isLoading}
|
||||
size="sm"
|
||||
className="focus-ring"
|
||||
>
|
||||
{isSaving ? (
|
||||
<>
|
||||
<Loader2 className="mr-1 sm:mr-2 h-4 w-4 animate-spin" />
|
||||
<span className="hidden sm:inline">{t('saving')}</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Save className="sm:mr-2 h-4 w-4" />
|
||||
<span className="hidden sm:inline">{t('save')}</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{!isMedia && (
|
||||
<div className="text-xs text-muted-foreground mt-1">
|
||||
{t('languageLabel')}: {getLanguageFromPath(filePath)}
|
||||
</div>
|
||||
)}
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="flex-1 p-0">
|
||||
<div className="flex-1 p-0">
|
||||
{isLoading ? (
|
||||
<div className="flex items-center justify-center h-full">
|
||||
<div className="animate-spin rounded-full h-6 w-6 border-b-2 border-primary"></div>
|
||||
@@ -146,7 +43,7 @@ export function FileEditor({ filePath, content, onSave, isLoading, projectId }:
|
||||
) : (
|
||||
<Textarea
|
||||
value={editedContent}
|
||||
onChange={(e) => setEditedContent(e.target.value)}
|
||||
onChange={handleChange}
|
||||
className={cn(
|
||||
'w-full h-full resize-none border-0 rounded-none',
|
||||
'focus:outline-none focus:ring-0',
|
||||
@@ -157,7 +54,7 @@ export function FileEditor({ filePath, content, onSave, isLoading, projectId }:
|
||||
spellCheck={false}
|
||||
/>
|
||||
)}
|
||||
</CardContent>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,7 +3,8 @@ import { useTranslation } from 'react-i18next';
|
||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useGitStatus } from '@/hooks/useGitStatus';
|
||||
import { ChevronRight, ChevronDown, File, Folder, Search } from 'lucide-react';
|
||||
import { ChevronRight, ChevronDown, File, Folder, Search, Code, FileText, Image, FileJson, Palette, Settings, FileCode } from 'lucide-react';
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { createGitignoreFilter, normalizePathForGitignore } from '@/lib/gitignore';
|
||||
import { Input } from '@/components/ui/input';
|
||||
@@ -22,6 +23,49 @@ interface FileNode {
|
||||
isOpen?: boolean;
|
||||
}
|
||||
|
||||
// Helper function to get file icon based on extension
|
||||
function getFileIcon(fileName: string): { icon: LucideIcon; color: string } {
|
||||
const ext = fileName.split('.').pop()?.toLowerCase() || '';
|
||||
|
||||
// Image files - subtle blue hint
|
||||
if (['jpg', 'jpeg', 'png', 'gif', 'svg', 'webp', 'ico', 'bmp', 'tiff'].includes(ext)) {
|
||||
return { icon: Image, color: 'text-blue-400/60' };
|
||||
}
|
||||
|
||||
// Code files - subtle amber hint
|
||||
if (['js', 'jsx', 'ts', 'tsx', 'py', 'java', 'cpp', 'c', 'cs', 'php', 'rb', 'go', 'rs', 'swift', 'kt', 'scala', 'dart'].includes(ext)) {
|
||||
return { icon: Code, color: 'text-amber-400/60' };
|
||||
}
|
||||
|
||||
// Web files - subtle orange hint
|
||||
if (['html', 'htm', 'xhtml'].includes(ext)) {
|
||||
return { icon: FileCode, color: 'text-orange-400/60' };
|
||||
}
|
||||
|
||||
// CSS files - subtle purple hint
|
||||
if (['css', 'scss', 'sass', 'less', 'styl'].includes(ext)) {
|
||||
return { icon: Palette, color: 'text-purple-400/60' };
|
||||
}
|
||||
|
||||
// Data/Config files - subtle green hint
|
||||
if (['json', 'jsonc'].includes(ext)) {
|
||||
return { icon: FileJson, color: 'text-green-400/60' };
|
||||
}
|
||||
|
||||
// Config files - subtle amber hint
|
||||
if (['xml', 'yaml', 'yml', 'toml', 'ini', 'conf', 'config'].includes(ext)) {
|
||||
return { icon: Settings, color: 'text-amber-400/60' };
|
||||
}
|
||||
|
||||
// Text/Markdown files - subtle amber hint
|
||||
if (['txt', 'md', 'markdown', 'rst', 'log'].includes(ext)) {
|
||||
return { icon: FileText, color: 'text-amber-400/60' };
|
||||
}
|
||||
|
||||
// Default file icon - subtle amber hint
|
||||
return { icon: File, color: 'text-amber-400/60' };
|
||||
}
|
||||
|
||||
export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProps) {
|
||||
const { t } = useTranslation();
|
||||
const [tree, setTree] = useState<FileNode[]>([]);
|
||||
@@ -264,7 +308,10 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp
|
||||
) : (
|
||||
<>
|
||||
<div className="w-4" /> {/* Spacer for alignment */}
|
||||
<File className={cn("h-4 w-4 text-gray-500 flex-shrink-0", gitignoreClasses)} />
|
||||
{(() => {
|
||||
const { icon: Icon, color } = getFileIcon(node.name);
|
||||
return <Icon className={cn("h-4 w-4 flex-shrink-0", color, gitignoreClasses)} />;
|
||||
})()}
|
||||
</>
|
||||
)}
|
||||
<span className={cn("text-sm whitespace-nowrap", gitStatusClasses, gitignoreClasses)}>{node.name}</span>
|
||||
|
||||
@@ -7,12 +7,10 @@ import { useFSPaths } from '@/hooks/useFSPaths';
|
||||
import { addConsoleMessage, getConsoleMessages, type ConsoleMessage } from '@/lib/consoleMessages';
|
||||
import { useConsoleError } from '@/hooks/useConsoleError';
|
||||
import { useBuildProject } from '@/hooks/useBuildProject';
|
||||
import { Tabs, TabsContent } from '@/components/ui/tabs';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { FolderOpen, ArrowLeft, Bug, Copy, Check, Loader2, Code, X, Terminal, Expand, Shrink, Hammer, RefreshCw } from 'lucide-react';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { GitStatusIndicator } from '@/components/GitStatusIndicator';
|
||||
import { FolderOpen, Bug, Copy, Check, Loader2, Code, X, Terminal, Expand, Shrink, Hammer, RefreshCw, Save } from 'lucide-react';
|
||||
import { BranchSwitcher } from '@/components/BranchSwitcher';
|
||||
import { BrowserAddressBar } from '@/components/ui/browser-address-bar';
|
||||
import { type DeviceMode } from '@/components/ui/device-toggle';
|
||||
@@ -63,16 +61,16 @@ interface JSONRPCResponse {
|
||||
id: number;
|
||||
}
|
||||
|
||||
export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable = true }: PreviewPaneProps) {
|
||||
export function PreviewPane({ projectId, activeTab, onToggleView: _onToggleView, isPreviewable = true }: PreviewPaneProps) {
|
||||
const { t } = useTranslation();
|
||||
const { config } = useAppContext();
|
||||
const { previewDomain } = config;
|
||||
const [selectedFile, setSelectedFile] = useState<string | null>(null);
|
||||
const [fileContent, setFileContent] = useState<string>('');
|
||||
const [openFiles, setOpenFiles] = useState<string[]>([]);
|
||||
const [activeFileTab, setActiveFileTab] = useState<string | null>(null);
|
||||
const [fileContents, setFileContents] = useState<Record<string, string>>({});
|
||||
const [editedContents, setEditedContents] = useState<Record<string, string>>({});
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [mobileCodeView, setMobileCodeView] = useState<'explorer' | 'editor' | 'terminal'>('explorer');
|
||||
const [desktopCodeView, setDesktopCodeView] = useState<'files' | 'terminal'>('files');
|
||||
const isMobile = useIsMobile();
|
||||
const [hasBuiltProject, setHasBuiltProject] = useState(false);
|
||||
const [buildError, setBuildError] = useState<string | null>(null);
|
||||
const [currentPath, setCurrentPath] = useState('/');
|
||||
@@ -82,6 +80,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
|
||||
const [isFullscreen, setIsFullscreen] = useState(false);
|
||||
const [deviceMode, setDeviceMode] = useState<DeviceMode>('laptop');
|
||||
const [isLogsOpen, setIsLogsOpen] = useState(false);
|
||||
const [logsPanelTab, setLogsPanelTab] = useState<'logs' | 'code' | 'terminal'>('logs');
|
||||
const previewContainerRef = useRef<HTMLDivElement>(null);
|
||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||
const iframePanelRef = useRef<ImperativePanelHandle>(null);
|
||||
@@ -125,22 +124,26 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
|
||||
const loadFileContent = useCallback(async (filePath: string) => {
|
||||
// Skip loading media files - they can't be edited as text
|
||||
if (isMediaFile(filePath)) {
|
||||
setFileContent('');
|
||||
setIsLoading(false);
|
||||
setFileContents(prev => ({ ...prev, [filePath]: '' }));
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't reload if we already have the content
|
||||
if (fileContents[filePath]) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const content = await projectsManager.readFile(projectId, filePath);
|
||||
setFileContent(content);
|
||||
setFileContents(prev => ({ ...prev, [filePath]: content }));
|
||||
} catch (_error) {
|
||||
console.error('Failed to load file:', _error);
|
||||
setFileContent('');
|
||||
setFileContents(prev => ({ ...prev, [filePath]: '' }));
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [projectId, projectsManager]);
|
||||
}, [projectId, projectsManager, fileContents]);
|
||||
|
||||
const getContentType = (filename: string): string => {
|
||||
const ext = filename.split('.').pop()?.toLowerCase();
|
||||
@@ -416,19 +419,22 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
|
||||
return () => window.removeEventListener('message', handleMessage);
|
||||
}, [handleFetch, handleConsoleMessage, handleUpdateNavigationState, projectId, previewDomain]);
|
||||
|
||||
// Load content for all open files
|
||||
useEffect(() => {
|
||||
if (selectedFile) {
|
||||
loadFileContent(selectedFile);
|
||||
}
|
||||
}, [selectedFile, loadFileContent]);
|
||||
openFiles.forEach(filePath => {
|
||||
if (!fileContents[filePath] && !isMediaFile(filePath)) {
|
||||
loadFileContent(filePath);
|
||||
}
|
||||
});
|
||||
}, [openFiles, fileContents, loadFileContent]);
|
||||
|
||||
// Reset selected file and navigation history when projectId changes
|
||||
const prevProjectIdRef = useRef<string>();
|
||||
useEffect(() => {
|
||||
setSelectedFile(null);
|
||||
setFileContent('');
|
||||
setMobileCodeView('explorer');
|
||||
setDesktopCodeView('files');
|
||||
setOpenFiles([]);
|
||||
setActiveFileTab(null);
|
||||
setFileContents({});
|
||||
setEditedContents({});
|
||||
setBuildError(null);
|
||||
|
||||
// Reset navigation history and state
|
||||
@@ -463,18 +469,61 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
|
||||
}, [projectId, checkForBuiltProject, refreshIframe]);
|
||||
|
||||
const handleFileSelect = (filePath: string) => {
|
||||
setSelectedFile(filePath);
|
||||
if (isMobile) {
|
||||
setMobileCodeView('editor');
|
||||
// Skip media files
|
||||
if (isMediaFile(filePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add to open files if not already open
|
||||
if (!openFiles.includes(filePath)) {
|
||||
setOpenFiles(prev => [...prev, filePath]);
|
||||
}
|
||||
|
||||
// Set as active tab
|
||||
setActiveFileTab(filePath);
|
||||
};
|
||||
|
||||
const handleCloseTab = (filePath: string, e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
|
||||
// Remove from open files
|
||||
setOpenFiles(prev => prev.filter(f => f !== filePath));
|
||||
|
||||
// Remove from file contents
|
||||
setFileContents(prev => {
|
||||
const newContents = { ...prev };
|
||||
delete newContents[filePath];
|
||||
return newContents;
|
||||
});
|
||||
|
||||
// If this was the active tab, switch to another tab or clear
|
||||
if (activeFileTab === filePath) {
|
||||
const remainingFiles = openFiles.filter(f => f !== filePath);
|
||||
if (remainingFiles.length > 0) {
|
||||
setActiveFileTab(remainingFiles[remainingFiles.length - 1]);
|
||||
} else {
|
||||
setActiveFileTab(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleFileSave = async (content: string) => {
|
||||
if (!selectedFile) return;
|
||||
const handleFileSave = async () => {
|
||||
if (!activeFileTab) return;
|
||||
|
||||
const contentToSave = editedContents[activeFileTab];
|
||||
if (contentToSave === undefined || contentToSave === fileContents[activeFileTab]) {
|
||||
return; // No changes to save
|
||||
}
|
||||
|
||||
setIsSaving(true);
|
||||
try {
|
||||
await fs.writeFile(`${projectsPath}/${projectId}/${selectedFile}`, content);
|
||||
setFileContent(content);
|
||||
await fs.writeFile(`${projectsPath}/${projectId}/${activeFileTab}`, contentToSave);
|
||||
setFileContents(prev => ({ ...prev, [activeFileTab]: contentToSave }));
|
||||
setEditedContents(prev => {
|
||||
const newContents = { ...prev };
|
||||
delete newContents[activeFileTab];
|
||||
return newContents;
|
||||
});
|
||||
|
||||
// Automatically trigger a rebuild after saving a file
|
||||
if (isPreviewable) {
|
||||
@@ -487,6 +536,8 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to save file:', error);
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -597,18 +648,6 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
|
||||
)}
|
||||
<span className="hidden lg:inline">Build</span>
|
||||
</Button>
|
||||
{(!isMobile && onToggleView && isPreviewable) && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onToggleView}
|
||||
className="h-8 gap-2"
|
||||
title={t('codeButtonTooltip')}
|
||||
>
|
||||
<Code className="h-4 w-4" />
|
||||
<span className="hidden lg:inline">Code</span>
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
@@ -617,7 +656,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
|
||||
title={t('logsButtonTooltip')}
|
||||
>
|
||||
<Bug className="h-4 w-4" />
|
||||
<span className="hidden lg:inline">Logs</span>
|
||||
<span className="hidden lg:inline">Debug</span>
|
||||
{hasConsoleErrors && (
|
||||
<span className="absolute -top-1 -right-1 h-3 w-3 rounded-full border-2 border-background bg-red-500" />
|
||||
)}
|
||||
@@ -631,7 +670,6 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
|
||||
<ResizablePanel
|
||||
ref={iframePanelRef}
|
||||
defaultSize={isLogsOpen ? 60 : 100}
|
||||
minSize={30}
|
||||
className="min-h-0"
|
||||
>
|
||||
<div className="h-full flex items-center justify-center min-h-0">
|
||||
@@ -751,35 +789,77 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
|
||||
collapsedSize={0}
|
||||
>
|
||||
{/* Logs Panel */}
|
||||
<div className="h-full flex flex-col bg-background border-t overflow-hidden min-h-0 w-full min-w-0">
|
||||
<Tabs value={logsPanelTab} onValueChange={(v) => setLogsPanelTab(v as 'logs' | 'code' | 'terminal')} className="h-full flex flex-col bg-background border-t overflow-hidden min-h-0 w-full min-w-0">
|
||||
{/* Logs Header */}
|
||||
<div className="h-12 px-4 border-b flex items-center justify-between flex-shrink-0">
|
||||
<TabsList className="h-8">
|
||||
<TabsTrigger value="logs" className="h-7 text-xs gap-1.5">
|
||||
<Bug className="h-3 w-3" />
|
||||
<span>Logs</span>
|
||||
{hasConsoleErrors && (
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-red-500" />
|
||||
)}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="code" className="h-7 text-xs gap-1.5">
|
||||
<Code className="h-3 w-3" />
|
||||
<span>Code</span>
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="terminal" className="h-7 text-xs gap-1.5">
|
||||
<Terminal className="h-3 w-3" />
|
||||
<span>Terminal</span>
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
<div className="flex items-center gap-2">
|
||||
{hasConsoleErrors && (
|
||||
<span className="h-2 w-2 rounded-full bg-red-500" />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{messageCount > 0 && (
|
||||
{logsPanelTab === 'logs' && messageCount > 0 && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={copyAllMessagesToClipboard}
|
||||
className="h-7 px-2 text-xs"
|
||||
className="h-7 text-xs gap-1.5"
|
||||
>
|
||||
{copiedAll ? (
|
||||
<>
|
||||
<Check className="h-3 w-3 mr-1.5 text-success" />
|
||||
{t('copied')}
|
||||
<Check className="h-3 w-3 text-success" />
|
||||
<span className="hidden sm:inline">{t('copied')}</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Copy className="h-3 w-3 mr-1.5" />
|
||||
{t('copyAll')}
|
||||
<Copy className="h-3 w-3" />
|
||||
<span className="hidden sm:inline">{t('copyAll')}</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
{logsPanelTab === 'code' && (
|
||||
<>
|
||||
<BranchSwitcher projectId={projectId} />
|
||||
{activeFileTab && (() => {
|
||||
const hasUnsavedChanges = editedContents[activeFileTab] !== undefined &&
|
||||
editedContents[activeFileTab] !== fileContents[activeFileTab];
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleFileSave}
|
||||
disabled={!hasUnsavedChanges || isSaving || isLoading}
|
||||
className="h-7 text-xs gap-1.5"
|
||||
>
|
||||
{isSaving ? (
|
||||
<>
|
||||
<Loader2 className="h-3 w-3 animate-spin" />
|
||||
<span className="hidden sm:inline">{t('saving')}</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Save className="h-3 w-3" />
|
||||
<span className="hidden sm:inline">{t('save')}</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
})()}
|
||||
</>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
@@ -790,60 +870,151 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
{/* Logs Content */}
|
||||
{/* Panel Content */}
|
||||
<div className="flex-1 min-h-0 overflow-hidden w-full">
|
||||
<ScrollArea className="h-full w-full">
|
||||
<div className="p-2 space-y-0 w-full min-w-0 max-w-full">
|
||||
{messageCount === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-12 text-center">
|
||||
<p className="text-sm text-muted-foreground font-medium">No console messages</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">Messages from your project will appear here</p>
|
||||
</div>
|
||||
) : (
|
||||
messages.map((msg, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="group relative py-0.5 px-1 hover:bg-muted/50 transition-colors duration-150 rounded cursor-pointer w-full max-w-full"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
copyMessageToClipboard(msg, index);
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"text-xs font-mono leading-tight whitespace-pre-wrap break-words w-full min-w-0 max-w-full",
|
||||
msg.level === 'error' ? "text-destructive" :
|
||||
msg.level === 'warn' ? "text-warning" :
|
||||
msg.level === 'info' ? "text-primary" :
|
||||
"text-muted-foreground"
|
||||
)}
|
||||
style={{ wordBreak: 'break-word', overflowWrap: 'break-word' }}
|
||||
>
|
||||
{msg.message}
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
{/* Logs Tab */}
|
||||
<TabsContent value="logs" className="h-full mt-0 m-0 data-[state=active]:flex data-[state=active]:flex-col">
|
||||
<ScrollArea className="flex-1 min-h-0">
|
||||
<div className="p-2 space-y-0 w-full min-w-0 max-w-full">
|
||||
{messageCount === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-12 text-center">
|
||||
<p className="text-sm text-muted-foreground font-medium">No console messages</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">Messages from your project will appear here</p>
|
||||
</div>
|
||||
) : (
|
||||
messages.map((msg, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="group relative py-0.5 px-1 hover:bg-muted/50 transition-colors duration-150 rounded cursor-pointer w-full max-w-full"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
copyMessageToClipboard(msg, index);
|
||||
}}
|
||||
className="h-3 w-3 p-0 opacity-0 group-hover:opacity-100 transition-all duration-200 absolute right-1 top-1 hover:bg-muted/70 text-muted-foreground hover:text-foreground bg-background/80 rounded border"
|
||||
>
|
||||
{copiedMessageIndex === index ? (
|
||||
<Check className="h-2 w-2 text-success" />
|
||||
) : (
|
||||
<Copy className="h-2 w-2" />
|
||||
)}
|
||||
</Button>
|
||||
<div
|
||||
className={cn(
|
||||
"text-xs font-mono leading-tight whitespace-pre-wrap break-words w-full min-w-0 max-w-full",
|
||||
msg.level === 'error' ? "text-destructive" :
|
||||
msg.level === 'warn' ? "text-warning" :
|
||||
msg.level === 'info' ? "text-primary" :
|
||||
"text-muted-foreground"
|
||||
)}
|
||||
style={{ wordBreak: 'break-word', overflowWrap: 'break-word' }}
|
||||
>
|
||||
{msg.message}
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
copyMessageToClipboard(msg, index);
|
||||
}}
|
||||
className="h-3 w-3 p-0 opacity-0 group-hover:opacity-100 transition-all duration-200 absolute right-1 top-1 hover:bg-muted/70 text-muted-foreground hover:text-foreground bg-background/80 rounded border"
|
||||
>
|
||||
{copiedMessageIndex === index ? (
|
||||
<Check className="h-2 w-2 text-success" />
|
||||
) : (
|
||||
<Copy className="h-2 w-2" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</TabsContent>
|
||||
{/* Code Tab */}
|
||||
<TabsContent value="code" className="h-full mt-0 m-0 data-[state=active]:flex data-[state=active]:flex-col">
|
||||
<div className="flex-1 min-h-0 flex">
|
||||
<div className="w-1/3 border-r flex flex-col min-h-0">
|
||||
<ScrollArea className="flex-1 min-h-0">
|
||||
<ScrollBar orientation="horizontal" />
|
||||
<div className="min-w-max">
|
||||
<FileTree
|
||||
projectId={projectId}
|
||||
onFileSelect={handleFileSelect}
|
||||
selectedFile={activeFileTab}
|
||||
/>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</ScrollArea>
|
||||
</div>
|
||||
<div className="flex-1 min-h-0 flex flex-col overflow-hidden">
|
||||
{openFiles.length > 0 ? (
|
||||
<>
|
||||
{/* File Tabs */}
|
||||
<div className="border-b flex-shrink-0 w-full overflow-x-auto overflow-y-hidden">
|
||||
<div className="flex items-center gap-1 px-2" style={{ width: 'max-content' }}>
|
||||
{openFiles.map((filePath) => {
|
||||
const fileName = filePath.split('/').pop() || filePath;
|
||||
const hasUnsavedChanges = editedContents[filePath] !== undefined &&
|
||||
editedContents[filePath] !== fileContents[filePath];
|
||||
const isActive = activeFileTab === filePath;
|
||||
|
||||
return (
|
||||
<button
|
||||
key={filePath}
|
||||
onClick={() => {
|
||||
setActiveFileTab(filePath);
|
||||
}}
|
||||
className={cn(
|
||||
"flex items-center gap-2 px-3 py-1.5 text-sm border-b-2 transition-colors flex-shrink-0 whitespace-nowrap",
|
||||
isActive
|
||||
? "border-primary text-foreground"
|
||||
: "border-transparent text-muted-foreground hover:text-foreground"
|
||||
)}
|
||||
>
|
||||
<span>{fileName}</span>
|
||||
{hasUnsavedChanges && (
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-primary flex-shrink-0" />
|
||||
)}
|
||||
<button
|
||||
onClick={(e) => handleCloseTab(filePath, e)}
|
||||
className="ml-1 hover:bg-muted rounded p-0.5 flex-shrink-0"
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
</button>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
{/* Editor */}
|
||||
{activeFileTab && (
|
||||
<FileEditor
|
||||
filePath={activeFileTab}
|
||||
content={editedContents[activeFileTab] !== undefined
|
||||
? editedContents[activeFileTab]
|
||||
: (fileContents[activeFileTab] ?? '')}
|
||||
onContentChange={(content) => {
|
||||
setEditedContents(prev => ({ ...prev, [activeFileTab]: content }));
|
||||
}}
|
||||
isLoading={isLoading && !fileContents[activeFileTab]}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div className="h-full flex items-center justify-center">
|
||||
<div className="text-center">
|
||||
<FolderOpen className="h-12 w-12 mx-auto text-muted-foreground mb-4" />
|
||||
<p className="text-muted-foreground">
|
||||
{t('selectFileFromExplorer')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</TabsContent>
|
||||
{/* Terminal Tab */}
|
||||
<TabsContent value="terminal" className="h-full mt-0 m-0 data-[state=active]:flex data-[state=active]:flex-col">
|
||||
<div className="flex-1 min-h-0">
|
||||
<TerminalComponent cwd={`${projectsPath}/${projectId}`} />
|
||||
</div>
|
||||
</TabsContent>
|
||||
</div>
|
||||
</div>
|
||||
</Tabs>
|
||||
</ResizablePanel>
|
||||
</ResizablePanelGroup>
|
||||
</div>
|
||||
@@ -864,180 +1035,6 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
|
||||
</TabsContent>
|
||||
)}
|
||||
|
||||
<TabsContent value="code" className="h-full mt-0">
|
||||
{isMobile ? (
|
||||
<div className="h-full flex flex-col min-h-0">
|
||||
{/* Mobile Code view header */}
|
||||
<div className="h-12 px-4 border-b flex items-center bg-gradient-to-r from-muted/20 to-background flex-shrink-0">
|
||||
<BranchSwitcher projectId={projectId} />
|
||||
<div className="flex-1" />
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setMobileCodeView(mobileCodeView === 'terminal' ? 'explorer' : 'terminal')}
|
||||
className="gap-2 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<Terminal className="h-4 w-4" />
|
||||
<span className="hidden sm:inline">Terminal</span>
|
||||
</Button>
|
||||
<GitStatusIndicator projectId={projectId} />
|
||||
</div>
|
||||
|
||||
{mobileCodeView === 'explorer' ? (
|
||||
<div className="flex-1 min-h-0">
|
||||
<ScrollArea className="h-full">
|
||||
<ScrollBar orientation="horizontal" />
|
||||
<div className="min-w-max">
|
||||
<FileTree
|
||||
projectId={projectId}
|
||||
onFileSelect={handleFileSelect}
|
||||
selectedFile={selectedFile}
|
||||
/>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
) : mobileCodeView === 'terminal' ? (
|
||||
<div className="flex-1 min-h-0">
|
||||
<TerminalComponent cwd={`${projectsPath}/${projectId}`} />
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="p-3 border-b bg-gradient-to-r from-primary/5 to-accent/5 flex items-center gap-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setMobileCodeView('explorer')}
|
||||
className="p-1"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<h3 className="font-semibold flex-1 truncate bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
|
||||
{selectedFile ? selectedFile.split('/').pop() : t('fileEditor')}
|
||||
</h3>
|
||||
<GitStatusIndicator projectId={projectId} />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
{selectedFile ? (
|
||||
<FileEditor
|
||||
filePath={selectedFile}
|
||||
content={fileContent}
|
||||
onSave={handleFileSave}
|
||||
isLoading={isLoading}
|
||||
projectId={projectId}
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full flex items-center justify-center">
|
||||
<div className="text-center">
|
||||
<FolderOpen className="h-12 w-12 mx-auto text-muted-foreground mb-4" />
|
||||
<p className="text-muted-foreground">
|
||||
{t('selectFileFromExplorer')}
|
||||
</p>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setMobileCodeView('explorer')}
|
||||
className="mt-4"
|
||||
>
|
||||
{t('openFileExplorer')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="h-full flex flex-col">
|
||||
{/* Code view header with back button */}
|
||||
{!isMobile && onToggleView && isPreviewable && (
|
||||
<div className="h-12 px-4 border-b flex items-center bg-gradient-to-r from-muted/20 to-background gap-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onToggleView}
|
||||
className="gap-2 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
{t('backToPreview')}
|
||||
</Button>
|
||||
<div className="flex-1" />
|
||||
<BranchSwitcher projectId={projectId} />
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setDesktopCodeView(desktopCodeView === 'terminal' ? 'files' : 'terminal')}
|
||||
className="gap-2 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<Terminal className="h-4 w-4" />
|
||||
<span className="hidden lg:inline">Terminal</span>
|
||||
</Button>
|
||||
<GitStatusIndicator projectId={projectId} />
|
||||
</div>
|
||||
)}
|
||||
{/* Code view header without back button for non-previewable projects */}
|
||||
{!isMobile && !isPreviewable && (
|
||||
<div className="h-12 px-4 border-b flex items-center bg-gradient-to-r from-muted/20 to-background">
|
||||
<div className="flex-1" />
|
||||
<BranchSwitcher projectId={projectId} />
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setDesktopCodeView(desktopCodeView === 'terminal' ? 'files' : 'terminal')}
|
||||
className="gap-2 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<Terminal className="h-4 w-4" />
|
||||
<span className="hidden lg:inline">Terminal</span>
|
||||
</Button>
|
||||
<GitStatusIndicator projectId={projectId} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 flex min-h-0">
|
||||
{desktopCodeView === 'terminal' ? (
|
||||
<div className="flex-1">
|
||||
<TerminalComponent cwd={`${projectsPath}/${projectId}`} />
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="w-1/3 border-r flex flex-col">
|
||||
<ScrollArea className="flex-1">
|
||||
<ScrollBar orientation="horizontal" />
|
||||
<div className="min-w-max">
|
||||
<FileTree
|
||||
projectId={projectId}
|
||||
onFileSelect={handleFileSelect}
|
||||
selectedFile={selectedFile}
|
||||
/>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
|
||||
<div className="flex-1">
|
||||
{selectedFile ? (
|
||||
<FileEditor
|
||||
filePath={selectedFile}
|
||||
content={fileContent}
|
||||
onSave={handleFileSave}
|
||||
isLoading={isLoading}
|
||||
projectId={projectId}
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full flex items-center justify-center">
|
||||
<div className="text-center">
|
||||
<p className="text-muted-foreground">
|
||||
{t('selectFileFromExplorer')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user