Skip to content

Commit

Permalink
feat: Updated Xpert component to be lazy loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Oct 18, 2024
1 parent 2a58ad2 commit f8fde7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/courseware/course/chat/Chat.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { React, Suspense, lazy } from 'react';
import { createPortal } from 'react-dom';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { Spinner } from '@openedx/paragon';

import { Xpert } from '@edx/frontend-lib-learning-assistant';
import { injectIntl } from '@edx/frontend-platform/i18n';

import { VERIFIED_MODES } from '@src/constants';
import { useModel } from '../../../generic/model-store';

const Xpert = lazy(async () => ({ default: (await import('@edx/frontend-lib-learning-assistant')).Xpert }));

const Chat = ({
enabled,
enrollmentMode,
Expand Down Expand Up @@ -54,7 +57,9 @@ const Chat = ({
<>
{/* Use a portal to ensure that component overlay does not compete with learning MFE styles. */}
{shouldDisplayChat && (createPortal(
<Xpert courseId={courseId} contentToolsEnabled={contentToolsEnabled} unitId={unitId} />,
<Suspense fallback={<Spinner animation="border" variant="light" />}>
<Xpert courseId={courseId} contentToolsEnabled={contentToolsEnabled} unitId={unitId} />
</Suspense>,
document.body,
))}
</>
Expand Down
3 changes: 2 additions & 1 deletion src/courseware/course/chat/Chat.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ describe('Chat', () => {
{ store },
);

const chat = screen.queryByTestId(mockXpertTestId);
if (test.isVisible) {
const chat = await screen.findByTestId(mockXpertTestId);
expect(chat).toBeInTheDocument();
} else {
const chat = screen.queryByTestId(mockXpertTestId);
expect(chat).not.toBeInTheDocument();
}
},
Expand Down

0 comments on commit f8fde7a

Please sign in to comment.