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.2 KB
Raw Blame
import { Flexbox } from '@lobehub/ui';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import NotFound from '@/components/404';
import AsyncError from '@/components/AsyncError';
import {
  TaskDetailSections,
  TaskDetailSkeleton,
  TopicChatDrawer,
  useActiveTaskDetail,
} from '@/features/AgentTasks';
import { useChatStore } from '@/store/chat';
import { chatPortalSelectors } from '@/store/chat/selectors';

import ForeignTaskDetail from './ForeignTaskDetail';

const ActiveScopeBody = memo(() => {
  const { t } = useTranslation('chat');
  const taskId = useChatStore(chatPortalSelectors.taskDetailId);
  // Same data wiring as the full /task/[tid] page — owns activeTaskId + polling
  // fetch so the shared section components resolve to this task.
  const { isInitialLoading, isNotFound, error, onRetry } = useActiveTaskDetail(taskId);

  if (!taskId) return null;

  // A transient fetch failure keeps the URL and offers Reload — distinct from a
  // resolved not-found (deleted task), which is a terminal 404.
  if (error) {
    return (
      <Flexbox flex={1} height={'100%'} style={{ minHeight: 0, overflowY: 'auto' }}>
        <AsyncError error={error} variant={'page'} onRetry={onRetry} />
      </Flexbox>
    );
  }

  if (isNotFound) {
    return (
      <Flexbox flex={1} height={'100%'} style={{ minHeight: 0, overflowY: 'auto' }}>
        <NotFound desc={t('taskDetail.notFound.desc')} title={t('taskDetail.notFound.title')} />
      </Flexbox>
    );
  }

  return (
    <Flexbox
      flex={1}
      height={'100%'}
      paddingInline={16}
      style={{ minHeight: 0, overflowY: 'auto' }}
    >
      {isInitialLoading ? <TaskDetailSkeleton chrome={'body'} /> : <TaskDetailSections />}
      <TopicChatDrawer />
    </Flexbox>
  );
});

ActiveScopeBody.displayName = 'ActiveScopeTaskDetailBody';

const Body = memo(() => {
  const isForeign = useChatStore((s) => !!chatPortalSelectors.taskDetailWorkspace(s));

  if (!isForeign) return <ActiveScopeBody />;

  return (
    <Flexbox
      flex={1}
      height={'100%'}
      paddingInline={16}
      style={{ minHeight: 0, overflowY: 'auto' }}
    >
      <ForeignTaskDetail />
    </Flexbox>
  );
});

export default Body;