Skip to content

Commit

Permalink
refactor: Add getStaticPaths function to diagram.tsx
Browse files Browse the repository at this point in the history
This commit adds the getStaticPaths function to the diagram.tsx file in the pages/material/[repoId]/[themeId] directory. The function generates the paths for the dynamic routes based on the material data retrieved from the getMaterial function. Each path corresponds to a specific combination of repoId, themeId, and courseId. This change ensures that the dynamic routes are properly generated and accessible for the material pages.
  • Loading branch information
alasdairwilson committed Jul 11, 2024
1 parent 79c2998 commit eecc321
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions cypress/component/EventCommentThreads.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe("EventCommentThreads component", () => {
type: "theme",
courses: [
{
files: [],
id: "course1",
name: "Course 1",
summary: "",
Expand Down
18 changes: 17 additions & 1 deletion pages/material/[repoId]/[themeId]/diagram.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NextPage, GetStaticProps } from "next"
import type { NextPage, GetStaticProps, GetStaticPaths } from "next"
import prisma from "lib/prisma"
import Layout from "components/Layout"
import { makeSerializable } from "lib/utils"
Expand Down Expand Up @@ -39,4 +39,20 @@ export const getStaticProps: GetStaticProps = async (context) => {
}
}

export const getStaticPaths: GetStaticPaths = async () => {
const material = await getMaterial()
let paths = []
for (const theme of material.themes) {
for (const course of theme.courses) {
paths.push({
params: { repoId: `${theme.repo}`, themeId: `${theme.id}`, courseId: `${course.id}` },
})
}
}
return {
paths,
fallback: false,
}
}

export default Home
2 changes: 1 addition & 1 deletion pages/material/diagram.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NextPage, GetStaticProps } from "next"
import type { NextPage, GetStaticProps, GetStaticPaths } from "next"
import prisma from "lib/prisma"
import Layout from "components/Layout"
import { makeSerializable } from "lib/utils"
Expand Down

0 comments on commit eecc321

Please sign in to comment.