Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /**
* usePortal — access portal tabs and navigation.
*/
import {useCallback} from 'react';
import {useAppStore} from '../state/appStore.js';
import type {IPortalConfig, ITab} from '../types/portal.js';
export interface IUsePortalResult {
tabs: ITab[];
activeTabId: string | null;
activeTab: ITab | undefined;
portalConfig: IPortalConfig | null;
openTab: (tab: ITab) => void;
closeTab: (id: string) => void;
setActiveTab: (id: string) => void;
setTabDirty: (id: string, dirty: boolean) => void;
}
export function usePortal(): IUsePortalResult {
const {tabs, activeTabId, portalConfig} = useAppStore(s => s.portal);
const openTab = useAppStore(s => s.openTab);
const closeTab = useAppStore(s => s.closeTab);
const setActiveTab = useAppStore(s => s.setActiveTab);
const setTabDirtyStore = useAppStore(s => s.setTabDirty);
const activeTab = tabs.find(t => t.id === activeTabId);
const setTabDirty = useCallback(
(id: string, dirty: boolean) => setTabDirtyStore(id, dirty),
[setTabDirtyStore],
);
return {
tabs,
activeTabId,
activeTab,
portalConfig,
openTab,
closeTab,
setActiveTab,
setTabDirty,
};
}
|