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.7 KB
Raw Blame
import { createStaticStyles, cssVar, Flexbox, Text } from '@lobehub/ui';
import { memo } from 'react';

import { useChatStore } from '@/store/chat';
import { chatPortalSelectors } from '@/store/chat/selectors';
import { useTaskStore } from '@/store/task';
import { oneLineEllipsis } from '@/styles';

import { useForeignTaskDetail } from './useForeignTaskDetail';

const styles = createStaticStyles(({ css, cssVar }) => ({
  identifier: css`
    flex-shrink: 0;

    padding-block: 1px;
    padding-inline: 6px;
    border-radius: 4px;

    font-family: ${cssVar.fontFamilyCode};
    font-size: 12px;
    color: ${cssVar.colorTextSecondary};

    background: ${cssVar.colorFillTertiary};
  `,
}));

const Title = memo(() => {
  const taskId = useChatStore(chatPortalSelectors.taskDetailId);
  const isForeign = useChatStore((s) => !!chatPortalSelectors.taskDetailWorkspace(s));
  const activeDetail = useTaskStore((s) =>
    taskId && !isForeign ? s.taskDetailMap[s.taskRefIndex?.[taskId] ?? taskId] : undefined,
  );
  const { data: foreignDetail } = useForeignTaskDetail();
  const detail = isForeign ? foreignDetail : activeDetail;
  const identifier = detail?.identifier ?? taskId;
  const name = detail?.name;

  return (
    // Hug the content so the shared `…` sits right after the name.
    <Flexbox horizontal align={'center'} gap={8} style={{ minWidth: 0 }}>
      {identifier && <span className={styles.identifier}>{identifier}</span>}
      {name && (
        <Text
          className={oneLineEllipsis}
          style={{ color: cssVar.colorText, flex: '0 1 auto', fontSize: 14, minWidth: 0 }}
        >
          {name}
        </Text>
      )}
    </Flexbox>
  );
});

export default Title;