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.

2.0 KB
Raw Blame
import { AGENT_CHAT_URL, GROUP_CHAT_URL } from '@lobechat/const';
import type { SidebarAgentItem } from '@lobechat/types';
import { agentDisplayName } from '@lobechat/types';
import { createStaticStyles } from '@lobehub/ui';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import LazyLoad from 'react-lazy-load';

import WorkspaceLink from '@/features/Workspace/WorkspaceLink';
import { useServerConfigStore } from '@/store/serverConfig';

import ListItem from './ListItem';
import { useListNavigation } from './useListNavigation';

const styles = createStaticStyles(({ css }) => ({
  container: css`
    min-height: 70px;
  `,
  link: css`
    display: block;
  `,
}));

interface AgentSearchListProps {
  dataSource?: SidebarAgentItem[];
}

export const AgentSearchList = memo<AgentSearchListProps>(({ dataSource }) => {
  const { t } = useTranslation('chat');
  const onNavigate = useListNavigation('search');
  const isMobile = useServerConfigStore((s) => s.isMobile);

  return dataSource?.map((item) => {
    const title = agentDisplayName(
      item,
      t(item.type === 'group' ? 'untitledGroup' : 'untitledAgent'),
    );

    return (
      <LazyLoad className={styles.container} key={item.id}>
        <WorkspaceLink
          aria-label={title}
          className={styles.link}
          to={item.type === 'group' ? GROUP_CHAT_URL(item.id) : AGENT_CHAT_URL(item.id, isMobile)}
          onClick={(event) => onNavigate(event, item)}
        >
          <ListItem
            agentId={item.id}
            avatar={item.avatar || ''}
            avatarBackground={item.backgroundColor || undefined}
            title={title}
            type={item.type}
            styles={{
              container: {
                gap: 12,
              },
              content: {
                gap: 6,
                maskImage: `linear-gradient(90deg, black 90%, transparent)`,
              },
            }}
          />
        </WorkspaceLink>
      </LazyLoad>
    );
  });
});

AgentSearchList.displayName = 'AgentSearchList';