From f6dc218ae7f34ac6c8e3f6755a0a26f157c8d2d6 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 21 Sep 2025 21:59:24 -0500 Subject: [PATCH 01/22] Remove "Repository Information" from GitDialog --- src/components/GitDialog.test.tsx | 8 ++-- src/components/GitDialog.tsx | 77 +------------------------------ 2 files changed, 4 insertions(+), 81 deletions(-) diff --git a/src/components/GitDialog.test.tsx b/src/components/GitDialog.test.tsx index faf4e17b..fa03051d 100644 --- a/src/components/GitDialog.test.tsx +++ b/src/components/GitDialog.test.tsx @@ -64,7 +64,7 @@ describe('GitDialog', () => { }); }); - it('renders git repository information', () => { + it('renders git dialog without repository information section', () => { render( {}}> @@ -74,10 +74,8 @@ describe('GitDialog', () => { ); expect(screen.getByText('Git Repository Status')).toBeInTheDocument(); - expect(screen.getByText('Repository Information')).toBeInTheDocument(); - expect(screen.getByText('main')).toBeInTheDocument(); - expect(screen.getByText('5')).toBeInTheDocument(); - expect(screen.getAllByText('origin')).toHaveLength(2); // Appears in remotes and credentials sections + expect(screen.queryByText('Repository Information')).not.toBeInTheDocument(); + expect(screen.getByText('origin')).toBeInTheDocument(); // Appears in credentials section }); it('shows sync status', () => { diff --git a/src/components/GitDialog.tsx b/src/components/GitDialog.tsx index 56ef8f13..8c444aff 100644 --- a/src/components/GitDialog.tsx +++ b/src/components/GitDialog.tsx @@ -31,7 +31,6 @@ import { Plus, Minus, Edit, - RefreshCw, Settings, AlertTriangle, Zap, @@ -399,11 +398,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog } }; - const handleRefresh = async () => { - await refetchGitStatus(); - setPushResult(null); - setPullResult(null); - }; + const getFileStatusIcon = (status: string) => { switch (status) { @@ -486,76 +481,6 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
- {/* Repository Info */} - - - - Repository Information - - - - - {gitStatus?.isGitRepo ? ( - <> -
- Current Branch: - - {gitStatus.currentBranch || 'unknown'} - -
- -
- Total Commits: - {gitStatus.totalCommits} -
- - {gitStatus.latestCommit && ( -
- Latest Commit: -
-
- {gitStatus.latestCommit.oid.substring(0, 7)} -
-
{gitStatus.latestCommit.message}
-
- - {new Date(gitStatus.latestCommit.author.timestamp * 1000).toLocaleString()} -
-
-
- )} - - {gitStatus.remotes.length > 0 && ( -
- Remotes: - {gitStatus.remotes.map((remote) => ( -
-
- {remote.name} - - {remote.url} - -
-
- ))} -
- )} - - ) : ( -
- -

Not a Git repository

-
- )} -
-
{/* Credentials Status */} {gitStatus?.isGitRepo && gitStatus.remotes.length > 0 && ( From fed44cef5e0ece564013d572597276e67298297e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 21 Sep 2025 23:36:08 -0500 Subject: [PATCH 02/22] GitDialog improvements --- src/components/GitDialog.test.tsx | 66 +++++-- src/components/GitDialog.tsx | 293 +++++++++++++++++++----------- 2 files changed, 240 insertions(+), 119 deletions(-) diff --git a/src/components/GitDialog.test.tsx b/src/components/GitDialog.test.tsx index fa03051d..ab2a5081 100644 --- a/src/components/GitDialog.test.tsx +++ b/src/components/GitDialog.test.tsx @@ -43,17 +43,10 @@ vi.mock('@/hooks/useToast', () => ({ })), })); +const mockUseGitSettings = vi.fn(); + vi.mock('@/hooks/useGitSettings', () => ({ - useGitSettings: vi.fn(() => ({ - settings: { - credentials: { - 'https://github.com': { - username: 'git', - password: 'github-token', - }, - }, - }, - })), + useGitSettings: () => mockUseGitSettings(), })); describe('GitDialog', () => { @@ -62,6 +55,17 @@ describe('GitDialog', () => { data: baseGitStatus, refetch: mockRefetch, }); + + mockUseGitSettings.mockReturnValue({ + settings: { + credentials: { + 'https://github.com': { + username: 'git', + password: 'github-token', + }, + }, + }, + }); }); it('renders git dialog without repository information section', () => { @@ -73,9 +77,9 @@ describe('GitDialog', () => { ); - expect(screen.getByText('Git Repository Status')).toBeInTheDocument(); + expect(screen.getByText('Repository')).toBeInTheDocument(); expect(screen.queryByText('Repository Information')).not.toBeInTheDocument(); - expect(screen.getByText('origin')).toBeInTheDocument(); // Appears in credentials section + expect(screen.queryByText('Authentication')).not.toBeInTheDocument(); // Authentication section is removed }); it('shows sync status', () => { @@ -143,7 +147,7 @@ describe('GitDialog', () => { expect(pushButton.closest('button')).toBeDisabled(); }); - it('shows configured credentials status', () => { + it('does not show credentials warning when credentials are configured', () => { render( {}}> @@ -152,8 +156,38 @@ describe('GitDialog', () => { ); - expect(screen.getByText('Authentication')).toBeInTheDocument(); - expect(screen.getByText('github.com')).toBeInTheDocument(); - expect(screen.getByText('Configured')).toBeInTheDocument(); + // Should not show warning when credentials are configured + expect(screen.queryByText(/No credentials configured/)).not.toBeInTheDocument(); + expect(screen.queryByText('Authentication')).not.toBeInTheDocument(); // Authentication section is removed + }); + + it('shows credentials warning when no credentials are configured', () => { + // Mock git settings with no credentials and mock git status with an https remote + mockUseGitSettings.mockReturnValue({ + settings: { + credentials: {}, + }, + }); + + mockUseGitStatus.mockReturnValue({ + data: { + ...baseGitStatus, + remotes: [{ name: 'origin', url: 'https://github.com/example/repo.git' }], + }, + refetch: mockRefetch, + }); + + render( + + {}}> + + + + ); + + // Should show warning when credentials are missing + expect(screen.getByText(/You are not logged into github.com/)).toBeInTheDocument(); + expect(screen.getByText('log in')).toBeInTheDocument(); + expect(screen.queryByText('Authentication')).not.toBeInTheDocument(); // Authentication section is removed }); }); \ No newline at end of file diff --git a/src/components/GitDialog.tsx b/src/components/GitDialog.tsx index 8c444aff..da1ef12c 100644 --- a/src/components/GitDialog.tsx +++ b/src/components/GitDialog.tsx @@ -1,10 +1,9 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, - DialogDescription, DialogHeader, DialogTitle, DialogTrigger, @@ -19,6 +18,8 @@ import { import { Badge } from '@/components/ui/badge'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Alert, AlertDescription } from '@/components/ui/alert'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; import { GitBranch, Upload, @@ -31,9 +32,9 @@ import { Plus, Minus, Edit, - Settings, AlertTriangle, Zap, + Save, } from 'lucide-react'; import { useGitStatus } from '@/hooks/useGitStatus'; import { useGitSettings } from '@/hooks/useGitSettings'; @@ -43,7 +44,7 @@ import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useNostr } from '@nostrify/react'; import { useNostrPublish } from '@/hooks/useNostrPublish'; import { cn } from '@/lib/utils'; -import { findCredentialsForRepo, getOriginDisplayName } from '@/lib/gitCredentials'; +import { findCredentialsForRepo } from '@/lib/gitCredentials'; import { nip19 } from 'nostr-tools'; const GRASP_SERVERS = ["git.shakespeare.diy", "relay.ngit.dev", "gitnostr.com"]; @@ -59,8 +60,8 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog const [isPushing, setIsPushing] = useState(false); const [isPulling, setIsPulling] = useState(false); const [isPushingToNostr, setIsPushingToNostr] = useState(false); - const [pushResult, setPushResult] = useState(null); - const [pullResult, setPullResult] = useState(null); + const [originUrl, setOriginUrl] = useState(''); + const [isSavingOrigin, setIsSavingOrigin] = useState(false); const navigate = useNavigate(); const { data: gitStatus, refetch: refetchGitStatus } = useGitStatus(projectId); @@ -73,6 +74,70 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog const projectPath = `/projects/${projectId}`; + // Initialize origin URL from git status + useEffect(() => { + if (gitStatus?.remotes) { + const originRemote = gitStatus.remotes.find(remote => remote.name === 'origin'); + setOriginUrl(originRemote?.url || ''); + } + }, [gitStatus?.remotes]); + + const handleSaveOrigin = async () => { + if (!gitStatus?.isGitRepo) { + toast({ + title: "Cannot configure origin", + description: "Not a git repository", + variant: "destructive", + }); + return; + } + + setIsSavingOrigin(true); + + try { + // Remove existing origin if it exists + try { + await git.deleteRemote({ + dir: projectPath, + remote: 'origin', + }); + } catch { + // Ignore if origin doesn't exist + } + + // Add new origin if URL is provided + if (originUrl.trim()) { + await git.addRemote({ + dir: projectPath, + remote: 'origin', + url: originUrl.trim(), + }); + + toast({ + title: "Origin configured", + description: `Origin remote set to ${originUrl.trim()}`, + }); + } else { + toast({ + title: "Origin removed", + description: "Origin remote has been removed", + }); + } + + // Refresh git status after changing origin + await refetchGitStatus(); + } catch (error) { + const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; + toast({ + title: "Failed to configure origin", + description: errorMessage, + variant: "destructive", + }); + } finally { + setIsSavingOrigin(false); + } + }; + const handlePushToNostr = async () => { if (!user) { toast({ @@ -93,7 +158,6 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog } setIsPushingToNostr(true); - setPushResult(null); try { // Check if repo announcement already exists @@ -264,10 +328,8 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog description: "Waiting for GRASP servers to update...", }); - setPushResult(`✅ Successfully published repository to Nostr`); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; - setPushResult(`❌ Push to Nostr failed: ${errorMessage}`); toast({ title: "Push to Nostr failed", description: errorMessage, @@ -307,7 +369,6 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog } setIsPushing(true); - setPushResult(null); try { const remote = gitStatus.remotes[0]; // Use first remote (usually 'origin') @@ -320,7 +381,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog signer: user?.signer, // For signing if pushing to Nostr }); - setPushResult(`✅ Successfully pushed ${gitStatus.ahead} commit${gitStatus.ahead !== 1 ? 's' : ''} to ${remote.name}/${gitStatus.currentBranch}`); + toast({ title: "Push successful", description: `${gitStatus.ahead} commit${gitStatus.ahead !== 1 ? 's' : ''} pushed to ${remote.name}/${gitStatus.currentBranch}`, @@ -330,7 +391,6 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog await refetchGitStatus(); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; - setPushResult(`❌ Push failed: ${errorMessage}`); toast({ title: "Push failed", description: errorMessage, @@ -361,7 +421,6 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog } setIsPulling(true); - setPullResult(null); try { const remote = gitStatus.remotes[0]; // Use first remote (usually 'origin') @@ -377,7 +436,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog onAuth: (url) => findCredentialsForRepo(url, settings.credentials), }); - setPullResult(`✅ Successfully pulled from ${remote.name}/${gitStatus.currentBranch}`); + toast({ title: "Pull successful", description: `Latest changes pulled from ${remote.name}/${gitStatus.currentBranch}`, @@ -387,7 +446,6 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog await refetchGitStatus(); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; - setPullResult(`❌ Pull failed: ${errorMessage}`); toast({ title: "Pull failed", description: errorMessage, @@ -472,85 +530,128 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog - Git Repository Status + Repository - - View repository status and sync with remote repositories - + {/* URL Configuration */} + {gitStatus?.isGitRepo && ( + + + Git URL + + +
+
+ + setOriginUrl(e.target.value)} + disabled={isSavingOrigin} + /> +
+ +
+ + {/* Credentials Warning */} + {gitStatus.remotes.length > 0 && ( + (() => { + const remoteWithoutCredentials = gitStatus.remotes.find((remote) => !findCredentialsForRepo(remote.url, settings.credentials)); + if (!remoteWithoutCredentials) return null; + + let protocol = ''; + let hostname = 'the remote host'; + try { + const url = new URL(remoteWithoutCredentials.url); + protocol = url.protocol; + hostname = url.hostname; + } catch { + // Invalid URL + return ( + + + + Invalid URL format. Enter an https URL. + + + ); + } + + // Check for unsupported protocols + if (protocol !== 'https:' && protocol !== 'nostr:') { + return ( + + + + The {protocol.replace(':', '')} URL type is not supported. Enter an https URL. + + + ); + } + + // For nostr protocol, only show warning if user is not logged in + if (protocol === 'nostr:' && !user) { + return ( + + + + You are not logged into Nostr. Push & pull might not work unless you{' '} + . + + + ); + } + + // For https protocol, show warning if no credentials + if (protocol === 'https:') { + return ( + + + + You are not logged into {hostname}. Push & pull might not work unless you{' '} + . + + + ); + } + + return null; + })() + )} +
+
+ )} +
- {/* Credentials Status */} - {gitStatus?.isGitRepo && gitStatus.remotes.length > 0 && ( - - - - Authentication - - - - Credentials for push/pull operations - - - - {gitStatus.remotes.map((remote) => { - const credentials = findCredentialsForRepo(remote.url, settings.credentials); - const originDisplayName = getOriginDisplayName(remote.url); - - return ( -
-
-
- {remote.name} - - {originDisplayName} - -
- {credentials ? ( -
- - Configured -
- ) : ( -
- - No credentials -
- )} -
- - {!credentials && ( - - - - No credentials configured for {originDisplayName}. - Push/pull operations may fail for private repositories.{' '} - - - - )} -
- ); - })} -
-
- )} - {/* Sync Status */} {gitStatus?.isGitRepo && ( @@ -619,21 +720,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
)} - {/* Operation Results */} - {(pushResult || pullResult) && ( -
- {pushResult && ( -
- {pushResult} -
- )} - {pullResult && ( -
- {pullResult} -
- )} -
- )} + )} From 16ee1235d394e7f788de40705ca483d26d6da2ea Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 21 Sep 2025 23:49:02 -0500 Subject: [PATCH 03/22] Fix Git History overflow --- src/components/ai/GitHistoryDialog.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/ai/GitHistoryDialog.tsx b/src/components/ai/GitHistoryDialog.tsx index 9381d3a7..e84845a4 100644 --- a/src/components/ai/GitHistoryDialog.tsx +++ b/src/components/ai/GitHistoryDialog.tsx @@ -1,7 +1,6 @@ import { useState, useEffect, useCallback } from 'react'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; -import { ScrollArea } from '@/components/ui/scroll-area'; import { Badge } from '@/components/ui/badge'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog'; import { History, GitCommit, RotateCcw, AlertTriangle, ChevronDown, ChevronUp } from 'lucide-react'; @@ -289,7 +288,7 @@ ${commitsToRevert.map(c => { )} - + @@ -300,7 +299,7 @@ ${commitsToRevert.map(c => { -
+
{isLoading ? (
@@ -329,7 +328,7 @@ ${commitsToRevert.map(c => {
) : ( - +
{commits.map((commit, index) => { const { firstLine, hasMoreLines, fullMessage } = getCommitMessageLines(commit.commit.message); @@ -340,7 +339,7 @@ ${commitsToRevert.map(c => {
-

+

{firstLine}

{hasMoreLines && ( @@ -440,7 +439,7 @@ ${commitsToRevert.map(c => { ); })}
- +
)}
From 25f11dbe1d4f3e6c59bda7d57ba6a391a48a0232 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 22 Sep 2025 00:02:52 -0500 Subject: [PATCH 04/22] Start simplifying 3-dots menu --- src/components/ActionsMenu.tsx | 21 +---- src/components/AppSettingsDialog.tsx | 108 ------------------------- src/components/ai/GitHistoryDialog.tsx | 25 +++--- 3 files changed, 20 insertions(+), 134 deletions(-) delete mode 100644 src/components/AppSettingsDialog.tsx diff --git a/src/components/ActionsMenu.tsx b/src/components/ActionsMenu.tsx index cb69af3b..ba54787b 100644 --- a/src/components/ActionsMenu.tsx +++ b/src/components/ActionsMenu.tsx @@ -24,15 +24,13 @@ import { Play, CloudUpload, Loader2, - GitBranch, + History, Download, Trash2, - Settings, GitMerge, } from 'lucide-react'; import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog'; import { GitDialog } from '@/components/GitDialog'; -import { AppSettingsDialog } from '@/components/AppSettingsDialog'; import { useNavigate } from 'react-router-dom'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useToast } from '@/hooks/useToast'; @@ -222,7 +220,7 @@ export function ActionsMenu({ className="gap-2" > - Git Status + Repository - - Git History + + Rollback - - e.preventDefault()} - > - - Settings - - - { - // Validate deploy server - if (!deployServer.trim()) { - toast({ - title: "Invalid deploy server", - description: "Deploy server cannot be empty.", - variant: "destructive", - }); - return; - } - - // Remove protocol if present - const cleanDeployServer = deployServer.replace(/^https?:\/\//, ''); - - updateConfig((current) => ({ - ...current, - deployServer: cleanDeployServer, - })); - - toast({ - title: "Settings saved", - description: "Your deployment settings have been updated.", - }); - - setOpen(false); - }; - - const handleCancel = () => { - // Reset to current config - setDeployServer(config.deployServer); - setOpen(false); - }; - - return ( - - - {children || ( - - )} - - - - App Settings - - Configure your application preferences and deployment settings. - - - -
- - - Deployment - - -
- - setDeployServer(e.target.value)} - placeholder="shakespeare.wtf" - className="font-mono" - /> -

- Your projects will be deployed to subdomains of this server. - Example: yourproject.{deployServer || 'shakespeare.wtf'} -

-
-
-
-
- -
- - -
-
-
- ); -} \ No newline at end of file diff --git a/src/components/ai/GitHistoryDialog.tsx b/src/components/ai/GitHistoryDialog.tsx index e84845a4..2dc7f3fa 100644 --- a/src/components/ai/GitHistoryDialog.tsx +++ b/src/components/ai/GitHistoryDialog.tsx @@ -1,7 +1,7 @@ import { useState, useEffect, useCallback } from 'react'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; -import { Badge } from '@/components/ui/badge'; + import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog'; import { History, GitCommit, RotateCcw, AlertTriangle, ChevronDown, ChevronUp } from 'lucide-react'; import { useGit } from '@/hooks/useGit'; @@ -291,11 +291,11 @@ ${commitsToRevert.map(c => { - - Git History + + Rollback - View the commit history for this project + Revert to an older commit @@ -371,7 +371,18 @@ ${commitsToRevert.map(c => {
- {index > 0 && ( // Don't show rollback for the most recent commit + {index === 0 ? ( + // Show "Current" for the most recent commit + + ) : ( + // Show rollback button for older commits
From 6478ed21bb2c742e72ab248bf42d33b0ec5b06c8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 22 Sep 2025 00:10:08 -0500 Subject: [PATCH 05/22] Remove pointless "File Explorer" header --- src/components/Shakespeare/PreviewPane.tsx | 32 ++++++---------------- src/lib/i18n.ts | 3 -- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/components/Shakespeare/PreviewPane.tsx b/src/components/Shakespeare/PreviewPane.tsx index 7d7ed0d7..19c54fe3 100644 --- a/src/components/Shakespeare/PreviewPane.tsx +++ b/src/components/Shakespeare/PreviewPane.tsx @@ -536,24 +536,16 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) { {isMobile ? (
{mobileCodeView === 'explorer' ? ( - <> -
-
-

{t('fileExplorer')}

- -
+ + +
+
- - -
- -
-
- +
) : ( <>
@@ -604,12 +596,6 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) { ) : (
-
-
-

{t('fileExplorer')}

- -
-
diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts index 48e19e05..81a6d02e 100644 --- a/src/lib/i18n.ts +++ b/src/lib/i18n.ts @@ -111,7 +111,6 @@ const resources = { // Preview Pane projectPreview: 'Project Preview', buildProjectToSeePreview: 'Build your project to see the preview here', - fileExplorer: 'File Explorer', fileEditor: 'File Editor', selectFileFromExplorer: 'Select a file from the explorer to edit', openFileExplorer: 'Open File Explorer', @@ -404,7 +403,6 @@ const resources = { // Preview Pane projectPreview: 'Visualização do Projeto', buildProjectToSeePreview: 'Construa seu projeto para ver a visualização aqui', - fileExplorer: 'Explorador de Arquivos', fileEditor: 'Editor de Arquivos', selectFileFromExplorer: 'Selecione um arquivo do explorador para editar', openFileExplorer: 'Abrir Explorador de Arquivos', @@ -697,7 +695,6 @@ const resources = { // Preview Pane projectPreview: '项目预览', buildProjectToSeePreview: '构建您的项目以在此处查看预览', - fileExplorer: '文件浏览器', fileEditor: '文件编辑器', selectFileFromExplorer: '从浏览器中选择一个文件进行编辑', openFileExplorer: '打开文件浏览器', From 369286383028dfc08972d99e0f4a6434b6b50188 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 22 Sep 2025 00:20:56 -0500 Subject: [PATCH 06/22] GitDialog tweaks --- src/components/ActionsMenu.tsx | 4 ++-- src/components/GitDialog.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/ActionsMenu.tsx b/src/components/ActionsMenu.tsx index ba54787b..1d18e4bd 100644 --- a/src/components/ActionsMenu.tsx +++ b/src/components/ActionsMenu.tsx @@ -19,6 +19,7 @@ import { AlertDialogTrigger, } from '@/components/ui/alert-dialog'; import { + GitBranch, MoreHorizontal, MessageSquarePlus, Play, @@ -27,7 +28,6 @@ import { History, Download, Trash2, - GitMerge, } from 'lucide-react'; import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog'; import { GitDialog } from '@/components/GitDialog'; @@ -219,7 +219,7 @@ export function ActionsMenu({ disabled={isAnyLoading} className="gap-2" > - + Repository diff --git a/src/components/GitDialog.tsx b/src/components/GitDialog.tsx index da1ef12c..1aa22072 100644 --- a/src/components/GitDialog.tsx +++ b/src/components/GitDialog.tsx @@ -526,7 +526,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog return ( {children && {children}} - + e.preventDefault()}> @@ -559,7 +559,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog disabled={isSavingOrigin} variant="outline" size="sm" - className="shrink-0" + className="h-10 shrink-0" > {isSavingOrigin ? ( From 668a6c79d9d5921da3b4ef4c6030af24626f2696 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 22 Sep 2025 01:08:05 -0500 Subject: [PATCH 07/22] Greatly simplify ProjectInfoDialog, move Export Project into there --- src/components/ActionsMenu.tsx | 108 +------ src/components/ProjectInfoDialog.tsx | 409 +++++++-------------------- 2 files changed, 99 insertions(+), 418 deletions(-) diff --git a/src/components/ActionsMenu.tsx b/src/components/ActionsMenu.tsx index 1d18e4bd..3a861ec1 100644 --- a/src/components/ActionsMenu.tsx +++ b/src/components/ActionsMenu.tsx @@ -26,7 +26,6 @@ import { CloudUpload, Loader2, History, - Download, Trash2, } from 'lucide-react'; import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog'; @@ -34,9 +33,6 @@ import { GitDialog } from '@/components/GitDialog'; import { useNavigate } from 'react-router-dom'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useToast } from '@/hooks/useToast'; -import { useGit } from '@/hooks/useGit'; -import { useFS } from '@/hooks/useFS'; -import JSZip from 'jszip'; interface ActionsMenuProps { projectId: string; @@ -68,15 +64,12 @@ export function ActionsMenu({ const [gitHistoryOpen, setGitHistoryOpen] = useState(false); const [gitDialogOpen, setGitDialogOpen] = useState(false); const [isDeleting, setIsDeleting] = useState(false); - const [isExporting, setIsExporting] = useState(false); const navigate = useNavigate(); const projectsManager = useProjectsManager(); const { toast } = useToast(); - const { fs } = useFS(); - const { git } = useGit(); - const isAnyLoading = isLoading || isBuildLoading || isDeployLoading || isDeleting || isExporting; + const isAnyLoading = isLoading || isBuildLoading || isDeployLoading || isDeleting; const handleDeleteProject = async () => { setIsDeleting(true); @@ -104,92 +97,6 @@ export function ActionsMenu({ } }; - const handleExportProject = async () => { - setIsExporting(true); - try { - const zip = new JSZip(); - const projectPath = `/projects/${projectId}`; - - // Recursive function to add files and directories to zip from a specific project - const addProjectToZip = async (dirPath: string, zipFolder: JSZip) => { - try { - const entries = await fs.readdir(dirPath, { withFileTypes: true }); - - for (const entry of entries) { - const fullPath = `${dirPath}/${entry.name}`; - - if (entry.isDirectory()) { - // Create folder in zip and recursively add its contents - const folder = zipFolder.folder(entry.name); - if (folder) { - await addProjectToZip(fullPath, folder); - } - } else if (entry.isFile()) { - // Add file to zip - try { - const fileContent = await fs.readFile(fullPath); - zipFolder.file(entry.name, fileContent); - } catch (error) { - console.warn(`Failed to read file ${fullPath}:`, error); - } - } - } - } catch (error) { - console.warn(`Failed to read directory ${dirPath}:`, error); - } - }; - - // Start from the project directory - await addProjectToZip(projectPath, zip); - - // Generate zip file - const content = await zip.generateAsync({ type: 'blob' }); - - // Create download link - const url = URL.createObjectURL(content); - const link = document.createElement('a'); - link.href = url; - - // Generate filename with commit hash - let filename = `${projectName}.zip`; - try { - // Get the current commit hash - const commits = await git.log({ - dir: projectPath, - depth: 1, - }); - - if (commits.length > 0) { - const commitHash = commits[0].oid.substring(0, 7); // Truncate to 7 characters - filename = `${projectName}-${commitHash}.zip`; - } - } catch (error) { - console.warn('Failed to get commit hash, using project name only:', error); - } - - link.download = filename; - - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - URL.revokeObjectURL(url); - - toast({ - title: "Project exported successfully", - description: `"${projectName}" has been downloaded as a zip file.`, - }); - } catch (error) { - console.error('Failed to export project:', error); - toast({ - title: "Failed to export project", - description: error instanceof Error ? error.message : "An unexpected error occurred", - variant: "destructive", - }); - } finally { - setIsExporting(false); - } - }; - return ( <> @@ -232,19 +139,6 @@ export function ActionsMenu({ Rollback - - {isExporting ? ( - - ) : ( - - )} - {isExporting ? 'Exporting...' : 'Export Project'} - - { if (onFirstInteraction) onFirstInteraction(); diff --git a/src/components/ProjectInfoDialog.tsx b/src/components/ProjectInfoDialog.tsx index 33fdf923..0c4bb8cd 100644 --- a/src/components/ProjectInfoDialog.tsx +++ b/src/components/ProjectInfoDialog.tsx @@ -1,36 +1,21 @@ -import { useState, useEffect } from 'react'; +import { useState } from 'react'; import { type Project } from '@/lib/ProjectsManager'; -import { useProjectsManager } from '@/hooks/useProjectsManager'; -import { useGitStatus } from '@/hooks/useGitStatus'; import { Dialog, DialogContent, - DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; -import { Badge } from '@/components/ui/badge'; -import { Separator } from '@/components/ui/separator'; -import { Skeleton } from '@/components/ui/skeleton'; +import { Button } from '@/components/ui/button'; +import { useToast } from '@/hooks/useToast'; +import { useFS } from '@/hooks/useFS'; import { Calendar, Folder, - GitBranch, - Package, - FileText, - GitCommit, - GitMerge, - Globe, - Clock, - User, - Hash, - AlertCircle, - CheckCircle, - Plus, - Minus, - Edit, - Eye + Download, + Loader2, } from 'lucide-react'; +import JSZip from 'jszip'; interface ProjectInfoDialogProps { project: Project; @@ -38,75 +23,10 @@ interface ProjectInfoDialogProps { onOpenChange: (open: boolean) => void; } -interface ProjectMetadata { - description?: string; - version?: string; - nostrRepoAddress?: string; - fileCount?: number; -} - export function ProjectInfoDialog({ project, open, onOpenChange }: ProjectInfoDialogProps) { - const [metadata, setMetadata] = useState({}); - const [isLoading, setIsLoading] = useState(false); - const projectsManager = useProjectsManager(); - const gitStatus = useGitStatus(project.id); - - useEffect(() => { - if (!open) return; - - const loadProjectMetadata = async () => { - setIsLoading(true); - try { - const meta: ProjectMetadata = {}; - - // Try to read package.json - try { - const packageJsonContent = await projectsManager.readFile(project.id, 'package.json'); - const packageJson = JSON.parse(packageJsonContent); - meta.description = packageJson.description; - meta.version = packageJson.version; - } catch { - // package.json doesn't exist or is invalid - } - - // Get Nostr repo address - try { - const repoAddress = await projectsManager.getNostrRepoAddress(project.id); - if (repoAddress) { - meta.nostrRepoAddress = repoAddress; - } - } catch { - // No Nostr repo configured - } - - // Calculate file count and size (simplified) - try { - const files = await projectsManager.listFiles(project.id); - meta.fileCount = files.length; - } catch { - // Can't read directory - } - - setMetadata(meta); - } catch (error) { - console.error('Failed to load project metadata:', error); - } finally { - setIsLoading(false); - } - }; - - loadProjectMetadata(); - }, [open, project.id, projectsManager]); - - const formatDate = (date: Date) => { - return new Intl.DateTimeFormat('en-US', { - year: 'numeric', - month: 'long', - day: 'numeric', - hour: '2-digit', - minute: '2-digit', - }).format(date); - }; + const [isExporting, setIsExporting] = useState(false); + const { toast } = useToast(); + const { fs } = useFS(); const formatDistanceToNow = (date: Date) => { const now = new Date(); @@ -120,239 +40,106 @@ export function ProjectInfoDialog({ project, open, onOpenChange }: ProjectInfoDi return `${Math.floor(diffInSeconds / 31536000)} years ago`; }; + const handleExportProject = async () => { + setIsExporting(true); + try { + const zip = new JSZip(); + const projectPath = `/projects/${project.id}`; + + // Recursive function to add files and directories to zip from a specific project + const addFolderToZip = async (dirPath: string, zipFolder: JSZip) => { + try { + const entries = await fs.readdir(dirPath, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = `${dirPath}/${entry.name}`; + + if (entry.isDirectory()) { + // Create folder in zip and recursively add its contents + const folder = zipFolder.folder(entry.name); + if (folder) { + await addFolderToZip(fullPath, folder); + } + } else if (entry.isFile()) { + // Add file to zip + try { + const fileContent = await fs.readFile(fullPath); + zipFolder.file(entry.name, fileContent); + } catch (error) { + console.warn(`Failed to read file ${fullPath}:`, error); + } + } + } + } catch (error) { + console.warn(`Failed to read directory ${dirPath}:`, error); + } + }; + + // Start from the project directory + await addFolderToZip(projectPath, zip); + + // Generate zip file + const content = await zip.generateAsync({ type: 'blob' }); + + // Create download link + const url = URL.createObjectURL(content); + const link = document.createElement('a'); + link.href = url; + link.download = `${project.id}.zip`; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(url); + + toast({ + title: "Project exported successfully", + description: `"${project.name}" has been downloaded as a zip file.`, + }); + } catch (error) { + console.error('Failed to export project:', error); + toast({ + title: "Failed to export project", + description: error instanceof Error ? error.message : "An unexpected error occurred", + variant: "destructive", + }); + } finally { + setIsExporting(false); + } + }; + return ( - + {project.name} - - Project information and metadata - - {isLoading ? ( -
-
-
-
-
+
+ {/* Last Modified */} +
+ + Last Modified: + {formatDistanceToNow(project.lastModified)}
- ) : ( -
- {/* Basic Information */} -
-

- Basic Information -

-
-
- - Project ID: - {project.id} -
-
- - Last Modified: - {formatDistanceToNow(project.lastModified)} -
- {metadata.version && ( -
- - Version: - {metadata.version} -
- )} - {metadata.fileCount !== undefined && ( -
- - Files: - {metadata.fileCount} -
- )} -
-
- Created: - {formatDate(project.lastModified)} -
- {metadata.description && ( -
- Description: -

{metadata.description}

-
- )} -
- {/* Nostr Information */} - {metadata.nostrRepoAddress && ( - <> - -
-

- - Nostr Repository -

-
- Repository Address: - - {metadata.nostrRepoAddress} - -
-
- + {/* Export Project Button */} +
- )} + {isExporting ? 'Exporting...' : 'Export Project'} + +
); From 46a5ca2a1e655bcfb07a89bcb6355197d0278082 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 22 Sep 2025 01:24:31 -0500 Subject: [PATCH 08/22] Add useBuildProject, useDeployProject hooks --- src/hooks/useBuildProject.ts | 17 ++++++ src/hooks/useDeployProject.ts | 26 ++++++++ src/pages/ProjectView.tsx | 109 ++++++++++++++-------------------- 3 files changed, 86 insertions(+), 66 deletions(-) create mode 100644 src/hooks/useBuildProject.ts create mode 100644 src/hooks/useDeployProject.ts diff --git a/src/hooks/useBuildProject.ts b/src/hooks/useBuildProject.ts new file mode 100644 index 00000000..3fd705db --- /dev/null +++ b/src/hooks/useBuildProject.ts @@ -0,0 +1,17 @@ +import { useMutation } from "@tanstack/react-query"; +import { buildProject } from "@/lib/build"; +import { useFS } from "./useFS"; + +export function useBuildProject(projectId: string) { + const { fs } = useFS(); + + return useMutation({ + mutationFn: async () => { + return await buildProject({ + fs, + projectPath: `/projects/${projectId}`, + domParser: new DOMParser(), + }); + }, + }); +} \ No newline at end of file diff --git a/src/hooks/useDeployProject.ts b/src/hooks/useDeployProject.ts new file mode 100644 index 00000000..9793ee1d --- /dev/null +++ b/src/hooks/useDeployProject.ts @@ -0,0 +1,26 @@ +import { useMutation } from "@tanstack/react-query"; +import { deployProject } from "@/lib/deploy"; +import { useFS } from "./useFS"; +import { useAppContext } from "./useAppContext"; +import { useCurrentUser } from "./useCurrentUser"; + +export function useDeployProject(projectId: string) { + const { fs } = useFS(); + const { user } = useCurrentUser(); + const { config } = useAppContext(); + + return useMutation({ + mutationFn: async () => { + if (!user) { + throw new Error("You must be logged into Nostr to deploy a project"); + } + return await deployProject({ + fs, + projectId: projectId, + deployServer: config.deployServer, + projectPath: `/projects/${projectId}`, + signer: user.signer, + }); + }, + }); +} \ No newline at end of file diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx index 01e9d2fd..439bf9a1 100644 --- a/src/pages/ProjectView.tsx +++ b/src/pages/ProjectView.tsx @@ -13,18 +13,14 @@ import { Skeleton } from '@/components/ui/skeleton'; import { ArrowLeft, MessageSquare, Eye, Code, Menu } from 'lucide-react'; import { useNavigate } from 'react-router-dom'; import { ActionsMenu } from '@/components/ActionsMenu'; - import { useIsMobile } from '@/hooks/useIsMobile'; -import { useFS } from '@/hooks/useFS'; import { useKeepAlive } from '@/hooks/useKeepAlive'; import { GitStatusIndicator } from '@/components/GitStatusIndicator'; import { StarButton } from '@/components/StarButton'; - -import { buildProject } from "@/lib/build"; -import { deployProject } from "@/lib/deploy"; import { useCurrentUser } from "@/hooks/useCurrentUser"; -import { useAppContext } from "@/hooks/useAppContext"; import { useToast } from "@/hooks/useToast"; +import { useBuildProject } from '@/hooks/useBuildProject'; +import { useDeployProject } from '@/hooks/useDeployProject'; export function ProjectView() { const { projectId } = useParams<{ projectId: string }>(); @@ -33,23 +29,22 @@ export function ProjectView() { const [isLoading, setIsLoading] = useState(true); const [activeTab, setActiveTab] = useState<'preview' | 'code'>('preview'); const [mobileView, setMobileView] = useState<'chat' | 'preview' | 'code'>('chat'); - const [isBuildLoading, setIsBuildLoading] = useState(false); - const [isDeployLoading, setIsDeployLoading] = useState(false); const [isAILoading, setIsAILoading] = useState(false); const [isProjectInfoOpen, setIsProjectInfoOpen] = useState(false); const projectsManager = useProjectsManager(); const chatPaneRef = useRef(null); const navigate = useNavigate(); const isMobile = useIsMobile(); - const { fs } = useFS(); const { user } = useCurrentUser(); - const { config } = useAppContext(); const { toast } = useToast(); const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile); + const build = useBuildProject(projectId!); + const deploy = useDeployProject(projectId!); + // Keep-alive functionality to prevent tab throttling during AI processing const { updateMetadata } = useKeepAlive({ - enabled: isAILoading || isBuildLoading || isDeployLoading, + enabled: isAILoading || build.isPending || deploy.isPending, title: 'Shakespeare', artist: project ? `Working on ${project.name}...` : 'Working...', artwork: [ @@ -79,28 +74,21 @@ export function ProjectView() { }, [loadProject]); const runBuild = async () => { - if (isBuildLoading || !project) return; - - setIsBuildLoading(true); + if (build.isPending || !project) return; updateMetadata('Shakespeare', `Building ${project.name}...`); - try { - const result = await buildProject({ - fs, - projectPath: `/projects/${project.id}`, - domParser: new DOMParser(), - }); - - console.log('Build completed:', result); - } catch (error) { - console.error('Build failed:', error); - } finally { - setIsBuildLoading(false); - } + await build.mutateAsync(undefined, { + onSuccess(result) { + console.log('Project built:', result); + }, + onError(error) { + console.error('Build failed:', error); + }, + }); }; const runDeploy = async () => { - if (isDeployLoading || !project) return; + if (deploy.isPending || !project) return; // Check if user is logged in if (!user || !user.signer) { @@ -112,38 +100,27 @@ export function ProjectView() { return; } - setIsDeployLoading(true); updateMetadata('Shakespeare', `Deploying ${project.name}...`); - try { - const result = await deployProject({ - projectId: project.id, - deployServer: config.deployServer, - fs, - projectPath: `/projects/${project.id}`, - signer: user.signer, - }); - - console.log('Project deployed:', result.url); - - toast({ - title: "Deployment successful!", - description: `Your project is now live at ${result.hostname}`, - }); - - // Open the deployed site in a new tab - window.open(result.url, '_blank'); - } catch (error) { - console.error('Deploy failed:', error); - - toast({ - title: "Deployment failed", - description: error instanceof Error ? error.message : "An unexpected error occurred", - variant: "destructive", - }); - } finally { - setIsDeployLoading(false); - } + await deploy.mutateAsync(undefined, { + onSuccess(result) { + console.log('Project deployed:', result.url); + toast({ + title: "Deployment successful!", + description: `Your project is now live at ${result.hostname}`, + }); + // Open the deployed site in a new tab + window.open(result.url, '_blank'); + }, + onError(error) { + console.error('Deploy failed:', error); + toast({ + title: "Deployment failed", + description: error instanceof Error ? error.message : "An unexpected error occurred", + variant: "destructive", + }); + }, + }); }; const handleNewChat = () => { @@ -228,8 +205,8 @@ export function ProjectView() { onBuild={runBuild} onDeploy={runDeploy} isLoading={isAILoading} - isBuildLoading={isBuildLoading} - isDeployLoading={isDeployLoading} + isBuildLoading={build.isPending} + isDeployLoading={deploy.isPending} onFirstInteraction={handleFirstInteraction} onProjectDeleted={handleProjectDeleted} /> @@ -283,8 +260,8 @@ export function ProjectView() { onFirstInteraction={handleFirstInteraction} onLoadingChange={handleAILoadingChange} isLoading={isAILoading} - isBuildLoading={isBuildLoading} - isDeployLoading={isDeployLoading} + isBuildLoading={build.isPending} + isDeployLoading={deploy.isPending} /> ) : (
@@ -435,8 +412,8 @@ export function ProjectView() { onBuild={runBuild} onDeploy={runDeploy} isLoading={isAILoading} - isBuildLoading={isBuildLoading} - isDeployLoading={isDeployLoading} + isBuildLoading={build.isPending} + isDeployLoading={deploy.isPending} onFirstInteraction={handleFirstInteraction} onProjectDeleted={handleProjectDeleted} /> @@ -463,8 +440,8 @@ export function ProjectView() { onFirstInteraction={handleFirstInteraction} onLoadingChange={handleAILoadingChange} isLoading={isAILoading} - isBuildLoading={isBuildLoading} - isDeployLoading={isDeployLoading} + isBuildLoading={build.isPending} + isDeployLoading={deploy.isPending} /> ) : (
From 7cbaaec734958d2a6a5c50650bd9c763a46d1abb Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 22 Sep 2025 01:55:34 -0500 Subject: [PATCH 09/22] 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={( +
+ + +
+ )} />