Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
made router ID's a var to avoid typos
Browse files Browse the repository at this point in the history
  • Loading branch information
matt01y committed Mar 13, 2024
1 parent 45be65a commit 455a882
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
4 changes: 4 additions & 0 deletions frontend/src/dataloaders/StudentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<studentLoaderObject> {
const projects: Project[] = await projectsLoader(teacherStudentRole.STUDENT);
// TODO: add submission data
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/dataloaders/SubjectsTeacherLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<subjectsTeacherLoaderObject> {
const temp: projectsAndSubjects = await getAllProjectsAndSubjects(teacherStudentRole.TEACHER);
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/dataloaders/TeacherLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<teacherLoaderObject> {
const projects: Project[] = await projectsLoader(teacherStudentRole.TEACHER);
return {"projects": projects}
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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([
{
Expand All @@ -32,19 +32,19 @@ const router = createBrowserRouter([
{
path: "/student",
element: <HomeStudent/>,
id: "student",
id: STUDENT_ROUTER_ID,
loader: studentLoader
},
{
path: "/teacher",
element: <HomeTeacher/>,
id: "teacher",
id: TEACHER_ROUTER_ID,
loader: teacherLoader
},
{
path: "/teacher/courses",
element: <SubjectsTeacher/>,
id: SUBJECT_TEACHER_ID,
id: SUBJECT_TEACHER_ROUTER_ID,
loader: subjectsTeacherLoader
}
]);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/student/HomeStudent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/teacher/HomeTeacher.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/teacher/SubjectsTeacher.tsx
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit 455a882

Please sign in to comment.