Skip to content

Commit

Permalink
feat: refresh component preview after updating OLX
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Sep 29, 2024
1 parent 30b08e6 commit d729d02
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/library-authoring/component-info/ComponentPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { OpenInFull } from '@openedx/paragon/icons';

import { LibraryBlock } from '../LibraryBlock';
import messages from './messages';
import { useLibraryBlockMetadata } from '../data/apiHooks';

interface ModalComponentPreviewProps {
isOpen: boolean;
Expand Down Expand Up @@ -35,6 +36,7 @@ const ComponentPreview = ({ usageKey }: ComponentPreviewProps) => {
const intl = useIntl();

const [isModalOpen, openModal, closeModal] = useToggle();
const { data: componentMetadata } = useLibraryBlockMetadata(usageKey);

return (
<>
Expand All @@ -48,7 +50,12 @@ const ComponentPreview = ({ usageKey }: ComponentPreviewProps) => {
>
{intl.formatMessage(messages.previewExpandButtonTitle)}
</Button>
<LibraryBlock usageKey={usageKey} />
{
// key=modified below is used to auto-refresh the preview when changes are made, e.g. via OLX editor
componentMetadata
? <LibraryBlock usageKey={usageKey} key={componentMetadata.modified} />

Check warning on line 56 in src/library-authoring/component-info/ComponentPreview.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/component-info/ComponentPreview.tsx#L56

Added line #L56 was not covered by tests
: null
}
</div>
<ModalComponentPreview isOpen={isModalOpen} close={closeModal} usageKey={usageKey} />
</>
Expand Down

0 comments on commit d729d02

Please sign in to comment.