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.

1.5 KB
Raw Blame
export const resolveNavPanelKey = (
  pathname: string,
  activeWorkspaceSlug: string | null,
): string => {
  const segments = pathname.split('/').filter(Boolean);
  const isWorkspaceRoute =
    !!activeWorkspaceSlug && segments.length > 0 && segments[0] === activeWorkspaceSlug;
  const routeSegments = isWorkspaceRoute ? segments.slice(1) : segments;
  const [rootSegment, childSegment, grandchildSegment] = routeSegments;

  if (rootSegment === 'settings') {
    return isWorkspaceRoute ? 'workspace-settings' : 'settings';
  }

  switch (rootSegment) {
    case 'agent': {
      return grandchildSegment === 'docs' ? 'agent-docs' : 'agent';
    }

    // `community` is the pre-rename URL; it only redirects to `marketplace`.
    case 'community':
    case 'marketplace': {
      return 'discover';
    }

    case 'eval': {
      return childSegment === 'bench' ? 'evalBench' : 'eval';
    }

    case 'group': {
      return 'group';
    }

    case 'image': {
      return 'image';
    }

    case 'memory': {
      return 'memory';
    }

    case 'music': {
      return 'music';
    }

    case 'page': {
      return 'page';
    }

    case 'project': {
      return 'project';
    }

    case 'resource': {
      // `/resource/library` is the library gallery under the Docs sidebar; only
      // a concrete library (`/resource/library/:id`) owns the library sidebar.
      return childSegment === 'library' && grandchildSegment ? 'resourceLibrary' : 'resource';
    }

    case 'video': {
      return 'video';
    }

    default: {
      return 'home';
    }
  }
};