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.

3.6 KB
Raw Blame
import { Flexbox } from '@lobehub/ui';
// import { PencilLineIcon } from 'lucide-react';
import { type FC } from 'react';

import AsyncBoundary from '@/components/AsyncBoundary';
import SkeletonBar from '@/components/Skeleton/Bar';
import { RouteLoading } from '@/components/Skeleton/RouteSegment';
import NavHeader from '@/features/NavHeader';
import WideScreenContainer from '@/features/WideScreenContainer';
import WideScreenButton from '@/features/WideScreenContainer/WideScreenButton';
import ActionBar from '@/routes/(main)/memory/features/ActionBar';
import MemoryAnalysis from '@/routes/(main)/memory/features/MemoryAnalysis';
import MemoryEmpty from '@/routes/(main)/memory/features/MemoryEmpty';
import { SCROLL_PARENT_ID } from '@/routes/(main)/memory/features/TimeLineView/useScrollParent';
import { useUserMemoryStore } from '@/store/userMemory';

import Persona from './features/Persona';
import PersonaHeader from './features/Persona/PersonaHeader';
import RoleTagCloud from './features/RoleTagCloud';

const Home: FC = () => {
  const useFetchTags = useUserMemoryStore((s) => s.useFetchTags);
  const useFetchPersona = useUserMemoryStore((s) => s.useFetchPersona);
  const roles = useUserMemoryStore((s) => s.roles);
  const persona = useUserMemoryStore((s) => s.persona);

  const { error: tagsError, isLoading: tagsLoading, mutate: mutateTags } = useFetchTags();
  const {
    error: personaError,
    isLoading: personaLoading,
    mutate: mutatePersona,
  } = useFetchPersona();
  // const { EditorModalElement, openEditor } = usePersonaEditor();

  // Persona / tags feed the store, so a failed fetch left the render falling
  // through to the "analyze to get started" onboarding — telling the user they
  // have no memories when the load merely errored. Branch error before empty.
  const hasData = !!persona || roles?.length > 0;
  const error = tagsError ?? personaError;
  // Nothing to purge, analyse or widen when the onboarding empty state is the
  // whole page — and it already offers the analyse action inline.
  const isEmpty = !hasData && !error;

  if ((tagsLoading || personaLoading) && !hasData) return <RouteLoading />;

  return (
    <Flexbox flex={1} height={'100%'}>
      <NavHeader
        right={
          isEmpty ? undefined : (
            <ActionBar showAnalysis showPurge>
              {/* <ActionIcon icon={PencilLineIcon} onClick={openEditor} /> */}
              <WideScreenButton />
            </ActionBar>
          )
        }
        style={{
          zIndex: 1,
        }}
      />
      <Flexbox
        height={'100%'}
        id={SCROLL_PARENT_ID}
        style={{ overflowY: 'auto', paddingBottom: '16vh' }}
        width={'100%'}
      >
        <WideScreenContainer gap={32} paddingBlock={48}>
          <AsyncBoundary
            data={persona ?? (roles?.length ? roles : undefined)}
            error={error}
            errorVariant={'page'}
            isEmpty={!hasData}
            empty={
              <MemoryEmpty>
                <MemoryAnalysis />
              </MemoryEmpty>
            }
            onRetry={() => {
              mutateTags();
              mutatePersona();
            }}
          >
            {roles?.length > 0 ? (
              <RoleTagCloud tags={roles} />
            ) : (
              tagsLoading && <SkeletonBar height={400} radius={12} />
            )}
            {persona && (
              <>
                <PersonaHeader />
                <Persona />
              </>
            )}
          </AsyncBoundary>
        </WideScreenContainer>
      </Flexbox>
      {/* {EditorModalElement} */}
    </Flexbox>
  );
};

export default Home;