Skip to content

Commit

Permalink
feat: WIP pasting library content
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuf-musleh committed Jul 29, 2024
1 parent fa43cc6 commit be7ef18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/library-authoring/add-content/AddContentContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const AddContentContainer = () => {
const createBlockMutation = useCreateLibraryBlock();
const { showToast } = useContext(ToastContext);
const canEdit = useSelector(getCanEdit);
const { showPasteXBlock } = useCopyToClipboard(canEdit);
const { showPasteXBlock, sharedClipboardData } = useCopyToClipboard(canEdit);

const contentTypes = [
{
Expand Down Expand Up @@ -84,11 +84,19 @@ const AddContentContainer = () => {

const onCreateContent = (blockType: string) => {
if (libraryId) {
createBlockMutation.mutateAsync({
const payload = {
libraryId,
blockType,
definitionId: `${uuid4()}`,
}).then(() => {
};

if (blockType === 'paste') {
console.log('pasting...');

Check warning on line 94 in src/library-authoring/add-content/AddContentContainer.tsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
console.log('sharedClipboardData', sharedClipboardData);

Check warning on line 95 in src/library-authoring/add-content/AddContentContainer.tsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
payload['stagedContent'] = 'clipboard';

Check failure on line 96 in src/library-authoring/add-content/AddContentContainer.tsx

View workflow job for this annotation

GitHub Actions / tests

["stagedContent"] is better written in dot notation
}

createBlockMutation.mutateAsync(payload).then(() => {
showToast(intl.formatMessage(messages.successCreateMessage));
}).catch(() => {
showToast(intl.formatMessage(messages.errorCreateMessage));
Expand Down
3 changes: 3 additions & 0 deletions src/library-authoring/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export interface CreateBlockDataRequest {
libraryId: string;
blockType: string;
definitionId: string;
stagedContent?: string;
}

export interface CreateBlockDataResponse {
Expand Down Expand Up @@ -129,13 +130,15 @@ export async function createLibraryBlock({
libraryId,
blockType,
definitionId,
stagedContent,
}: CreateBlockDataRequest): Promise<CreateBlockDataResponse> {
const client = getAuthenticatedHttpClient();
const { data } = await client.post(
getCreateLibraryBlockUrl(libraryId),
{
block_type: blockType,
definition_id: definitionId,
staged_content: stagedContent,
},
);
return data;
Expand Down

0 comments on commit be7ef18

Please sign in to comment.