diff --git a/src/client/components/Nav.tsx b/src/client/components/Nav.tsx index 34d8472..61f0429 100644 --- a/src/client/components/Nav.tsx +++ b/src/client/components/Nav.tsx @@ -1,9 +1,15 @@ import type { App } from '../../shared/types' -import { apps, selectedTab, setSelectedTab } from '../state' +import { apps, selectedApp, selectedTab, setSelectedTab } from '../state' import { Tab, TabBar } from '../styles' +import { resetToolIframe } from '../tool-iframes' export function Nav({ app, render }: { app: App; render: () => void }) { const handleTabClick = (tab: string) => { + // If clicking already-selected tool tab, reset to home + if (tab === selectedTab && tab !== 'overview') { + resetToolIframe(tab, selectedApp) + return + } setSelectedTab(tab) render() } diff --git a/src/client/tool-iframes.ts b/src/client/tool-iframes.ts index 39a05ae..1b38b0f 100644 --- a/src/client/tool-iframes.ts +++ b/src/client/tool-iframes.ts @@ -28,7 +28,7 @@ function setupMessageListener() { for (const [, cached] of iframes) { if (cached.iframe.contentWindow === event.source) { cached.contentHeight = height - cached.iframe.style.height = `100vh` + cached.iframe.style.height = `${height}px` return } } @@ -85,6 +85,19 @@ function buildCacheKey(toolName: string, params: Record): string return parts.join(':') } +// Reset a tool iframe to its home page +export function resetToolIframe(toolName: string, selectedApp: string | null) { + const params: Record = {} + if (selectedApp) params.app = selectedApp + const cacheKey = buildCacheKey(toolName, params) + const cached = iframes.get(cacheKey) + if (cached) { + // For code app, include empty file param to clear its localStorage + const urlParams = toolName === 'code' ? { ...params, file: '' } : params + cached.iframe.src = buildToolUrl(cached.port, urlParams) + } +} + // Update which iframe is visible based on selected tab and tool state export function updateToolIframes( selectedTab: string,