Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

994 B
Raw Blame
import { type ReactNode, useSyncExternalStore } from 'react';

import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
import {
  getNavPanelRegistrySnapshot,
  subscribeNavPanelRegistry,
} from '@/features/NavPanel/registry';
import { resolveNavPanelKey } from '@/features/NavPanel/routeKey';
import { useActiveLocation } from '@/hooks/useActiveLocation';

/**
 * The sidebar the active route registered through `NavPanelPortal`, for the
 * mobile drawer. `home` is the desktop agent list, which mobile already shows
 * as its home page, so it never opens as a drawer.
 */
export const useNavPanelDrawerContent = (): ReactNode | undefined => {
  const { pathname } = useActiveLocation();
  const navKey = resolveNavPanelKey(pathname, useActiveWorkspaceSlug());

  const getContent = () =>
    navKey === 'home' ? undefined : getNavPanelRegistrySnapshot().get(navKey)?.node;

  return useSyncExternalStore(subscribeNavPanelRegistry, getContent, getContent);
};