From 2b55611c70d9d74cb1a7a7efa294f410b4d69269 Mon Sep 17 00:00:00 2001 From: Process-ing Date: Tue, 20 Aug 2024 18:05:52 +0100 Subject: [PATCH] Move context states to CombinedProvider --- src/contexts/CombinedProvider.tsx | 22 +++++++++++++-- src/pages/TimeTableScheduler.tsx | 45 +++++++++---------------------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/contexts/CombinedProvider.tsx b/src/contexts/CombinedProvider.tsx index 770ec418..77f10a6f 100644 --- a/src/contexts/CombinedProvider.tsx +++ b/src/contexts/CombinedProvider.tsx @@ -1,14 +1,21 @@ import { useState } from "react"; -import { MultipleOptions } from "../@types"; +import { CourseInfo, Major, MultipleOptions } from "../@types"; import StorageAPI from "../api/storage"; import MultipleOptionsContext from "./MultipleOptionsContext"; import { ThemeContext } from "./ThemeContext"; import { useDarkMode } from "../hooks"; +import CourseContext from "./CourseContext"; +import MajorContext from "./MajorContext"; const CombinedProvider = ({ children }) => { const [enabled, setEnabled] = useDarkMode() // TODO (Process-ing): Stop using a hook (who smoked here?) const [multipleOptions, setMultipleOptionsState] = useState(StorageAPI.getMultipleOptionsStorage()); const [selectedOption, setSelectedOptionState] = useState(StorageAPI.getSelectedOptionStorage()); + const [majors, setMajors] = useState([]) + const [coursesInfo, setCoursesInfo] = useState([]); + const [pickedCourses, setPickedCourses] = useState(StorageAPI.getPickedCoursesStorage()); + const [checkboxedCourses, setCheckboxedCourses] = useState(StorageAPI.getPickedCoursesStorage()); + const [choosingNewCourse, setChoosingNewCourse] = useState(false); const setMultipleOptions = (newMultipleOptions: MultipleOptions | ((prevMultipleOptions: MultipleOptions) => MultipleOptions)) => { @@ -30,7 +37,18 @@ const CombinedProvider = ({ children }) => { return ( - {children} + + + {children} + + ); diff --git a/src/pages/TimeTableScheduler.tsx b/src/pages/TimeTableScheduler.tsx index d50eefb3..9ff3c9ae 100644 --- a/src/pages/TimeTableScheduler.tsx +++ b/src/pages/TimeTableScheduler.tsx @@ -1,19 +1,11 @@ import BackendAPI from '../api//backend' -import StorageAPI from '../api/storage' -import { useState, useEffect } from 'react' +import { useEffect, useContext } from 'react' import { Schedule, Sidebar } from '../components/planner' -import { CourseInfo, Major } from '../@types' import MajorContext from '../contexts/MajorContext' -import CourseContext from '../contexts/CourseContext' +import { Major } from '../@types' const TimeTableSchedulerPage = () => { - const [majors, setMajors] = useState([]) - const [coursesInfo, setCoursesInfo] = useState([]); - const [pickedCourses, setPickedCourses] = useState(StorageAPI.getPickedCoursesStorage()); - const [checkboxedCourses, setCheckboxedCourses] = useState(StorageAPI.getPickedCoursesStorage()); - - //TODO: Looks suspicious - const [choosingNewCourse, setChoosingNewCourse] = useState(false); + const { setMajors } = useContext(MajorContext); // // fetch majors when component is ready useEffect(() => { @@ -21,30 +13,19 @@ const TimeTableSchedulerPage = () => { BackendAPI.getMajors().then((majors: Major[]) => { setMajors(majors) }) - }, []) + }, []); return ( - - -
- {/* Schedule Preview */} -
-
- -
-
- - +
+ {/* Schedule Preview */} +
+
+
- - +
+ + +
) }