Skip to content

Commit

Permalink
feat: open the editor when creating a new component
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Sep 6, 2024
1 parent 478216f commit 7147905
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/library-authoring/add-content/AddContentContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ import {
ContentPaste,
} from '@openedx/paragon/icons';
import { v4 as uuid4 } from 'uuid';
import { useParams } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router-dom';

import { ToastContext } from '../../generic/toast-context';
import { useCopyToClipboard } from '../../generic/clipboard';
import { getCanEdit } from '../../course-unit/data/selectors';
import { useCreateLibraryBlock, useLibraryPasteClipboard } from '../data/apiHooks';
import { getEditUrl } from '../components/utils';

import messages from './messages';

const AddContentContainer = () => {
const intl = useIntl();
const navigate = useNavigate();
const { libraryId } = useParams();
const createBlockMutation = useCreateLibraryBlock();
const pasteClipboardMutation = useLibraryPasteClipboard();
Expand Down Expand Up @@ -100,8 +103,14 @@ const AddContentContainer = () => {
libraryId,
blockType,
definitionId: `${uuid4()}`,
}).then(() => {
showToast(intl.formatMessage(messages.successCreateMessage));
}).then((data) => {
const editUrl = getEditUrl(data.id);
if (editUrl) {
navigate(editUrl);
} else {
// We can't start editing this right away so just show a toast message:
showToast(intl.formatMessage(messages.successCreateMessage));
}
}).catch(() => {
showToast(intl.formatMessage(messages.errorCreateMessage));
});
Expand Down
2 changes: 1 addition & 1 deletion src/library-authoring/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export async function createLibraryBlock({
definition_id: definitionId,
},
);
return data;
return camelCaseObject(data);
}

/**
Expand Down

0 comments on commit 7147905

Please sign in to comment.