diff --git a/src/components/Shakespeare/PreviewPane.tsx b/src/components/Shakespeare/PreviewPane.tsx index 30e72057..7da345e5 100644 --- a/src/components/Shakespeare/PreviewPane.tsx +++ b/src/components/Shakespeare/PreviewPane.tsx @@ -21,6 +21,7 @@ import { import { FileTree } from './FileTree'; import { FileEditor } from './FileEditor'; import { DeployDialog } from '@/components/DeployDialog'; +import { useSearchParams } from 'react-router-dom'; // Get iframe domain from environment variable const IFRAME_DOMAIN = import.meta.env.VITE_IFRAME_DOMAIN || 'local-shakespeare.dev'; @@ -89,13 +90,36 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o const projectsManager = useProjectsManager(); const { mutate: buildProject, isPending: isBuildLoading } = useBuildProject(projectId); - const handleBuildProject = () => { + const [searchParams, setSearchParams] = useSearchParams(); + const [shouldBuild, setShouldBuild] = useState(false); + + const handleBuildProject = useCallback(() => { buildProject(undefined, { onError: (error) => { console.error('Build failed:', error); } }); - }; + }, [buildProject]); + + // Handle "build" URL parameter on initial load + useEffect(() => { + if (searchParams.has('build')) { + setShouldBuild(true); + + // Remove the build parameter from URL + const newSearchParams = new URLSearchParams(searchParams); + newSearchParams.delete('build'); + setSearchParams(newSearchParams, { replace: true }); + } + }, [searchParams, setSearchParams]); + + // Build automatically if "build" parameter was present + useEffect(() => { + if (shouldBuild && isPreviewable && !isBuildLoading) { + setShouldBuild(false); + handleBuildProject(); + } + }, [isBuildLoading, isPreviewable, handleBuildProject, shouldBuild]); const loadFileContent = useCallback(async (filePath: string) => { setIsLoading(true); diff --git a/src/pages/Clone.tsx b/src/pages/Clone.tsx index 1a3b94f8..01ec43ca 100644 --- a/src/pages/Clone.tsx +++ b/src/pages/Clone.tsx @@ -116,8 +116,8 @@ export default function Clone() { description: successDescription, }); - // Navigate to the new project - navigate(`/project/${project.id}`); + // Navigate to the new project with build parameter + navigate(`/project/${project.id}?build`); } catch (error) { console.error('Failed to clone repository:', error);