diff --git a/client/src/screens/browse/components/collapsible/index.jsx b/client/src/screens/browse/components/collapsible/index.jsx index 49779caa..a97084cb 100644 --- a/client/src/screens/browse/components/collapsible/index.jsx +++ b/client/src/screens/browse/components/collapsible/index.jsx @@ -26,25 +26,28 @@ const Collapsible = ({ course, color, state }) => { const dispatch = useDispatch(); const onClick = () => { - if (initial && !open) triggerGetCourse(); + if (!open) triggerGetCourse(); + else dispatch(ChangeCurrentYearData(null, [])); setOpen(!open); }; const getCurrentCourse = async (code) => { + dispatch(ChangeCurrentYearData(null, [])); // Clear folderData till next folderData is loaded + setLoading(true); let currCourse = null; let insessionStorage = null; try { - currCourse = allCourseData.find( - (course) => course.code.toLowerCase() === code.toLowerCase().replaceAll(" ", "") + const allLocal = JSON.parse(sessionStorage.getItem("AllCourses")); + insessionStorage = allLocal?.find( + (course) => course.code.toLowerCase() === code.toLowerCase().replaceAll(" ","") ); } catch (error) { sessionStorage.removeItem("AllCourses"); location.reload(); } try { - const allLocal = JSON.parse(sessionStorage.getItem("AllCourses")); - insessionStorage = allLocal?.find( - (course) => course.code.toLowerCase() === code.toLowerCase() + currCourse = allCourseData.find( + (course) => course.code.toLowerCase() === code.toLowerCase().replaceAll(" ","") ); } catch (error) { sessionStorage.removeItem("AllCourses"); @@ -82,6 +85,7 @@ const Collapsible = ({ course, color, state }) => { } } setLoading(false); + dispatch(ChangeFolder(null)); return currCourse; }; @@ -89,30 +93,22 @@ const Collapsible = ({ course, color, state }) => { const run = async () => { const t = await getCurrentCourse(course.code); if (t) { + const yearChildren = Array.isArray(t.children?.[t.children.length - 1]?.children) + ? t.children[t.children.length - 1].children : []; if (initial) { - const prevChildren = Array.isArray(t.children?.[t.children.length - 1]?.children) - ? t.children[t.children.length - 1].children : []; - dispatch(ChangeCurrentYearData(t.children.length - 1, prevChildren)); + dispatch(ChangeCurrentYearData(t.children.length - 1, yearChildren)); setInitial(false); } else { try { - dispatch( - ChangeCurrentYearData(currentYear, t.children?.[currentYear].children) - ); + dispatch(ChangeCurrentYearData(t.children.length - 1, yearChildren)); if (!folderId) { - dispatch(ChangeFolder(t.children?.[currentYear])); + dispatch(ChangeFolder(t.children?.[t.children.length - 1])); folderId = null; } } catch (error) { // console.log(error); - dispatch( - ChangeCurrentYearData( - t.children.length - 1, - t.children?.[t.children.length - 1].children - ) - ); + dispatch(ChangeCurrentYearData(t.children.length - 1,yearChildren)); dispatch(ChangeFolder(t.children?.[t.children.length - 1])); - setInitial(false); } } dispatch(ChangeCurrentCourse(t.children, t.code)); @@ -125,14 +121,13 @@ const Collapsible = ({ course, color, state }) => { useEffect(() => { // console.log(currCourseCode); // console.log(course); - //console.log(currCourseCode?.toLowerCase(),courseCode?.toLowerCase()); if (currCourseCode?.toLowerCase() !== courseCode?.toLowerCase()){setOpen(false);} if (currCourseCode?.toLowerCase() === courseCode?.toLowerCase()) { //console.log("called"); triggerGetCourse(); setOpen(true); } - setInitial(true); + //setInitial(true); }, [currCourseCode]); useEffect(() => { @@ -145,7 +140,6 @@ const Collapsible = ({ course, color, state }) => { useEffect(() => { if (initial) return; - //console.log(code,courseCode?.toLowerCase()); if (code && folderId && code?.toLowerCase() === courseCode?.toLowerCase()) { // console.log(course); try { diff --git a/client/src/screens/browse/components/navbar/index.jsx b/client/src/screens/browse/components/navbar/index.jsx index c9fbb866..12f0dd97 100644 --- a/client/src/screens/browse/components/navbar/index.jsx +++ b/client/src/screens/browse/components/navbar/index.jsx @@ -3,11 +3,14 @@ import Logo from "./components/logo"; import NavLink from "../../../../components/navbar/components/navlink"; import SearchBar from "../../../../components/navbar/components/searchbar"; import { useNavigate } from "react-router-dom"; +import { useDispatch } from "react-redux"; +import { LogoutUser } from "../../../../actions/user_actions"; const NavBarBrowseScreen = () => { const navigate = useNavigate(); + const dispatch = useDispatch(); const handleLogout = () => { dispatch(LogoutUser()); - window.location = "https://www.coursehubiitg.in/logout"; + window.location = "http://localhost:8080/api/auth/logout"; }; return (