Skip to content

Commit bd570eb

Browse files
committed
fixup! fixup! fixup! fixup! fixup! fixup! feat: Syllabus page for learner MFE
1 parent b58665c commit bd570eb

File tree

6 files changed

+51
-38
lines changed

6 files changed

+51
-38
lines changed

src/components/BlockCollapsible.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { Collapsible } from '@openedx/paragon';
3-
import { Block } from '../hooks';
3+
import { type Block } from '../types';
44
import { HighlightMatch } from './HighlightMatch';
55

66
interface BlockCollapsibleProps {

src/components/PrintSyllabus.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { useRef } from 'react';
33
import { useIntl } from '@edx/frontend-platform/i18n';
44
import { Button } from '@openedx/paragon';
55
import messages from '../messages';
6-
import { BlockResponse } from '../hooks';
6+
import { type BlockResponse } from '../types';
77

88
export const PrintSyllabus = ({ blockData }: { blockData: BlockResponse }) => {
99
const intl = useIntl();
10-
const iframeRef = useRef(null);
10+
const iframeRef = useRef<HTMLIFrameElement | null>(null);
1111
const blocks = blockData?.blocks;
1212
const rootBlock = blockData?.blocks[blockData.root];
1313
const makeList = (items: string[] | null) => {
@@ -43,29 +43,32 @@ export const PrintSyllabus = ({ blockData }: { blockData: BlockResponse }) => {
4343
}
4444
4545
body > ul > li > ul {
46-
break-inside: avoid;
4746
break-after: auto;
4847
list-style: none;
4948
}
49+
5050
body ul ul ul ul li:before {
51-
content: '\\01F517 ';
51+
content: '\\01F517';
5252
margin-right: 0.5rem;
5353
}
54+
5455
body ul ul ul ul {
5556
list-style: none;
5657
padding-left: 0;
5758
}
58-
body ul > li {
59-
break-inside: avoid;
60-
break-after: auto;
61-
}
59+
6260
body ul > li ul {
6361
break-after: auto;
6462
}
6563
64+
li {
65+
break-inside: avoid;
66+
}
67+
6668
ul {
6769
margin: 0;
6870
padding-left: 1rem;
71+
break-after: auto;
6972
}
7073
</style>
7174
</head>
@@ -82,11 +85,14 @@ ${syllabusList}
8285
className="d-none"
8386
title={intl.formatMessage(messages.syllabusTitle)}
8487
/>
88+
{iframeRef.current?.contentWindow && (
8589
<Button
8690
variant="outline-primary"
8791
onClick={() => iframeRef.current.contentWindow.print()}
88-
>Print
92+
>
93+
{intl.formatMessage(messages.print)}
8994
</Button>
95+
)}
9096
</div>
9197
);
9298
};

src/components/Syllabus.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import * as React from 'react';
44
import { useEffect, useState } from 'react';
55
import { useParams } from 'react-router-dom';
66
import {
7-
Block, BlockMap, UsageId, useBlockData, usePanels,
7+
useBlockData, usePanels,
88
} from '../hooks';
9+
import { type BlockMap, type UsageId } from '../types';
910
import { BlockCollapsible } from './BlockCollapsible';
1011
import { HighlightMatch } from './HighlightMatch';
1112
import { PrintSyllabus } from './PrintSyllabus';

src/hooks.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,10 @@
11
import { getConfig } from '@edx/frontend-platform';
22
import { getAuthenticatedHttpClient, getAuthenticatedUser } from '@edx/frontend-platform/auth';
33
import { useEffect, useMemo, useState } from 'react';
4+
import { type BlockResponse, type UsageId } from './types';
45

5-
export type UsageId = string;
6-
7-
export type Block = {
8-
id: UsageId;
9-
type: string;
10-
display_name: string;
11-
children: UsageId[];
12-
student_view_data: {
13-
html: string;
14-
}
15-
links: {
16-
text: string;
17-
href: string;
18-
}[]
19-
};
20-
21-
export type BlockMap = {
22-
[blockId: UsageId]: Block;
23-
};
24-
25-
type BlockResponse = {
26-
blocks: BlockMap;
27-
root: UsageId;
28-
};
29-
30-
const processData = (data: BlockResponse) => {
6+
const processBlockData = (blockData: BlockResponse) => {
7+
const data = { ...blockData };
318
const domParser = new DOMParser();
329
const pruneBlocks: UsageId[] = [];
3310
Object.keys(data.blocks).forEach((blockId) => {
@@ -69,7 +46,7 @@ export const useBlockData = (courseId?: string) => {
6946
(async () => {
7047
if (courseId === undefined) { return; }
7148
const { data } = await getAuthenticatedHttpClient().get(getCourseBlocksUrl(courseId));
72-
setBlockData(processData(data));
49+
setBlockData(processBlockData(data));
7350
})();
7451
}, [courseId]);
7552
return blockData;

src/messages.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const messages = defineMessages({
1616
defaultMessage: 'Expand all',
1717
description: 'Label for the button that expands the course syllabus.',
1818
},
19+
print: {
20+
id: 'plugins.syllabus.print',
21+
defaultMessage: 'Print',
22+
description: 'Label for the button that prints the course syllabus.',
23+
},
1924
});
2025

2126
export default messages;

src/types.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export type UsageId = string;
2+
3+
export type Block = {
4+
id: UsageId;
5+
type: string;
6+
display_name: string;
7+
children: UsageId[];
8+
student_view_data: {
9+
html: string;
10+
}
11+
links: {
12+
text: string;
13+
href: string;
14+
}[]
15+
};
16+
17+
export type BlockMap = {
18+
[blockId: UsageId]: Block;
19+
};
20+
21+
export type BlockResponse = {
22+
blocks: BlockMap;
23+
root: UsageId;
24+
};

0 commit comments

Comments
 (0)