agent-ecosystem/src/features/agent-graph/renderer/hooks/useGraphSidebarVisibility.ts
777genius aed08113e6 feat(agent-graph): integrate stable slot layout for improved node positioning and interaction
- Added stable slot layout support in various components, enhancing the layout and interaction of nodes.
- Updated TypeScript configuration to include new paths for the agent-graph package.
- Refactored layout logic in activity lanes and kanban to accommodate stable slot assignments.
- Enhanced GraphView and GraphControls to support sidebar visibility toggling and owner slot drop handling.
- Introduced new types for layout management in GraphDataPort and related files.
- Updated README to include stable slot layout documentation.
2026-04-15 16:18:11 +03:00

52 lines
1.4 KiB
TypeScript

import { useCallback, useEffect, useState } from 'react';
import { useStore } from '@renderer/store';
const GRAPH_SIDEBAR_VISIBILITY_STORAGE_KEY = 'team-graph-sidebar-visible';
function readInitialVisibility(): boolean {
if (typeof window === 'undefined') {
return true;
}
try {
return window.localStorage.getItem(GRAPH_SIDEBAR_VISIBILITY_STORAGE_KEY) !== 'false';
} catch {
return true;
}
}
export function useGraphSidebarVisibility(): {
sidebarVisible: boolean;
toggleSidebarVisible: () => void;
} {
const [sidebarEnabled, setSidebarEnabled] = useState<boolean>(readInitialVisibility);
const messagesPanelMode = useStore((state) => state.messagesPanelMode);
const setMessagesPanelMode = useStore((state) => state.setMessagesPanelMode);
const sidebarVisible = sidebarEnabled && messagesPanelMode === 'sidebar';
useEffect(() => {
try {
window.localStorage.setItem(GRAPH_SIDEBAR_VISIBILITY_STORAGE_KEY, String(sidebarEnabled));
} catch {
// Ignore storage failures and keep UI responsive.
}
}, [sidebarEnabled]);
const toggleSidebarVisible = useCallback(() => {
if (sidebarVisible) {
setSidebarEnabled(false);
return;
}
setSidebarEnabled(true);
if (messagesPanelMode !== 'sidebar') {
setMessagesPanelMode('sidebar');
}
}, [messagesPanelMode, setMessagesPanelMode, sidebarVisible]);
return {
sidebarVisible,
toggleSidebarVisible,
};
}