MCPcopy Index your code
hub / github.com/xintaofei/codeg / DeepLinkBootstrap

Function DeepLinkBootstrap

src/components/workspace/deep-link-bootstrap.tsx:13–89  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11 * Runs once after both folders and tabs have hydrated.
12 */
13export function DeepLinkBootstrap() {
14 const { foldersHydrated, folders, addFolderToWorkspaceById, conversations } =
15 useAppWorkspace()
16 const { tabsHydrated, openTab } = useTabContext()
17 const ranRef = useRef(false)
18
19 useEffect(() => {
20 if (ranRef.current) return
21 if (!foldersHydrated || !tabsHydrated) return
22 ranRef.current = true
23
24 if (typeof window === "undefined") return
25
26 const params = new URLSearchParams(window.location.search)
27 const rawFolderId = params.get("folderId")
28 const rawConversationId = params.get("conversationId")
29 const rawAgent = params.get("agent") as AgentType | null
30
31 if (!rawFolderId && !rawConversationId) return
32
33 const clearUrl = () => {
34 try {
35 window.history.replaceState({}, "", "/workspace")
36 } catch {
37 /* ignore */
38 }
39 }
40
41 void (async () => {
42 try {
43 const folderId = rawFolderId ? Number(rawFolderId) : null
44 const conversationId = rawConversationId
45 ? Number(rawConversationId)
46 : null
47
48 if (folderId == null || !Number.isFinite(folderId)) return
49 if (conversationId == null || !Number.isFinite(conversationId)) return
50 if (!rawAgent) return
51
52 let folder = folders.find((f) => f.id === folderId)
53 if (!folder) {
54 try {
55 folder = await addFolderToWorkspaceById(folderId)
56 } catch (err) {
57 console.error("[DeepLinkBootstrap] open folder failed:", err)
58 toast.error("Unable to open linked folder")
59 return
60 }
61 }
62
63 const hasConv = conversations.some(
64 (c) =>
65 c.id === conversationId &&
66 c.folder_id === folderId &&
67 c.agent_type === rawAgent
68 )
69 if (!hasConv) {
70 toast.error("Linked conversation not found")

Callers

nothing calls this directly

Calls 3

useAppWorkspaceFunction · 0.90
useTabContextFunction · 0.90
clearUrlFunction · 0.85

Tested by

no test coverage detected