Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Course details #224

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"welcomeDescription": "Welcome to Peristerónas, the online submission platform of UGent",
"login": "Login"
},
"courseDetailTeacher": {
"courseDetail": {
"title": "Course Details",
"deleteCourse": "Delete Course",
"unauthorizedDelete": "You are unauthorized to delete this course",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "react-router-dom";
import Layout from "./components/Header/Layout";
import { AllCoursesTeacher } from "./components/Courses/AllCoursesTeacher";
import { CourseDetailTeacher } from "./components/Courses/CourseDetailTeacher";
import { CourseDetail } from "./components/Courses/CourseDetail.tsx";
import {
dataLoaderCourseDetail,
dataLoaderCourses,
Expand Down Expand Up @@ -41,7 +41,7 @@ const router = createBrowserRouter(
<Route path="courses">
<Route index element={<AllCoursesTeacher />} loader={dataLoaderCourses}/>
<Route path="join" loader={synchronizeJoinCode} />
<Route path=":courseId" element={<CourseDetailTeacher />} loader={dataLoaderCourseDetail} />
<Route path=":courseId" element={<CourseDetail />} loader={dataLoaderCourseDetail} />
</Route>
<Route path="projects">
<Route
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/components/Courses/CourseDetail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useEffect, useState } from "react";
import { fetchMe } from "../../utils/fetches/FetchMe";
import { CourseDetailStudent } from "./CourseDetailStudent";
import { CourseDetailTeacher } from "./CourseDetailTeacher";
import { Me } from "../../types/me";

/**
*
* @returns The right course detail component according to the role of the user.
*/
export function CourseDetail(): JSX.Element {
const [me, setMe] = useState<Me | null>(null);

useEffect(() => {
fetchMe().then((data) => {
setMe(data);
});
}, []);

if (me?.role === "STUDENT") {
return <CourseDetailStudent />;
}
if (me === undefined) {
return <></>;
}
return <CourseDetailTeacher />;
}
49 changes: 49 additions & 0 deletions frontend/src/components/Courses/CourseDetailStudent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
Grid,
Paper,
Typography
} from "@mui/material";
import { useLoaderData } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Course } from "../../types/course";
import { ProjectDetail } from "./CourseUtils";
import { Title } from "../Header/Title";
import { EmptyOrNotProjects } from "./CourseDetailTeacher";

/**
*
* @returns The component representing the course details page for a student.
*/
export function CourseDetailStudent(): JSX.Element {
const courseDetail = useLoaderData() as {
course: Course;
projects: ProjectDetail[];
};

const { course, projects } = courseDetail;
const { t } = useTranslation("translation", {
keyPrefix: "courseDetail",
});

return (
<>
<Title title={course.name}></Title>
<Grid
container
direction={"row"}
spacing={2}
margin="1rem"
style={{ height: "80vh" }}
>
<Grid item xs={5} height="100%">
<Paper
style={{ height: "100%", maxHeight: "100%", overflow: "auto" }}
>
<Typography variant="h5">{t("projects")}:</Typography>
<EmptyOrNotProjects projects={projects} />
</Paper>
</Grid>
</Grid>
</>
);
}
8 changes: 4 additions & 4 deletions frontend/src/components/Courses/CourseDetailTeacher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function CourseDetailTeacher(): JSX.Element {
const [adminObjects, setAdminObjects] = useState<Me[]>([]);
const [studentObjects, setStudentObjects] = useState<Me[]>([]);
const { t } = useTranslation("translation", {
keyPrefix: "courseDetailTeacher",
keyPrefix: "courseDetail",
});
const { i18n } = useTranslation();
const lang = i18n.language;
Expand Down Expand Up @@ -303,13 +303,13 @@ export function CourseDetailTeacher(): JSX.Element {
* @param projects - The array of projects.
* @returns Either a place holder for no projects or a grid of cards describing the projects.
*/
function EmptyOrNotProjects({
export function EmptyOrNotProjects({
projects,
}: {
projects: ProjectDetail[];
}): JSX.Element {
const { t } = useTranslation("translation", {
keyPrefix: "courseDetailTeacher",
keyPrefix: "courseDetail",
});
if (projects === undefined || projects.length === 0) {
return <Typography variant="h6">{t("noProjects")}</Typography>;
Expand Down Expand Up @@ -474,7 +474,7 @@ function JoinCodeMenu({
anchorEl: HTMLElement | null;
}) {
const { t } = useTranslation("translation", {
keyPrefix: "courseDetailTeacher",
keyPrefix: "courseDetail",
});

const [codes, setCodes] = useState<JoinCode[]>([]);
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types/course.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface Course {
name: string;
teacher: string;
projects: [string];
course_id: string;
}
12 changes: 12 additions & 0 deletions frontend/src/types/project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface Project {
title: string;
description: string;
assignment_file: string;
deadline: string;
course_id: string;
visible_for_students: boolean;
archived: boolean;
test_path: string;
script_name: string;
regex_expressions: [string];
}