From 7cbaaec734958d2a6a5c50650bd9c763a46d1abb Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 22 Sep 2025 01:55:34 -0500 Subject: [PATCH] Move build button into PreviewPane --- src/components/ActionsMenu.tsx | 19 -- src/components/Shakespeare/PreviewPane.tsx | 248 +++++++++++++-------- src/pages/ProjectView.tsx | 2 - 3 files changed, 156 insertions(+), 113 deletions(-) diff --git a/src/components/ActionsMenu.tsx b/src/components/ActionsMenu.tsx index 3a861ec1..6f9eadad 100644 --- a/src/components/ActionsMenu.tsx +++ b/src/components/ActionsMenu.tsx @@ -22,7 +22,6 @@ import { GitBranch, MoreHorizontal, MessageSquarePlus, - Play, CloudUpload, Loader2, History, @@ -38,7 +37,6 @@ interface ActionsMenuProps { projectId: string; projectName: string; onNewChat: () => void; - onBuild: () => void; onDeploy: () => void; isLoading?: boolean; isBuildLoading?: boolean; @@ -52,7 +50,6 @@ export function ActionsMenu({ projectId, projectName, onNewChat, - onBuild, onDeploy, isLoading = false, isBuildLoading = false, @@ -139,22 +136,6 @@ export function ActionsMenu({ Rollback - { - if (onFirstInteraction) onFirstInteraction(); - onBuild(); - }} - disabled={isAnyLoading} - className="gap-2" - > - {isBuildLoading ? ( - - ) : ( - - )} - {isBuildLoading ? 'Building...' : 'Build'} - - { if (onFirstInteraction) onFirstInteraction(); diff --git a/src/components/Shakespeare/PreviewPane.tsx b/src/components/Shakespeare/PreviewPane.tsx index 19c54fe3..cb1b6571 100644 --- a/src/components/Shakespeare/PreviewPane.tsx +++ b/src/components/Shakespeare/PreviewPane.tsx @@ -3,16 +3,18 @@ import { useState, useEffect, useCallback, useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useFS } from '@/hooks/useFS'; +import { useBuildProject } from '@/hooks/useBuildProject'; import { Tabs, TabsContent } from '@/components/ui/tabs'; import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area'; import { Button } from '@/components/ui/button'; -import { FolderOpen, ArrowLeft, X, Bug, Copy, Check } from 'lucide-react'; +import { FolderOpen, ArrowLeft, X, Bug, Copy, Check, Play, Loader2, MenuIcon } from 'lucide-react'; import { useIsMobile } from '@/hooks/useIsMobile'; import { GitStatusIndicator } from '@/components/GitStatusIndicator'; import { BrowserAddressBar } from '@/components/ui/browser-address-bar'; import { DropdownMenu, DropdownMenuContent, + DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; @@ -79,6 +81,15 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) { const iframeRef = useRef(null); const { fs } = useFS(); const projectsManager = useProjectsManager(); + const { mutate: buildProject, isPending: isBuildLoading } = useBuildProject(projectId); + + const handleBuildProject = () => { + buildProject(undefined, { + onError: (error) => { + console.error('Build failed:', error); + } + }); + }; const loadFileContent = useCallback(async (filePath: string) => { setIsLoading(true); @@ -132,16 +143,15 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) { const refreshIframe = useCallback(() => { if (iframeRef.current) { // Force reload the iframe by updating its src - const currentSrc = iframeRef.current.src; - iframeRef.current.src = ''; + iframeRef.current.src = '/'; // Use a small timeout to ensure the src is cleared before setting it back setTimeout(() => { if (iframeRef.current) { - iframeRef.current.src = currentSrc; + iframeRef.current.src = `https://${projectId}.${IFRAME_DOMAIN}${currentPath}`; } }, 10); } - }, []); + }, [currentPath, projectId]); const navigateToPath = useCallback((path: string) => { if (iframeRef.current) { @@ -399,100 +409,131 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) { }; const ConsoleDropdown = () => { - const getLevelColor = (level: ConsoleMessage['level']) => { - switch (level) { - case 'error': return 'text-red-500'; - case 'warn': return 'text-yellow-500'; - case 'info': return 'text-blue-500'; - case 'debug': return 'text-gray-500'; - default: return 'text-gray-400'; - } - }; + const getLevelColor = (level: ConsoleMessage['level']) => { + switch (level) { + case 'error': return 'text-red-500'; + case 'warn': return 'text-yellow-500'; + case 'info': return 'text-blue-500'; + case 'debug': return 'text-gray-500'; + default: return 'text-gray-400'; + } + }; - const getLevelIcon = (level: ConsoleMessage['level']) => { - switch (level) { - case 'error': return '!'; - case 'warn': return '⚠'; - case 'info': return 'ℹ'; - case 'debug': return '🔍'; - default: return '•'; - } - }; + const getLevelIcon = (level: ConsoleMessage['level']) => { + switch (level) { + case 'error': return '!'; + case 'warn': return '⚠'; + case 'info': return 'ℹ'; + case 'debug': return '🔍'; + default: return '•'; + } + }; - const clearConsole = () => { - setConsoleMessages([]); - }; + const clearConsole = () => { + setConsoleMessages([]); + }; - const copyMessageToClipboard = async (msg: ConsoleMessage) => { - try { - // Create a formatted string with all message details - const formattedMessage = `[${msg.level.toUpperCase()}] ${msg.message}`; + const copyMessageToClipboard = async (msg: ConsoleMessage) => { + try { + // Create a formatted string with all message details + const formattedMessage = `[${msg.level.toUpperCase()}] ${msg.message}`; - await navigator.clipboard.writeText(formattedMessage); - setCopiedMessageId(msg.id); + await navigator.clipboard.writeText(formattedMessage); + setCopiedMessageId(msg.id); - // Reset the copied state after 2 seconds - setTimeout(() => { - setCopiedMessageId(null); - }, 2000); - } catch (error) { - console.error('Failed to copy message to clipboard:', error); - } - }; + // Reset the copied state after 2 seconds + setTimeout(() => { + setCopiedMessageId(null); + }, 2000); + } catch (error) { + console.error('Failed to copy message to clipboard:', error); + } + }; - return ( - - - - - -
- Console Output ({consoleMessages.length}) - -
- -
- {consoleMessages.length === 0 ? ( -
- No console messages -
- ) : ( - consoleMessages.map((msg) => ( -
-
-
{getLevelIcon(msg.level)} {msg.message}
- -
-
- )) + return ( + + + + + +
+ Console Output ({consoleMessages.length}) +
- -
-
- ); -}; + +
+ {consoleMessages.length === 0 ? ( +
+ No console messages +
+ ) : ( + consoleMessages.map((msg) => ( +
+
+
{getLevelIcon(msg.level)} {msg.message}
+ +
+
+ )) + )} +
+
+ + + ); + }; + + const Menu = () => { + return ( + + + + + + + {isBuildLoading ? ( + + ) : ( + + )} + {isBuildLoading ? 'Building...' : 'Build'} + + + + ); + }; return (
@@ -509,7 +550,12 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) { onForward={goForward} canGoBack={historyIndex > 0} canGoForward={historyIndex < navigationHistory.length - 1} - extraContent={} + extraContent={( +
+ + +
+ )} />