diff --git a/src/App.tsx b/src/App.tsx index afd77e2b..0347253b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,6 +7,7 @@ import { AboutPage, TimeTableSelectorPage, FaqsPage, NotFoundPage } from './page import { getPath, config, dev_config, plausible } from './utils' import Layout from './components/layout' import * as Sentry from "@sentry/react"; +import { SidebarProvider } from "./components/layout/SidebarPosition"; const configToUse = Number(import.meta.env.VITE_APP_PROD) ? config : dev_config @@ -60,33 +61,35 @@ const App = () => { const SentryRoutes = Sentry.withSentryReactRouterV6Routing(Routes); return ( - - - - {pages.map((page, pageIdx) => ( - -
- - -
- - } - /> - ))} - {redirects.map((redirect, redirectIdx) => ( - } - /> - ))} -
-
-
+ + + + + {pages.map((page, pageIdx) => ( + +
+ + +
+ + } + /> + ))} + {redirects.map((redirect, redirectIdx) => ( + } + /> + ))} +
+
+
+
) } diff --git a/src/components/layout/SidebarPosition.tsx b/src/components/layout/SidebarPosition.tsx new file mode 100644 index 00000000..bbf663dd --- /dev/null +++ b/src/components/layout/SidebarPosition.tsx @@ -0,0 +1,37 @@ +import { createContext, useContext, useState, useEffect } from "react"; + +type SidebarContextType = { + sidebarPosition: 'left' | 'right'; + toggleSidebarPosition: () => void; +}; + +const SidebarContext = createContext(undefined); + +export const SidebarProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { + const [sidebarPosition, setSidebarPosition] = useState<'left' | 'right'>(() => { + const storedPosition = window.localStorage.getItem("sidebar-position"); + return storedPosition === "left" || storedPosition === "right" ? storedPosition : "right"; + }); + + const toggleSidebarPosition = () => { + setSidebarPosition((prev) => { + const newPosition = prev === "right" ? "left" : "right"; + window.localStorage.setItem("sidebar-position", newPosition); + return newPosition; + }); + }; + + return ( + + {children} + + ); +}; + +export const useSidebarContext = () => { + const context = useContext(SidebarContext); + if (!context) { + throw new Error('useSidebarContext must be used within a SidebarProvider') + } + return context +} \ No newline at end of file diff --git a/src/components/planner/Sidebar.tsx b/src/components/planner/Sidebar.tsx index 9d6f9481..b78042e9 100644 --- a/src/components/planner/Sidebar.tsx +++ b/src/components/planner/Sidebar.tsx @@ -4,16 +4,19 @@ import OptionsController from './sidebar/OptionsController' import SelectedOptionController from './sidebar/SelectedOptionController' import CoursesController from './sidebar/CoursesController' import MultipleOptionsContext from '../../contexts/MultipleOptionsContext' +import { useSidebarContext } from '../layout/SidebarPosition' +import { ArrowsRightLeftIcon } from '@heroicons/react/24/outline' /** * Sidebar with all the main schedule interactions */ const Sidebar = () => { const { multipleOptions, selectedOption } = useContext(MultipleOptionsContext); + const { toggleSidebarPosition } = useSidebarContext(); return (
-
+
@@ -23,6 +26,15 @@ const Sidebar = () => {
+
+ +
) } diff --git a/src/components/planner/sidebar/CoursesController/ClassItem.tsx b/src/components/planner/sidebar/CoursesController/ClassItem.tsx index b8bc0332..538ca658 100644 --- a/src/components/planner/sidebar/CoursesController/ClassItem.tsx +++ b/src/components/planner/sidebar/CoursesController/ClassItem.tsx @@ -74,4 +74,4 @@ const ClassItem = ({ course_id, classInfo, onSelect, onMouseEnter, onMouseLeave ) } -export default ClassItem +export default ClassItem \ No newline at end of file diff --git a/src/components/planner/sidebar/sessionController/CoursePicker.tsx b/src/components/planner/sidebar/sessionController/CoursePicker.tsx index 6aa5116b..9a2b2622 100644 --- a/src/components/planner/sidebar/sessionController/CoursePicker.tsx +++ b/src/components/planner/sidebar/sessionController/CoursePicker.tsx @@ -15,9 +15,9 @@ import { ClearAllCoursesButton } from './course-picker/ClearAllCoursesButton' //TODO: absolute imports with @ + const CoursePicker = () => { const { pickedCourses, setPickedCourses, checkboxedCourses, setChoosingNewCourse, setCoursesInfo, ucsModalOpen, setUcsModalOpen } = useContext(CourseContext) - const [selectedMajor, setSelectedMajor] = useState(StorageAPI.getSelectedMajorStorage()); const { courseUnits, loading: loadingCourseUnits } = useCourseUnits(selectedMajor ? selectedMajor.id : null); const showContent = selectedMajor || pickedCourses.length > 0 diff --git a/src/pages/TimeTableSelector.tsx b/src/pages/TimeTableSelector.tsx index 9eb6f343..4e140c27 100644 --- a/src/pages/TimeTableSelector.tsx +++ b/src/pages/TimeTableSelector.tsx @@ -5,6 +5,7 @@ import { Schedule, Sidebar } from '../components/planner' import { CourseInfo, Major } from '../@types' import MajorContext from '../contexts/MajorContext' import CourseContext from '../contexts/CourseContext' +import { useSidebarContext } from '../components/layout/SidebarPosition' const TimeTableSelectorPage = () => { const [majors, setMajors] = useState([]) @@ -12,6 +13,7 @@ const TimeTableSelectorPage = () => { const [pickedCourses, setPickedCourses] = useState(StorageAPI.getPickedCoursesStorage()); const [checkboxedCourses, setCheckboxedCourses] = useState(StorageAPI.getPickedCoursesStorage()); const [ucsModalOpen, setUcsModalOpen] = useState(false); + const { sidebarPosition } = useSidebarContext(); //TODO: Looks suspicious const [choosingNewCourse, setChoosingNewCourse] = useState(false); @@ -21,6 +23,8 @@ const TimeTableSelectorPage = () => { setMajors(majors) }) }, []) + + return ( { } }>
- {/* Schedule Preview */} -
-
+ {sidebarPosition === 'left' ?( + <> +
+ +
+
+ +
+ + ) : ( + <> +
-
-
- - +
+
+ +
+ + )}
- ) -} + ); +}; + -export default TimeTableSelectorPage; +export default TimeTableSelectorPage; \ No newline at end of file