-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: In libraries, allow opening the editor for text (html) components
- Loading branch information
1 parent
dde8385
commit 0720d11
Showing
6 changed files
with
110 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* eslint-disable react/require-default-props */ | ||
import React from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
|
||
import EditorPage from './EditorPage'; | ||
|
||
interface Props { | ||
/** Course ID or Library ID */ | ||
learningContextId: string; | ||
/** Event handler for when user cancels out of the editor page */ | ||
onClose?: () => void; | ||
/** Event handler for when user saves changes using an editor */ | ||
onSave?: () => (newData: Record<string, any>) => void; | ||
} | ||
|
||
const EditorContainer: React.FC<Props> = ({ | ||
learningContextId, | ||
onClose, | ||
onSave, | ||
}) => { | ||
const { blockType, blockId } = useParams(); | ||
if (blockType === undefined || blockId === undefined) { | ||
// This shouldn't be possible; it's just here to satisfy the type checker. | ||
return <div>Error: missing URL parameters</div>; | ||
} | ||
return ( | ||
<div className="editor-page"> | ||
<EditorPage | ||
courseId={learningContextId} | ||
blockType={blockType} | ||
blockId={blockId} | ||
studioEndpointUrl={getConfig().STUDIO_BASE_URL} | ||
lmsEndpointUrl={getConfig().LMS_BASE_URL} | ||
onClose={onClose} | ||
returnFunction={onSave} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default EditorContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,54 @@ | ||
import React from 'react'; | ||
import { | ||
Route, | ||
Routes, | ||
useNavigate, | ||
useParams, | ||
} from 'react-router-dom'; | ||
import { PageWrap } from '@edx/frontend-platform/react'; | ||
|
||
import EditorContainer from '../editors/EditorContainer'; | ||
import LibraryAuthoringPage from './LibraryAuthoringPage'; | ||
import { LibraryProvider } from './common/context'; | ||
|
||
const LibraryLayout = () => ( | ||
<LibraryProvider> | ||
<LibraryAuthoringPage /> | ||
</LibraryProvider> | ||
); | ||
const LibraryLayout = () => { | ||
const { libraryId } = useParams(); | ||
|
||
if (libraryId === undefined) { | ||
throw new Error('Error: route is missing libraryId.'); // Should never happen | ||
} | ||
|
||
const navigate = useNavigate(); | ||
const goBack = React.useCallback(() => { | ||
if (window.history.length > 1) { | ||
navigate(-1); // go back | ||
} else { | ||
navigate(`/library/${libraryId}`); | ||
} | ||
// The following function is called only if changes are saved: | ||
return ({ id }) => { | ||
// TODO:: invalidate any queries that involve ID. | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<LibraryProvider> | ||
<Routes> | ||
<Route | ||
path="editor/:blockType/:blockId?" | ||
element={( | ||
<PageWrap> | ||
<EditorContainer learningContextId={libraryId} onClose={goBack} onSave={goBack} /> | ||
</PageWrap> | ||
)} | ||
/> | ||
<Route | ||
path="*" | ||
element={<LibraryAuthoringPage />} | ||
/> | ||
</Routes> | ||
</LibraryProvider> | ||
); | ||
}; | ||
|
||
export default LibraryLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters