From 455a8821a97ffb076080aac8309dcb2f6a96a088 Mon Sep 17 00:00:00 2001 From: Matthias Seghers Date: Wed, 13 Mar 2024 23:10:34 +0100 Subject: [PATCH] made router ID's a var to avoid typos --- frontend/src/dataloaders/StudentLoader.ts | 4 ++++ frontend/src/dataloaders/SubjectsTeacherLoader.ts | 2 +- frontend/src/dataloaders/TeacherLoader.ts | 3 +++ frontend/src/main.tsx | 12 ++++++------ frontend/src/pages/student/HomeStudent.tsx | 4 ++-- frontend/src/pages/teacher/HomeTeacher.tsx | 4 ++-- frontend/src/pages/teacher/SubjectsTeacher.tsx | 4 ++-- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/frontend/src/dataloaders/StudentLoader.ts b/frontend/src/dataloaders/StudentLoader.ts index 36d804db..39dd96d0 100644 --- a/frontend/src/dataloaders/StudentLoader.ts +++ b/frontend/src/dataloaders/StudentLoader.ts @@ -4,6 +4,10 @@ import {projectsLoader, teacherStudentRole} from "./SharedFunctions.ts"; export interface studentLoaderObject { projects: Project[] } + +export const STUDENT_ROUTER_ID = "student"; + + export default async function studentLoader(): Promise { const projects: Project[] = await projectsLoader(teacherStudentRole.STUDENT); // TODO: add submission data diff --git a/frontend/src/dataloaders/SubjectsTeacherLoader.ts b/frontend/src/dataloaders/SubjectsTeacherLoader.ts index 87432a67..e5c066a1 100644 --- a/frontend/src/dataloaders/SubjectsTeacherLoader.ts +++ b/frontend/src/dataloaders/SubjectsTeacherLoader.ts @@ -5,7 +5,7 @@ export interface subjectsTeacherLoaderObject { subjects: properSubject[] } -export let SUBJECT_TEACHER_ID = "subjectTeacher"; +export const SUBJECT_TEACHER_ROUTER_ID = "subjectTeacher"; export default async function subjectsTeacherLoader(): Promise { const temp: projectsAndSubjects = await getAllProjectsAndSubjects(teacherStudentRole.TEACHER); diff --git a/frontend/src/dataloaders/TeacherLoader.ts b/frontend/src/dataloaders/TeacherLoader.ts index 1be5fa07..da3e74ca 100644 --- a/frontend/src/dataloaders/TeacherLoader.ts +++ b/frontend/src/dataloaders/TeacherLoader.ts @@ -4,6 +4,9 @@ import {projectsLoader, teacherStudentRole} from "./SharedFunctions.ts"; export interface teacherLoaderObject { projects: Project[] } + +export const TEACHER_ROUTER_ID = "teacher"; + export default async function teacherLoader(): Promise { const projects: Project[] = await projectsLoader(teacherStudentRole.TEACHER); return {"projects": projects} diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index 6dd6346b..29f90a54 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -10,10 +10,10 @@ import HomeStudent from "./pages/student/HomeStudent.tsx"; import HomeTeacher from "./pages/teacher/HomeTeacher.tsx"; import 'bulma/css/bulma.min.css'; import './assets/styles/mainpage.css' -import studentLoader from "./dataloaders/StudentLoader.ts"; -import teacherLoader from "./dataloaders/TeacherLoader.ts"; +import studentLoader, {STUDENT_ROUTER_ID} from "./dataloaders/StudentLoader.ts"; +import teacherLoader, {TEACHER_ROUTER_ID} from "./dataloaders/TeacherLoader.ts"; import SubjectsTeacher from "./pages/teacher/SubjectsTeacher.tsx"; -import subjectsTeacherLoader, {SUBJECT_TEACHER_ID} from "./dataloaders/SubjectsTeacherLoader.ts"; +import subjectsTeacherLoader, {SUBJECT_TEACHER_ROUTER_ID} from "./dataloaders/SubjectsTeacherLoader.ts"; const router = createBrowserRouter([ { @@ -32,19 +32,19 @@ const router = createBrowserRouter([ { path: "/student", element: , - id: "student", + id: STUDENT_ROUTER_ID, loader: studentLoader }, { path: "/teacher", element: , - id: "teacher", + id: TEACHER_ROUTER_ID, loader: teacherLoader }, { path: "/teacher/courses", element: , - id: SUBJECT_TEACHER_ID, + id: SUBJECT_TEACHER_ROUTER_ID, loader: subjectsTeacherLoader } ]); diff --git a/frontend/src/pages/student/HomeStudent.tsx b/frontend/src/pages/student/HomeStudent.tsx index d53fa306..6a32fb36 100644 --- a/frontend/src/pages/student/HomeStudent.tsx +++ b/frontend/src/pages/student/HomeStudent.tsx @@ -4,12 +4,12 @@ import {Sidebar} from "../../components/Sidebar.tsx"; import ProjectCardStudent from "./ProjectCardStudent.tsx"; import '../../assets/styles/students_components.css' import {useRouteLoaderData} from "react-router-dom"; -import {studentLoaderObject} from "../../dataloaders/StudentLoader.ts"; +import {STUDENT_ROUTER_ID, studentLoaderObject} from "../../dataloaders/StudentLoader.ts"; export default function HomeStudent(): JSX.Element { // data contains a list of Project in data.projects (i think) - const data: studentLoaderObject = useRouteLoaderData("student") as studentLoaderObject + const data: studentLoaderObject = useRouteLoaderData(STUDENT_ROUTER_ID) as studentLoaderObject console.log(data) // TODO: remove return ( diff --git a/frontend/src/pages/teacher/HomeTeacher.tsx b/frontend/src/pages/teacher/HomeTeacher.tsx index 4b42b601..b38a8b1c 100644 --- a/frontend/src/pages/teacher/HomeTeacher.tsx +++ b/frontend/src/pages/teacher/HomeTeacher.tsx @@ -1,10 +1,10 @@ import {JSX} from "react"; -import {teacherLoaderObject} from "../../dataloaders/TeacherLoader.ts"; +import {TEACHER_ROUTER_ID, teacherLoaderObject} from "../../dataloaders/TeacherLoader.ts"; import {useRouteLoaderData} from "react-router-dom"; export default function HomeTeacher(): JSX.Element { - const data: teacherLoaderObject = useRouteLoaderData("teacher") as teacherLoaderObject; + const data: teacherLoaderObject = useRouteLoaderData(TEACHER_ROUTER_ID) as teacherLoaderObject; console.log(data); return ( diff --git a/frontend/src/pages/teacher/SubjectsTeacher.tsx b/frontend/src/pages/teacher/SubjectsTeacher.tsx index 30075e0a..ef214a2b 100644 --- a/frontend/src/pages/teacher/SubjectsTeacher.tsx +++ b/frontend/src/pages/teacher/SubjectsTeacher.tsx @@ -1,10 +1,10 @@ import {JSX} from "react"; -import {SUBJECT_TEACHER_ID, subjectsTeacherLoaderObject} from "../../dataloaders/SubjectsTeacherLoader.ts"; +import {SUBJECT_TEACHER_ROUTER_ID, subjectsTeacherLoaderObject} from "../../dataloaders/SubjectsTeacherLoader.ts"; import {useRouteLoaderData} from "react-router-dom"; export default function SubjectsTeacher(): JSX.Element { - const data: subjectsTeacherLoaderObject = useRouteLoaderData(SUBJECT_TEACHER_ID) as subjectsTeacherLoaderObject; + const data= useRouteLoaderData(SUBJECT_TEACHER_ROUTER_ID) as subjectsTeacherLoaderObject; console.log(data); return(