2023-08-25 22:54:30 +00:00
|
|
|
import { createSignal } from "solid-js";
|
|
|
|
import { Course } from "../types/Course";
|
|
|
|
|
2023-08-29 16:14:33 +00:00
|
|
|
type CourseMap = {[k: number]: Course};
|
|
|
|
|
2023-08-25 22:54:30 +00:00
|
|
|
export const [allCourses, setAllCourses] = createSignal<Array<Course>>([]);
|
2023-08-29 16:14:33 +00:00
|
|
|
export const [courseMap, setCourseMap] = createSignal<CourseMap>({});
|
2023-08-25 22:54:30 +00:00
|
|
|
|
|
|
|
(() => {
|
|
|
|
// Get all courses from the API
|
|
|
|
fetch(`${import.meta.env.VITE_BACKEND_URL}/api/course`)
|
|
|
|
.then((res) => res.json())
|
2023-08-29 16:14:33 +00:00
|
|
|
.then((data: Array<Course>) => {
|
|
|
|
setAllCourses(data);
|
|
|
|
|
|
|
|
const map: CourseMap = {};
|
|
|
|
for (const course of data) {
|
|
|
|
map[course.course_id] = course;
|
|
|
|
}
|
|
|
|
console.log("course map", map);
|
|
|
|
setCourseMap(map);
|
|
|
|
});
|
2023-08-25 22:54:30 +00:00
|
|
|
})();
|
|
|
|
|