Skip to content

Commit

Permalink
Merge pull request #202 from OxfordRSE/learning-outcomes
Browse files Browse the repository at this point in the history
feat: learning outcomes
  • Loading branch information
alasdairwilson authored May 7, 2024
2 parents 416dea1 + f2bdc9d commit c588afa
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
38 changes: 38 additions & 0 deletions components/content/LearningOutcomes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Section } from "../../lib/material"
import ListItem from "@mui/material/ListItem"
import ListItemText from "@mui/material/ListItemText"
import List from "@mui/material/List"
import Alert from "@mui/material/Alert"
import Typography from "@mui/material/Typography"
import Collapse from "@mui/material/Collapse"
import Tooltip from "@mui/material/Tooltip"
import { HiOutlineTrophy } from "react-icons/hi2"
import ListItemIcon from "@mui/material/ListItemIcon"
import React from "react"
import { type Theme } from "@mui/system"

export default function LearningOutcomes({ learningOutcomes }: { learningOutcomes: Section["learningOutcomes"] }) {
const [open, setOpen] = React.useState(true)
if (learningOutcomes.length === 0) return null
return (
<Alert severity="success" sx={{ marginBottom: (t: Theme) => t.spacing(1) }}>
<Tooltip title={`Click to ${open ? "hide" : "show"} learning outcomes`}>
<Typography variant="body2" onClick={() => setOpen(!open)} sx={{ cursor: "pointer" }}>
Learning outcomes
</Typography>
</Tooltip>
<Collapse in={open}>
<List>
{learningOutcomes.map((o, i) => (
<ListItem key={i}>
<ListItemIcon>
<HiOutlineTrophy />
</ListItemIcon>
<ListItemText>{o}</ListItemText>
</ListItem>
))}
</List>
</Collapse>
</Alert>
)
}
1 change: 1 addition & 0 deletions cypress/component/EventCommentThreads.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe("EventCommentThreads component", () => {
file: "",
index: 0,
tags: [],
learningOutcomes: ["LO 1", "LO 2"],
},
],
},
Expand Down
1 change: 1 addition & 0 deletions cypress/component/Paragraph.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe("Paragraph", () => {
license: "test",
},
],
learningOutcomes: ["LO 1", "LO 2"],
problems: ["problem1"],
}
const currentUser: User = {
Expand Down
19 changes: 18 additions & 1 deletion lib/material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type Section = {
type: string
attribution: Attribution[]
problems: string[]
learningOutcomes: string[]
}

export type Course = {
Expand Down Expand Up @@ -274,10 +275,26 @@ export async function getSection(
const name = (sectionObject.attributes.name as string) || humanize(file)
// @ts-expect-error
const attribution = (sectionObject.attributes.attribution as Attribution[]) || []
// @ts-expect-error
const learningOutcomes = (sectionObject.attributes.learningOutcomes as string[]) || []
const markdown = no_markdown ? "" : (sectionObject.body as string)
const type = "Section"
const regex =
/:{3,}challenge\s*{\s*(?:id\s*=\s*"?([^"\s]+)"?\s*title\s*=\s*"[^"]+"|title\s*=\s*"[^"]+"\s*id\s*=\s*"?([^"\s]+)"?)\s*}/g
const problems = Array.from(markdown.matchAll(regex)).map((match) => match[1] || match[2])
return { id, file, theme, course, name, markdown, index, type, tags, dependsOn, attribution, problems }
return {
id,
file,
theme,
course,
name,
markdown,
index,
type,
tags,
dependsOn,
attribution,
learningOutcomes,
problems,
}
}
3 changes: 2 additions & 1 deletion pages/material/[repoId]/[themeId]/[courseId]/[sectionId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Content from "components/content/Content"
import Title from "components/ui/Title"
import { Event } from "lib/types"
import { PageTemplate, pageTemplate } from "lib/pageTemplate"
import excludeVariablesFromRoot from "@mui/material/styles/excludeVariablesFromRoot"
import LearningOutcomes from "components/content/LearningOutcomes"

type SectionComponentProps = {
theme: Theme
Expand Down Expand Up @@ -51,6 +51,7 @@ const SectionComponent: NextPage<SectionComponentProps> = ({
excludes={excludes}
>
<Title text={section.name} />
<LearningOutcomes learningOutcomes={section.learningOutcomes} />
<Content markdown={section.markdown} theme={theme} course={course} section={section} />
</Layout>
)
Expand Down

0 comments on commit c588afa

Please sign in to comment.