diff --git a/src/components/Shakespeare/PreviewPane.tsx b/src/components/Shakespeare/PreviewPane.tsx index 335ef465..bb1559af 100644 --- a/src/components/Shakespeare/PreviewPane.tsx +++ b/src/components/Shakespeare/PreviewPane.tsx @@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button'; import { RefreshCw, FolderOpen, ArrowLeft } from 'lucide-react'; import { useIsMobile } from '@/hooks/useIsMobile'; import { GitStatusIndicator } from '@/components/GitStatusIndicator'; +import { BrowserAddressBar } from '@/components/ui/browser-address-bar'; import { FileTree } from './FileTree'; import { FileEditor } from './FileEditor'; @@ -53,6 +54,9 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) { const [mobileCodeView, setMobileCodeView] = useState<'explorer' | 'editor'>('explorer'); const isMobile = useIsMobile(); const [hasBuiltProject, setHasBuiltProject] = useState(false); + const [currentPath, setCurrentPath] = useState('/'); + const [navigationHistory, setNavigationHistory] = useState(['/']); + const [historyIndex, setHistoryIndex] = useState(0); const iframeRef = useRef(null); const { fs } = useFS(); const projectsManager = useProjectsManager(); @@ -120,6 +124,51 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) { } }, []); + const navigateToPath = useCallback((path: string) => { + if (iframeRef.current) { + const baseUrl = `https://${projectId}.local-shakespeare.dev`; + const newUrl = `${baseUrl}${path}`; + iframeRef.current.src = newUrl; + setCurrentPath(path); + + // Update navigation history + const newHistory = navigationHistory.slice(0, historyIndex + 1); + newHistory.push(path); + setNavigationHistory(newHistory); + setHistoryIndex(newHistory.length - 1); + } + }, [projectId, navigationHistory, historyIndex]); + + const goBack = useCallback(() => { + if (historyIndex > 0) { + const newIndex = historyIndex - 1; + const path = navigationHistory[newIndex]; + setHistoryIndex(newIndex); + setCurrentPath(path); + + if (iframeRef.current) { + const baseUrl = `https://${projectId}.local-shakespeare.dev`; + const newUrl = `${baseUrl}${path}`; + iframeRef.current.src = newUrl; + } + } + }, [historyIndex, navigationHistory, projectId]); + + const goForward = useCallback(() => { + if (historyIndex < navigationHistory.length - 1) { + const newIndex = historyIndex + 1; + const path = navigationHistory[newIndex]; + setHistoryIndex(newIndex); + setCurrentPath(path); + + if (iframeRef.current) { + const baseUrl = `https://${projectId}.local-shakespeare.dev`; + const newUrl = `${baseUrl}${path}`; + iframeRef.current.src = newUrl; + } + } + }, [historyIndex, navigationHistory, projectId]); + const sendResponse = useCallback((message: JSONRPCResponse) => { if (iframeRef.current?.contentWindow) { console.log(`Sending response to iframe:`, message); @@ -303,20 +352,18 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) { {hasBuiltProject ? (
-
- Project Preview - -
+ 0} + canGoForward={historyIndex < navigationHistory.length - 1} + />