This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
77 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
import {Project, Subject} from "../utils/ApiInterfaces.ts"; | ||
import apiFetch from "../utils/ApiFetch.ts"; | ||
|
||
export enum projectLoaderRole { | ||
export enum teacherStudentRole { | ||
STUDENT = "student", | ||
TEACHER = "teacher" | ||
} | ||
|
||
export async function projectLoader(role: projectLoaderRole): Promise<Project[]> { | ||
const projects: Project[] = await (await apiFetch(`/api/${role}/projects`)).json() as Project[]; | ||
const subjects: Subject[] = await (await apiFetch(`/api/${role}/subjects`)).json() as Subject[]; | ||
export async function projectsLoader(role: teacherStudentRole): Promise<Project[]> { | ||
const getter = await getAllProjectsAndSubjects(role); | ||
const subjects = getter.subjects; | ||
const projects = getter.projects; | ||
// TODO: add submission data | ||
for (let i = 0; i < projects.length; i++) { | ||
const subject: Subject | undefined = subjects.find(subject => subject.id === projects[i].subject_id); | ||
if (subject !== undefined) { | ||
projects[i].subject_name = subject.name; | ||
} | ||
} | ||
// TODO: add submission data | ||
return projects; | ||
} | ||
|
||
export interface projectsAndSubjects { | ||
projects: Project[], | ||
subjects: Subject[] | ||
} | ||
|
||
export async function getAllProjectsAndSubjects(role: teacherStudentRole): Promise<projectsAndSubjects> { | ||
const projects: Project[] = await (await apiFetch(`/${role}/projects`)).json() as Project[]; | ||
const subjects: Subject[] = await (await apiFetch(`/${role}/subjects`)).json() as Subject[]; | ||
return {projects, subjects} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import {Project} from "../utils/ApiInterfaces.ts"; | ||
import {projectLoader, projectLoaderRole} from "./SharedFunctions.ts"; | ||
import {projectsLoader, teacherStudentRole} from "./SharedFunctions.ts"; | ||
|
||
export interface studentLoaderObject { | ||
projects: Project[] | ||
} | ||
export default async function studentLoader(): Promise<studentLoaderObject> { | ||
const projects: Project[] = await projectLoader(projectLoaderRole.STUDENT); | ||
const projects: Project[] = await projectsLoader(teacherStudentRole.STUDENT); | ||
// TODO: add submission data | ||
return {"projects": projects}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {Project, properSubject, Subject} from "../utils/ApiInterfaces.ts"; | ||
import {getAllProjectsAndSubjects, projectsAndSubjects, teacherStudentRole} from "./SharedFunctions.ts"; | ||
|
||
export interface subjectsTeacherLoaderObject { | ||
subjects: properSubject[] | ||
} | ||
|
||
export let SUBJECT_TEACHER_ID = "subjectTeacher"; | ||
|
||
export default async function subjectsTeacherLoader(): Promise<subjectsTeacherLoaderObject> { | ||
const temp: projectsAndSubjects = await getAllProjectsAndSubjects(teacherStudentRole.TEACHER); | ||
const subjects: Subject[] = temp.subjects; | ||
const projects: Project[] = temp.projects; | ||
|
||
const p_subjects: properSubject[] = subjects.map(subject => { | ||
const active_projects = projects.filter(project => | ||
project.archived && project.subject_id === subject.id | ||
); | ||
return { | ||
id: subject.id, | ||
name: subject.name, | ||
active_projects: active_projects.length, | ||
first_deadline: null // TODO: add deadlines when needed api endpoints are added. | ||
}; | ||
}); | ||
return {"subjects": p_subjects} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import {Project} from "../utils/ApiInterfaces.ts"; | ||
import {projectLoader, projectLoaderRole} from "./SharedFunctions.ts"; | ||
import {projectsLoader, teacherStudentRole} from "./SharedFunctions.ts"; | ||
|
||
export interface teacherLoaderObject { | ||
projects: Project[] | ||
} | ||
export default async function teacherLoader(): Promise<teacherLoaderObject> { | ||
const projects: Project[] = await projectLoader(projectLoaderRole.TEACHER); | ||
const projects: Project[] = await projectsLoader(teacherStudentRole.TEACHER); | ||
return {"projects": projects} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {JSX} from "react"; | ||
import {SUBJECT_TEACHER_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; | ||
console.log(data); | ||
|
||
return( | ||
<p>hier ziet de lkr al zijn vakken.</p> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters