优化folder打开逻辑

This commit is contained in:
xintaofei
2026-03-25 18:24:32 +08:00
parent b330a4f936
commit 388f92637c
9 changed files with 119 additions and 13 deletions

View File

@@ -11,7 +11,8 @@ import {
type ReactNode,
} from "react"
import { toErrorMessage } from "@/lib/app-error"
import { getFolder, listFolderConversations } from "@/lib/api"
import { getFolder, listFolderConversations, closeFolderWindow } from "@/lib/api"
import { isDesktop } from "@/lib/transport"
import type {
AgentType,
AgentStats,
@@ -195,6 +196,22 @@ export function FolderProvider({
}
}, [])
// Web mode: register this tab's name so that window.open(url, "folder-{id}")
// from other pages can find and reuse it instead of opening duplicates.
// Also notify backend when the folder tab closes.
useEffect(() => {
if (isDesktop() || !folderId) return
window.name = `folder-${folderId}`
const onUnload = () => closeFolderWindow(folderId)
window.addEventListener("pagehide", onUnload)
return () => {
window.removeEventListener("pagehide", onUnload)
}
}, [folderId])
const selectConversation = useCallback((id: number, agentType: AgentType) => {
setSelectedConversation({ id, agentType })
setNewConversation(null)