Skip to content

Commit

Permalink
feat: Broadcast clipboard on lib component copy
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuf-musleh committed Aug 14, 2024
1 parent b321ee1 commit 9b64557
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/library-authoring/components/ComponentCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ const contentHit: ContentHit = {
lastPublished: null,
};

const clipboardBroadcastChannelMock = {
postMessage: jest.fn(),
close: jest.fn(),
};

(global as any).BroadcastChannel = jest.fn(() => clipboardBroadcastChannelMock);

const RootWrapper = () => (
<AppProvider store={store}>
<IntlProvider locale="en">
Expand Down
9 changes: 7 additions & 2 deletions src/library-authoring/components/ComponentCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useMemo } from 'react';
import React, { useContext, useMemo, useState } from 'react';
import { useIntl } from '@edx/frontend-platform/i18n';
import {
ActionRow,
Expand All @@ -17,6 +17,7 @@ import TagCount from '../../generic/tag-count';
import { ToastContext } from '../../generic/toast-context';
import { type ContentHit, Highlight } from '../../search-manager';
import messages from './messages';
import { STUDIO_CLIPBOARD_CHANNEL } from '../../constants';

type ComponentCardProps = {
contentHit: ContentHit,
Expand All @@ -26,9 +27,13 @@ type ComponentCardProps = {
const ComponentCardMenu = ({ usageKey }: { usageKey: string }) => {
const intl = useIntl();
const { showToast } = useContext(ToastContext);
const [clipboardBroadcastChannel] = useState(() => new BroadcastChannel(STUDIO_CLIPBOARD_CHANNEL));
const updateClipboardClick = () => {
updateClipboard(usageKey)
.then(() => showToast(intl.formatMessage(messages.copyToClipboardSuccess)))
.then((clipboardData) => {
clipboardBroadcastChannel.postMessage(clipboardData);
showToast(intl.formatMessage(messages.copyToClipboardSuccess))

Check failure on line 35 in src/library-authoring/components/ComponentCard.tsx

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon
})
.catch(() => showToast(intl.formatMessage(messages.copyToClipboardError)));
};

Expand Down

0 comments on commit 9b64557

Please sign in to comment.