Skip to content

Commit 24e1c73

Browse files
authored
feat: add UnitSidebarPagesContext (#2874)
1 parent 449af65 commit 24e1c73

10 files changed

Lines changed: 362 additions & 297 deletions

File tree

src/course-outline/outline-sidebar/OutlineSidebarPagesContext.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type OutlineSidebarPages = {
1919
align?: SidebarPage;
2020
};
2121

22-
export const getOutlineSidebarPages = () => ({
22+
const getOutlineSidebarPages = () => ({
2323
info: {
2424
component: InfoSidebar,
2525
icon: Info,
@@ -55,24 +55,24 @@ export const getOutlineSidebarPages = () => ({
5555
* export function CourseOutlineSidebarWrapper(
5656
* { component, pluginProps }: { component: React.ReactNode, pluginProps: CourseOutlineAspectsPageProps },
5757
* ) {
58+
* const AnalyticsPage = React.useCallback(() => <CourseOutlineAspectsPage {...pluginProps} />, [pluginProps]);
59+
* const sidebarPages = useOutlineSidebarPagesContext();
5860
*
59-
* const AnalyticsPage = React.useCallback(() => <CourseOutlineAspectsPage {...pluginProps} />, [pluginProps]);
60-
* const sidebarPages = useOutlineSidebarPagesContext();
61+
* const overridedPages = useMemo(() => ({
62+
* ...sidebarPages,
63+
* analytics: {
64+
* component: AnalyticsPage,
65+
* icon: AutoGraph,
66+
* title: messages.analyticsLabel,
67+
* },
68+
* }), [sidebarPages, AnalyticsPage]);
6169
*
62-
* const overridedPages = useMemo(() => ({
63-
* ...sidebarPages,
64-
* analytics: {
65-
* component: AnalyticsPage,
66-
* icon: AutoGraph,
67-
* title: messages.analyticsLabel,
68-
* },
69-
* }), [sidebarPages, AnalyticsPage]);
70-
*
71-
* return (
72-
* <OutlineSidebarPagesContext.Provider value={overridedPages}>
73-
* {component}
74-
* </OutlineSidebarPagesContext.Provider>
75-
*}
70+
* return (
71+
* <OutlineSidebarPagesContext.Provider value={overridedPages}>
72+
* {component}
73+
* </OutlineSidebarPagesContext.Provider>
74+
* );
75+
* }
7676
*/
7777
export const OutlineSidebarPagesContext = createContext<OutlineSidebarPages | undefined>(undefined);
7878

@@ -94,6 +94,7 @@ export const OutlineSidebarPagesProvider = ({ children }: OutlineSidebarPagesPro
9494

9595
export const useOutlineSidebarPagesContext = (): OutlineSidebarPages => {
9696
const ctx = useContext(OutlineSidebarPagesContext);
97+
// istanbul ignore if: this should never happen
9798
if (ctx === undefined) { throw new Error('useOutlineSidebarPages must be used within an OutlineSidebarPagesProvider'); }
9899
return ctx;
99100
};
Lines changed: 53 additions & 57 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)