Skip to content

Commit 210a2f8

Browse files
committed
done
1 parent 461ac24 commit 210a2f8

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/editors/Editor.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React from 'react';
44
import { useDispatch } from 'react-redux';
55

66
import * as hooks from './hooks';
7+
import { useEditorContext } from './EditorContext';
78

89
import supportedEditors from './supportedEditors';
910
import type { EditorComponent } from './EditorComponent';
@@ -13,20 +14,17 @@ export interface Props extends EditorComponent {
1314
blockType: string;
1415
blockId: string | null;
1516
learningContextId: string | null;
16-
lmsEndpointUrl: string | null;
17-
studioEndpointUrl: string | null;
1817
}
1918

2019
const Editor: React.FC<Props> = ({
2120
learningContextId,
2221
blockType,
2322
blockId,
24-
lmsEndpointUrl,
25-
studioEndpointUrl,
2623
onClose = null,
2724
returnFunction = null,
2825
}) => {
2926
const dispatch = useDispatch();
27+
const { lmsEndpointUrl, studioEndpointUrl } = useEditorContext();
3028
const loading = hooks.useInitializeApp({
3129
dispatch,
3230
data: {

src/editors/EditorContext.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ export interface EditorContext {
1515
learningContextId: string;
1616
/** Is the so-called "Markdown" problem editor available in this learning context? */
1717
isMarkdownEditorEnabledForContext: boolean;
18+
/** e.g. "http://studio.local.openedx.io:8001" */
19+
studioEndpointUrl?: string | null;
20+
/** e.g. "http://local.openedx.io:8000" */
21+
lmsEndpointUrl?: string | null;
1822
}
1923

2024
export type EditorContextInit = {
2125
learningContextId: string;
26+
studioEndpointUrl?: string | null;
27+
lmsEndpointUrl?: string | null;
2228
};
2329

2430
const context = React.createContext<EditorContext | undefined>(undefined);
@@ -36,17 +42,23 @@ export function useEditorContext() {
3642
export const EditorContextProvider: React.FC<{ children: React.ReactNode; } & EditorContextInit> = ({
3743
children,
3844
learningContextId,
45+
studioEndpointUrl,
46+
lmsEndpointUrl,
3947
}) => {
4048
const courseIdIfCourse = isCourseKey(learningContextId) ? learningContextId : undefined;
4149
const isMarkdownEditorEnabledForContext = useWaffleFlags(courseIdIfCourse).useReactMarkdownEditor;
4250

4351
const ctx: EditorContext = React.useMemo(() => ({
4452
learningContextId,
4553
isMarkdownEditorEnabledForContext,
54+
studioEndpointUrl,
55+
lmsEndpointUrl,
4656
}), [
4757
// Dependencies - make sure we update the context object if any of these values change:
4858
learningContextId,
4959
isMarkdownEditorEnabledForContext,
60+
studioEndpointUrl,
61+
lmsEndpointUrl,
5062
]);
5163
return <context.Provider value={ctx}>{children}</context.Provider>;
5264
};

src/editors/EditorPage.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ const EditorPage: React.FC<Props> = ({
3636
studioEndpointUrl,
3737
}}
3838
>
39-
<EditorContextProvider learningContextId={courseId}>
39+
<EditorContextProvider
40+
learningContextId={courseId}
41+
studioEndpointUrl={studioEndpointUrl}
42+
lmsEndpointUrl={lmsEndpointUrl}
43+
>
4044
<Editor
4145
{...{
4246
onClose,
4347
learningContextId: courseId,
4448
blockType,
4549
blockId,
46-
lmsEndpointUrl,
47-
studioEndpointUrl,
4850
returnFunction,
4951
}}
5052
/>

0 commit comments

Comments
 (0)