MCPcopy Index your code
hub / github.com/winfunc/opcode / useTabState

Function useTabState

src/hooks/useTabState.ts:43–362  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41}
42
43export const useTabState = (): UseTabStateReturn => {
44 const {
45 tabs,
46 activeTabId,
47 addTab,
48 removeTab,
49 updateTab,
50 setActiveTab,
51 getTabById,
52 getTabsByType
53 } = useTabContext();
54
55 const activeTab = useMemo(() =>
56 activeTabId ? getTabById(activeTabId) : undefined,
57 [activeTabId, getTabById]
58 );
59
60 const tabCount = tabs.length;
61 const chatTabCount = useMemo(() => getTabsByType('chat').length, [getTabsByType]);
62 const agentTabCount = useMemo(() => getTabsByType('agent').length, [getTabsByType]);
63
64 const createChatTab = useCallback((projectId?: string, title?: string, projectPath?: string): string => {
65 const tabTitle = title || `Chat ${chatTabCount + 1}`;
66 return addTab({
67 type: 'chat',
68 title: tabTitle,
69 sessionId: projectId,
70 initialProjectPath: projectPath,
71 status: 'idle',
72 hasUnsavedChanges: false,
73 icon: 'message-square'
74 });
75 }, [addTab, chatTabCount]);
76
77 const createAgentTab = useCallback((agentRunId: string, agentName: string): string => {
78 // Check if tab already exists
79 const existingTab = tabs.find(tab => tab.agentRunId === agentRunId);
80 if (existingTab) {
81 setActiveTab(existingTab.id);
82 return existingTab.id;
83 }
84
85 return addTab({
86 type: 'agent',
87 title: agentName,
88 agentRunId,
89 status: 'running',
90 hasUnsavedChanges: false,
91 icon: 'bot'
92 });
93 }, [addTab, tabs, setActiveTab]);
94
95 const createProjectsTab = useCallback((): string | null => {
96 // Allow multiple projects tabs
97 return addTab({
98 type: 'projects',
99 title: 'Projects',
100 status: 'idle',

Callers 10

AppContentFunction · 0.90
AgentExecutionFunction · 0.90
AgentRunsListFunction · 0.90
TabManagerFunction · 0.90
AgentsFunction · 0.90
AgentRunOutputViewerFunction · 0.90
TabPanelFunction · 0.90
TabContentFunction · 0.90
AppContentFunction · 0.90
AgentsModalFunction · 0.90

Calls 1

useTabContextFunction · 0.90

Tested by

no test coverage detected