Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions client/src/screens/browse/components/collapsible/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -82,37 +85,30 @@ const Collapsible = ({ course, color, state }) => {
}
}
setLoading(false);
dispatch(ChangeFolder(null));
return currCourse;
};

const triggerGetCourse = () => {
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));
Expand All @@ -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(() => {
Expand All @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion client/src/screens/browse/components/navbar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<nav className="nav-browse">
Expand Down
3 changes: 2 additions & 1 deletion client/src/screens/dashboard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ const Dashboard = () => {
}, []);

const handleClick = (code) => {
dispatch(ChangeCurrentCourse(null, code.toUpperCase()));
let Code=code.replaceAll(" ","");
dispatch(ChangeCurrentCourse(null, Code.toUpperCase()));
navigate("/browse");
};
// console.log(user);
Expand Down
Loading