Skip to content

Commit

Permalink
feat: learning outcomes
Browse files Browse the repository at this point in the history
Learning outcomes can now be specified on a `section` using the `learningOutcomes` tag in the `yaml` header.

`learningOutcomes` should be a list of strings.

These are then rendered in an alert component below the title and before the content. Each learning outcome is prefixed with a 🏆 icon.

The list can be minimized by clicking the heading.
  • Loading branch information
mjaquiery committed Apr 26, 2024
1 parent 16a568d commit 284f3c9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
33 changes: 33 additions & 0 deletions components/content/LearningOutcomes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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>
}
5 changes: 4 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,12 @@ 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 284f3c9

Please sign in to comment.