index.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import { DocumentData } from '@/appflowy_app/interfaces/document';
  2. import React, { useCallback } from 'react';
  3. import { useRoot } from './Root.hooks';
  4. import Node from '../Node';
  5. import { withErrorBoundary } from 'react-error-boundary';
  6. import { ErrorBoundaryFallbackComponent } from '../_shared/ErrorBoundaryFallbackComponent';
  7. import VirtualizedList from '../VirtualizedList';
  8. import { Skeleton } from '@mui/material';
  9. function Root({ documentData }: { documentData: DocumentData }) {
  10. const { node, childIds } = useRoot({ documentData });
  11. const renderNode = useCallback((nodeId: string) => {
  12. return <Node key={nodeId} id={nodeId} />;
  13. }, []);
  14. if (!node || !childIds) {
  15. return <Skeleton />;
  16. }
  17. return (
  18. <div id='appflowy-block-doc' className='h-[100%] overflow-hidden'>
  19. <VirtualizedList node={node} childIds={childIds} renderNode={renderNode} />
  20. </div>
  21. );
  22. }
  23. const RootWithErrorBoundary = withErrorBoundary(Root, {
  24. FallbackComponent: ErrorBoundaryFallbackComponent,
  25. });
  26. export default React.memo(RootWithErrorBoundary);