remember
This commit is contained in:
parent
a25088e723
commit
51f347a544
|
|
@ -1,9 +1,15 @@
|
||||||
import type { App } from '../../shared/types'
|
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 { Tab, TabBar } from '../styles'
|
||||||
|
import { resetToolIframe } from '../tool-iframes'
|
||||||
|
|
||||||
export function Nav({ app, render }: { app: App; render: () => void }) {
|
export function Nav({ app, render }: { app: App; render: () => void }) {
|
||||||
const handleTabClick = (tab: string) => {
|
const handleTabClick = (tab: string) => {
|
||||||
|
// If clicking already-selected tool tab, reset to home
|
||||||
|
if (tab === selectedTab && tab !== 'overview') {
|
||||||
|
resetToolIframe(tab, selectedApp)
|
||||||
|
return
|
||||||
|
}
|
||||||
setSelectedTab(tab)
|
setSelectedTab(tab)
|
||||||
render()
|
render()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ function setupMessageListener() {
|
||||||
for (const [, cached] of iframes) {
|
for (const [, cached] of iframes) {
|
||||||
if (cached.iframe.contentWindow === event.source) {
|
if (cached.iframe.contentWindow === event.source) {
|
||||||
cached.contentHeight = height
|
cached.contentHeight = height
|
||||||
cached.iframe.style.height = `100vh`
|
cached.iframe.style.height = `${height}px`
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -85,6 +85,19 @@ function buildCacheKey(toolName: string, params: Record<string, string>): string
|
||||||
return parts.join(':')
|
return parts.join(':')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset a tool iframe to its home page
|
||||||
|
export function resetToolIframe(toolName: string, selectedApp: string | null) {
|
||||||
|
const params: Record<string, string> = {}
|
||||||
|
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
|
// Update which iframe is visible based on selected tab and tool state
|
||||||
export function updateToolIframes(
|
export function updateToolIframes(
|
||||||
selectedTab: string,
|
selectedTab: string,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user