From f45cd5baf6557b2ed736cd2b358b00c60f49b892 Mon Sep 17 00:00:00 2001 From: Alasdair Wilson Date: Wed, 17 Jan 2024 14:36:27 +0000 Subject: [PATCH] multi repo associated url fixes --- components/EventCommentThreads.tsx | 22 +++---------------- components/Layout.tsx | 11 +++------- components/Navbar.tsx | 11 +++++----- components/content/Content.tsx | 4 +++- lib/baseMaterialUrl.ts | 1 - lib/material.ts | 7 ++++++ .../[themeId]/[courseId]/[sectionId].tsx | 10 ++++++--- 7 files changed, 29 insertions(+), 37 deletions(-) delete mode 100644 lib/baseMaterialUrl.ts diff --git a/components/EventCommentThreads.tsx b/components/EventCommentThreads.tsx index e398605..8c59e38 100644 --- a/components/EventCommentThreads.tsx +++ b/components/EventCommentThreads.tsx @@ -1,23 +1,8 @@ -import React, { useEffect } from "react" -import { HiArrowNarrowRight } from "react-icons/hi" -import { Course, Material, Section, Theme, eventItemSplit, sectionSplit } from "lib/material" -import { EventFull, Event, Problem } from "lib/types" -import useSWR, { Fetcher } from "swr" -import Title from "components/ui/Title" -import { Avatar, Button, Card, Table, Timeline, Tooltip } from "flowbite-react" -import { ListGroup } from "flowbite-react" -import { basePath } from "lib/basePath" -import { MdClose } from "react-icons/md" +import React from "react" +import { Material, sectionSplit } from "lib/material" +import { EventFull } from "lib/types" import Link from "next/link" -import EventItemView from "./EventItemView" -import { useFieldArray, useForm } from "react-hook-form" -import SelectField from "./forms/SelectField" -import { EventItem } from "@prisma/client" -import useUsers from "lib/hooks/useUsers" -import { useProblems } from "lib/hooks/useProblems" -import useUsersOnEvent from "lib/hooks/useUsersOnEvent" import useCommentThreads from "lib/hooks/useCommentThreads" -import SubTitle from "./ui/SubTitle" type Props = { event: EventFull @@ -30,7 +15,6 @@ const EventCommentThreads: React.FC = ({ material, event }) => { if (!commentThreads) return
failed to load
const unresolvedThreads = commentThreads.filter((thread) => !thread.resolved) - return (
    diff --git a/components/Layout.tsx b/components/Layout.tsx index bb6feec..9acfc15 100644 --- a/components/Layout.tsx +++ b/components/Layout.tsx @@ -6,14 +6,7 @@ import { useState } from "react" import React, { ReactNode } from "react" import Footer from "./Footer" import Header from "./Header" -import { Dropdown } from "flowbite-react" -import { EventFull, Event } from "lib/types" -import { AiOutlineUser } from "react-icons/ai" -import { FaUser } from "react-icons/fa" -import { Avatar } from "flowbite-react" -import { basePath } from "lib/basePath" import { Material } from "lib/material" -import EventView from "./EventView" import Overlay from "./Overlay" import Navbar from "./Navbar" import { useSidebarOpen } from "lib/hooks/useSidebarOpen" @@ -28,9 +21,10 @@ type Props = { section?: Section children: ReactNode pageInfo?: PageTemplate + repoUrl?: string } -const Layout: React.FC = ({ material, theme, course, section, children, pageInfo }) => { +const Layout: React.FC = ({ material, theme, course, section, children, pageInfo, repoUrl }) => { const [activeEvent, setActiveEvent] = useActiveEvent() const router = useRouter() const { data: session } = useSession() @@ -81,6 +75,7 @@ const Layout: React.FC = ({ material, theme, course, section, children, p setSidebarOpen={setSidebarOpen} showAttribution={showAttribution} setShowAttribution={setShowAttribution} + repoUrl={repoUrl} /> void sidebarOpen: boolean showAttribution: boolean + repoUrl?: string } const Navbar: React.FC = ({ @@ -32,6 +32,7 @@ const Navbar: React.FC = ({ setSidebarOpen, sidebarOpen, showAttribution, + repoUrl, }) => { const [showSearch, setShowSearch] = useRecoilState(searchQueryState) const { data: session } = useSession() @@ -121,7 +122,7 @@ const Navbar: React.FC = ({ > {theme.name} @@ -129,7 +130,7 @@ const Navbar: React.FC = ({
)}{" "} - {course && ( + {theme && course && (
  • = ({ > {course.name} @@ -177,7 +178,7 @@ const Navbar: React.FC = ({ {theme && course && section && ( diff --git a/components/content/Content.tsx b/components/content/Content.tsx index 3d67199..9a4011a 100644 --- a/components/content/Content.tsx +++ b/components/content/Content.tsx @@ -128,7 +128,9 @@ type Props = { } const Content: React.FC = ({ markdown, theme, course, section }) => { - const sectionStr = `${theme ? theme.id + "." : ""}${course ? course.id + "." : ""}${section ? section.id : ""}` + const sectionStr = `${theme ? theme.repo + "." : ""}${theme ? theme.id + "." : ""}${course ? course.id + "." : ""}${ + section ? section.id : "" + }` return (
    repos[key].path === repo) + const repoConfig = repos[key] + return repoConfig.url +} + export async function getMaterial(no_markdown = false): Promise { const repos = getrepos() let allThemes: Theme[] = [] diff --git a/pages/material/[repoId]/[themeId]/[courseId]/[sectionId].tsx b/pages/material/[repoId]/[themeId]/[courseId]/[sectionId].tsx index a181f23..bf2de05 100644 --- a/pages/material/[repoId]/[themeId]/[courseId]/[sectionId].tsx +++ b/pages/material/[repoId]/[themeId]/[courseId]/[sectionId].tsx @@ -1,6 +1,6 @@ import type { NextPage, GetStaticProps, GetStaticPaths } from "next" import prisma from "lib/prisma" -import { getMaterial, Course, Theme, Material, Section, remove_markdown } from "lib/material" +import { getMaterial, Course, Theme, Material, Section, remove_markdown, getRepoUrl } from "lib/material" import Layout from "components/Layout" import { makeSerializable } from "lib/utils" import Content from "components/content/Content" @@ -15,6 +15,7 @@ type SectionComponentProps = { material: Material events: Event[] pageInfo?: PageTemplate + repoUrl?: string } const SectionComponent: NextPage = ({ @@ -24,9 +25,10 @@ const SectionComponent: NextPage = ({ events, material, pageInfo, + repoUrl, }: SectionComponentProps) => { return ( - + <Content markdown={section.markdown} theme={theme} course={course} section={section} /> </Layout> @@ -58,6 +60,8 @@ export const getStaticPaths: GetStaticPaths = async () => { export const getStaticProps: GetStaticProps = async (context) => { const pageInfo = pageTemplate + const repoId = context?.params?.repoId + const repoUrl = getRepoUrl(repoId as string) const events = await prisma.event .findMany({ where: { hidden: false }, @@ -91,7 +95,7 @@ export const getStaticProps: GetStaticProps = async (context) => { return { notFound: true } } remove_markdown(material, section) - return { props: makeSerializable({ theme, course, section, events, material, pageInfo }) } + return { props: makeSerializable({ theme, course, section, events, material, pageInfo, repoUrl }) } } export default SectionComponent