Skip to content

Commit

Permalink
deleted course folder which was not used
Browse files Browse the repository at this point in the history
  • Loading branch information
Junhaeng committed Nov 26, 2023
1 parent 63bc43d commit c47b8ec
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 109 deletions.
4 changes: 2 additions & 2 deletions components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Navbar: FC<NavbarProps> = ({ courseList }) => {
const isActive = (route: string) => {
const pathList = pathName.asPath.split("/");
/*pathList = ["", dashboard] or ["", courses, [courseName], ...]*/
return pathList.length > 2 ? route === pathList[2] : route === pathList[1];
return route === pathList[1];
};
return (
<nav className="flex flex-col bg-navbarColor text-white h-screen">
Expand All @@ -41,7 +41,7 @@ const Navbar: FC<NavbarProps> = ({ courseList }) => {
{courseList.map((course: Course) => (
<Link
key={course.id}
href={`/courses/${course.name}`}
href={`/${course.name || currentCourse}`}
className={`p-4 block ${
isActive(`${course.name}`)
? "bg-sidebarColor"
Expand Down
21 changes: 15 additions & 6 deletions components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,35 @@ const Sidebar: FC = () => {
"Modules",
"Files",
]);
const originPath = `/courses/${currentCourse}`;
const pathName = useRouter();
const router = useRouter();

const isActive = (it: string) => {
// If the item is 'Home', check against the base path ('/')
const paramList = pathName.asPath.split("/");
const paramList = router.asPath.split("/");
if (it === "Home") {
return paramList.length === 3;
return paramList.length === 2;
}
// Otherwise, compare against the lowercased item
return paramList[3] === it.toLocaleLowerCase();
return paramList[2] === it.toLocaleLowerCase();
};
useEffect(() => {
// If currentCourse is not set, redirect to the home page
if (!currentCourse) {
router.push("/");
}
}, [currentCourse, router]);

if (!currentCourse) {
return <div>Loading...</div>;
}

return (
<nav className="flex flex-col bg-sidebarColor text-white h-screen pl-3 pr-2">
<div className="flex flex-col flex-grow">
{/* Links */}
{tabList.map((it) => (
<Link
href={`${originPath}${
href={`/${currentCourse}${
it !== "Home" ? `/${it.toLocaleLowerCase()}` : ""
}`}
className={`p-4 block group border-l-4 ${
Expand Down
38 changes: 18 additions & 20 deletions context/userContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const UserContext = createContext<userData>({
setCourseList: (): string[] => [],
});

import React from "react";

export const UserContextProvider = ({
children,
}: {
Expand All @@ -33,24 +31,24 @@ export const UserContextProvider = ({
const [userId, setUserId] = useState("");
const [courseList, setCourseList] = useState<string[]>([]);

useEffect(() => {
try {
const savedCourseList = localStorage.getItem("taking_courses");
if (savedCourseList) {
setCourseList(JSON.parse(savedCourseList));
}
} catch (error) {
console.error("Failed to parse courses from localStorage:", error);
}
}, []);

useEffect(() => {
try {
localStorage.setItem("taking_courses", JSON.stringify(courseList));
} catch (error) {
console.error("Failed to save courses to localStorage:", error);
}
}, [courseList]);
// useEffect(() => {
// try {
// const savedCourseList = localStorage.getItem("taking_courses");
// if (savedCourseList) {
// setCourseList(JSON.parse(savedCourseList));
// }
// } catch (error) {
// console.error("Failed to parse courses from localStorage:", error);
// }
// }, []);

// useEffect(() => {
// try {
// localStorage.setItem("taking_courses", JSON.stringify(courseList));
// } catch (error) {
// console.error("Failed to save courses to localStorage:", error);
// }
// }, [courseList]);
return (
<UserContext.Provider
value={{ userId, setUserId, courseList, setCourseList }}
Expand Down
3 changes: 3 additions & 0 deletions pages/[courseName]/assignments/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Assignments() {
return <div>Assignments</div>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {
TableRow,
} from "@/components/ui/table";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";

async function getFilesList(courseName: string | string[] | undefined) {
async function getFilesList(courseName: string) {
let res = await fetch(
"http://localhost:3000/api/" + courseName + "/listFiles",
{
Expand All @@ -26,10 +27,17 @@ async function getFilesList(courseName: string | string[] | undefined) {
}

export default async function Files() {
const [filesList, setFilesList] = useState<FilesList | null>(null);
const router = useRouter();
const { courseName } = router.query;

const filesList: FilesList = await getFilesList(courseName);
useEffect(() => {
if (typeof courseName === "string") {
getFilesList(courseName)
.then(setFilesList)
.catch((error) => console.error(error));
}
}, [courseName]);
return (
<div className="hidden h-full flex-1 flex-col space-y-8 p-8 md:flex">
<div className="flex items-center justify-between space-y-2">
Expand Down Expand Up @@ -60,3 +68,6 @@ export default async function Files() {
</div>
);
}
// export default function Files() {
// return <div>files</div>;
// }
120 changes: 120 additions & 0 deletions pages/[courseName]/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"use client";

import { useRouter } from "next/router";
import React from "react";
import type {
InferGetStaticPropsType,
GetStaticProps,
GetStaticPaths,
} from "next";
import { useUserContext } from "@/context/userContext";
import { Course, CourseList } from "@/lib/types";

// type Repo = {
// name: string;
// stargazers_count: number;
// };

// export const getStaticPaths = (async () => {
// return {
// paths: [
// {
// params: {
// name: "next.js",
// },
// }, // See the "paths" section below
// ],
// fallback: true, // false or "blocking"
// };
// }) satisfies GetStaticPaths;

// export const getStaticProps = (async (context) => {
// const res = await fetch("https://api.github.com/repos/vercel/next.js");
// const repo = await res.json();
// return { props: { repo } };
// }) satisfies GetStaticProps<{
// repo: Repo;
// }>;

// const courseList: CourseList = [
// { id: 1, name: "cs3312" },
// { id: 2, name: "cs2200" },
// { id: 3, name: "cs4400" },
// ];

// export const getStaticPaths = (async () => {
// const paths = courseList.map((course) => ({
// params: { path: course.name },
// }));
// return { paths, fallback: false };
// }) satisfies GetStaticPaths;

// export const getStaticProps = (async (context) => {
// const courseName = courseList.find((course) => course.name === context);
// return { props: { courseName } };
// }) satisfies GetStaticProps<{
// courseName: Course | undefined;
// }>;

// export async function getStaticProps({ params }) {
// const courseName = courseList.find((course) => course.name === params.path);
// return { props: { courseName } };
// }

// const { BlockBlobClient } = require("@azure/storage-blob");
// // import ReactMarkdown from "react-markdown";

// async function getSASurl(courseName: string) {
// let res = await fetch(
// "http://localhost:3000/api/" +
// courseName +
// "/getSAS?filename=readme/syllabus.md",
// {
// method: "GET",
// }
// );

// if (!res.ok) {
// throw new Error("Failed to fetch data");
// }
// let sasURL = await res.json();
// return sasURL.sasURL;
// }

// // Convert stream to text
// async function streamToText(readable: any) {
// readable.setEncoding("utf8");
// let data = "";
// for await (const chunk of readable) {
// data += chunk;
// }
// return data;
// }

// // Download the blob content
// async function getHomePage(courseName: string) {
// const sasURL: string = await getSASurl(courseName);
// const blockBlobClient = new BlockBlobClient(sasURL);

// const downloadBlockBlobResponse = await blockBlobClient.download(0);
// const downloaded = await streamToText(
// await downloadBlockBlobResponse.readableStreamBody
// );
// return downloaded;
// }

// export default async function Course() {
export default function Course() {
// const { courseList } = useUserContext();
// const router = useRouter();
// const { courseName } = router.query;
// console.log(repo);
// const content = await getHomePage(params.courseName); FETCH DISABLED WHILE DEVELOPING

return (
<div>
{/* <ReactMarkdown className="prose" children={content} /> FETCH DISABLED WHILE DEVELOPING*/}
<h1>Course</h1>
</div>
);
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default function Quiz() {
const router = useRouter();
const { quizName } = router.query;

const pathName = usePathname();
const pathName = router.asPath;
console.log(pathName);
const { isTA } = useUserTypeContext();

return (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import {
import { Button } from "@/components/ui/button";
import { useContext, useState } from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useUserTypeContext } from "@/context/userTypeContext";
import { useRouter } from "next/router";

export default function Quizzes() {
const router = useRouter();
const { courseName } = router.query;
console.log("courseName" + courseName);
const currentPath = router.pathname;
// List of the quizzes' file names.
const [quizList, setQuizList] = useState([
"Quiz_0",
Expand All @@ -30,8 +31,6 @@ export default function Quizzes() {

const { isTA, setIsTA } = useUserTypeContext();

const pathName = usePathname();

return (
<div className="hidden h-full flex-1 flex-col space-y-8 p-8 md:flex">
<div className="flex items-center justify-between space-y-2">
Expand All @@ -53,8 +52,10 @@ export default function Quizzes() {
? quizList.map((quizName: string) => (
<TableRow key={quizName}>
<TableCell>
{" "}
<Link href={`${pathName}/${quizName}`} className="flex ">
<Link
href={`${currentPath}/${quizName}`}
className="flex "
>
<span>{quizName}</span>
</Link>
</TableCell>
Expand All @@ -65,7 +66,7 @@ export default function Quizzes() {
<TableCell>
{isTA && (
<Button>
<Link href={`${pathName}/create`} className="flex ">
<Link href={`${currentPath}/create`} className="flex ">
<span>create</span>
</Link>
</Button>
Expand Down
27 changes: 15 additions & 12 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { CourseList, User } from "@/lib/types";
import { useRouter } from "next/router";
import Sidebar from "@/components/Sidebar";
import { UserContextProvider } from "@/context/userContext";

export default function App({ Component, pageProps }: AppProps) {
// const session = await auth(); // This is from next-auth after OAuth login
Expand All @@ -36,18 +37,20 @@ export default function App({ Component, pageProps }: AppProps) {
];
const { isTA, setIsTA } = useUserTypeContext();

const showSidebar = router.pathname.startsWith("/courses");
const showSidebar = !router.pathname.startsWith("/dashboard");
return (
<UserTypeContextProvider>
<CourseContextProvider>
<SessionProvider session={pageProps.session}>
<div className="flex">
<Navbar courseList={courseList} />
{showSidebar && <Sidebar />}
<Component {...pageProps} />
</div>
</SessionProvider>
</CourseContextProvider>
</UserTypeContextProvider>
<UserContextProvider>
<UserTypeContextProvider>
<CourseContextProvider>
<SessionProvider session={pageProps.session}>
<div className="flex">
<Navbar courseList={courseList} />
{showSidebar && <Sidebar />}
<Component {...pageProps} />
</div>
</SessionProvider>
</CourseContextProvider>
</UserTypeContextProvider>
</UserContextProvider>
);
}
1 change: 0 additions & 1 deletion pages/courses/[courseName]/assignments/index.tsx

This file was deleted.

Loading

0 comments on commit c47b8ec

Please sign in to comment.