Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Merge branch 'development' into frontend/fix/authorization-project-view
Browse files Browse the repository at this point in the history
  • Loading branch information
AronBuzogany committed May 23, 2024
2 parents 947a797 + ff7dd73 commit d984e71
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 5 deletions.
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,6 @@ import {
} from "react-router-dom";
import Layout from "./components/Header/Layout";
import { AllCoursesTeacher } from "./components/Courses/AllCoursesTeacher";
import { CourseDetailTeacher } from "./components/Courses/CourseDetailTeacher";
import {
dataLoaderCourseDetail,
dataLoaderCourses,
Expand All @@ -23,6 +22,7 @@ import { synchronizeJoinCode } from "./loaders/join-code.ts";
import { fetchMe } from "./utils/fetches/FetchMe.ts";
import { fetchProjectForm } from "./components/ProjectForm/project-form.ts";
import loadSubmissionOverview from "./loaders/submission-overview-loader.ts";
import CoursesDetail from "./components/Courses/CoursesDetail.tsx";
import loadProjectViewData from "./loaders/project-view-loader.ts";

const router = createBrowserRouter(
Expand All @@ -45,7 +45,7 @@ const router = createBrowserRouter(
<Route path="join" loader={synchronizeJoinCode} />
<Route
path=":courseId"
element={<CourseDetailTeacher />}
element={<CoursesDetail />}
loader={dataLoaderCourseDetail}
/>
</Route>
Expand Down
94 changes: 94 additions & 0 deletions frontend/src/components/Courses/CourseDetailStudent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
Grid,
Paper,
Typography,
} from "@mui/material";
import { useTranslation } from "react-i18next";
import {
Course, ProjectDetail,
} from "./CourseUtils";
import {
useLoaderData,
} from "react-router-dom";
import { Title } from "../Header/Title";
import { Me } from "../../types/me";
import {EmptyOrNotProjects} from "./CourseDetailTeacher"

/**
*
* @returns A jsx component representing the course detail page for a teacher
*/
export default function CourseDetailStudent() {

const courseDetail = useLoaderData() as {
course: Course;
projects: ProjectDetail[];
adminMes: Me[];
studentMes: Me[];
me:Me;
};
const { course, projects, adminMes } = courseDetail;
const { t } = useTranslation("translation", {
keyPrefix: "courseDetailTeacher",
});

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" }}
>
<div style={{ padding: "1rem" }}>
<Typography variant="h5">{t("projects")}:</Typography>
<EmptyOrNotProjects projects={projects} />
</div>
</Paper>
</Grid>
<Grid item xs={5} height="100%">
<Grid container direction={"column"} spacing={2} height={"100%"}>
<Grid
item
style={{
height: "50%",
}}
>
<Paper
style={{
overflow: "auto",
height: "100%",
}}
>
<Typography variant="h5">{t("admins")}:</Typography>
<Grid container direction={"column"}>
{adminMes.map((admin: Me) => (
<Grid
container
alignItems="center"
spacing={1}
key={admin.uid}
>
<Grid item>
<Typography variant="body1">
{admin.display_name}
</Typography>
</Grid>

</Grid>
))}
</Grid>
</Paper>
</Grid>
</Grid>
</Grid>
</Grid>
</>
);
}
5 changes: 3 additions & 2 deletions frontend/src/components/Courses/CourseDetailTeacher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function handleDeleteCourse(
*
* @returns A jsx component representing the course detail page for a teacher
*/
export function CourseDetailTeacher(): JSX.Element {
export default function CourseDetailTeacher() {
const [selectedStudents, setSelectedStudents] = useState<string[]>([]);
const [anchorEl, setAnchorElStudent] = useState<null | HTMLElement>(null);
const openCodes = Boolean(anchorEl);
Expand All @@ -129,6 +129,7 @@ export function CourseDetailTeacher(): JSX.Element {
projects: ProjectDetail[];
adminMes: Me[];
studentMes: Me[];
me:Me;
};
const { course, projects, adminMes, studentMes } = courseDetail;
const { t } = useTranslation("translation", {
Expand Down Expand Up @@ -276,7 +277,7 @@ 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[];
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Courses/CourseUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,6 @@ export const dataLoaderCourseDetail = async ({
const student_uids = students.map((student: {uid: string}) => getIdFromLink(student.uid));
const adminMes = await fetchMes([course.teacher, ...admin_uids]);
const studentMes = await fetchMes(student_uids);
return { course, projects, adminMes, studentMes };
const me = await fetchMe();
return { course, projects, adminMes, studentMes, me};
};
24 changes: 24 additions & 0 deletions frontend/src/components/Courses/CoursesDetail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {useLoaderData} from "react-router-dom";
import {Me} from "../../types/me.ts";
import {Course, ProjectDetail} from "./CourseUtils.tsx";
import CourseDetailTeacher from "./CourseDetailTeacher.tsx";
import CourseDetailStudent from "./CourseDetailStudent.tsx";

/**
* gives the right detail page
* @returns - detail page
*/
export default function CoursesDetail() :JSX.Element {
const loader = useLoaderData() as {
course: Course;
projects: ProjectDetail[];
adminMes: Me[];
studentMes: Me[];
me:Me;
};
if (loader.course.teacher === loader.me.uid) {
return <CourseDetailTeacher/>;
} else {
return <CourseDetailStudent/>;
}
}

0 comments on commit d984e71

Please sign in to comment.