Skip to content

Commit 104a498

Browse files
authored
Merge pull request #66 from Coding-Club-IITG/shreya
Shreya
2 parents aa77ee5 + 983b7e3 commit 104a498

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

client/src/screens/browse/components/collapsible/index.jsx

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,28 @@ const Collapsible = ({ course, color, state }) => {
2626
const dispatch = useDispatch();
2727

2828
const onClick = () => {
29-
if (initial && !open) triggerGetCourse();
29+
if (!open) triggerGetCourse();
30+
else dispatch(ChangeCurrentYearData(null, []));
3031
setOpen(!open);
3132
};
3233

3334
const getCurrentCourse = async (code) => {
35+
dispatch(ChangeCurrentYearData(null, [])); // Clear folderData till next folderData is loaded
36+
setLoading(true);
3437
let currCourse = null;
3538
let insessionStorage = null;
3639
try {
37-
currCourse = allCourseData.find(
38-
(course) => course.code.toLowerCase() === code.toLowerCase().replaceAll(" ", "")
40+
const allLocal = JSON.parse(sessionStorage.getItem("AllCourses"));
41+
insessionStorage = allLocal?.find(
42+
(course) => course.code.toLowerCase() === code.toLowerCase().replaceAll(" ","")
3943
);
4044
} catch (error) {
4145
sessionStorage.removeItem("AllCourses");
4246
location.reload();
4347
}
4448
try {
45-
const allLocal = JSON.parse(sessionStorage.getItem("AllCourses"));
46-
insessionStorage = allLocal?.find(
47-
(course) => course.code.toLowerCase() === code.toLowerCase()
49+
currCourse = allCourseData.find(
50+
(course) => course.code.toLowerCase() === code.toLowerCase().replaceAll(" ","")
4851
);
4952
} catch (error) {
5053
sessionStorage.removeItem("AllCourses");
@@ -82,37 +85,30 @@ const Collapsible = ({ course, color, state }) => {
8285
}
8386
}
8487
setLoading(false);
88+
dispatch(ChangeFolder(null));
8589
return currCourse;
8690
};
8791

8892
const triggerGetCourse = () => {
8993
const run = async () => {
9094
const t = await getCurrentCourse(course.code);
9195
if (t) {
96+
const yearChildren = Array.isArray(t.children?.[t.children.length - 1]?.children)
97+
? t.children[t.children.length - 1].children : [];
9298
if (initial) {
93-
const prevChildren = Array.isArray(t.children?.[t.children.length - 1]?.children)
94-
? t.children[t.children.length - 1].children : [];
95-
dispatch(ChangeCurrentYearData(t.children.length - 1, prevChildren));
99+
dispatch(ChangeCurrentYearData(t.children.length - 1, yearChildren));
96100
setInitial(false);
97101
} else {
98102
try {
99-
dispatch(
100-
ChangeCurrentYearData(currentYear, t.children?.[currentYear].children)
101-
);
103+
dispatch(ChangeCurrentYearData(t.children.length - 1, yearChildren));
102104
if (!folderId) {
103-
dispatch(ChangeFolder(t.children?.[currentYear]));
105+
dispatch(ChangeFolder(t.children?.[t.children.length - 1]));
104106
folderId = null;
105107
}
106108
} catch (error) {
107109
// console.log(error);
108-
dispatch(
109-
ChangeCurrentYearData(
110-
t.children.length - 1,
111-
t.children?.[t.children.length - 1].children
112-
)
113-
);
110+
dispatch(ChangeCurrentYearData(t.children.length - 1,yearChildren));
114111
dispatch(ChangeFolder(t.children?.[t.children.length - 1]));
115-
setInitial(false);
116112
}
117113
}
118114
dispatch(ChangeCurrentCourse(t.children, t.code));
@@ -125,14 +121,13 @@ const Collapsible = ({ course, color, state }) => {
125121
useEffect(() => {
126122
// console.log(currCourseCode);
127123
// console.log(course);
128-
//console.log(currCourseCode?.toLowerCase(),courseCode?.toLowerCase());
129124
if (currCourseCode?.toLowerCase() !== courseCode?.toLowerCase()){setOpen(false);}
130125
if (currCourseCode?.toLowerCase() === courseCode?.toLowerCase()) {
131126
//console.log("called");
132127
triggerGetCourse();
133128
setOpen(true);
134129
}
135-
setInitial(true);
130+
//setInitial(true);
136131
}, [currCourseCode]);
137132

138133
useEffect(() => {
@@ -145,7 +140,6 @@ const Collapsible = ({ course, color, state }) => {
145140

146141
useEffect(() => {
147142
if (initial) return;
148-
//console.log(code,courseCode?.toLowerCase());
149143
if (code && folderId && code?.toLowerCase() === courseCode?.toLowerCase()) {
150144
// console.log(course);
151145
try {

client/src/screens/browse/components/navbar/index.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import Logo from "./components/logo";
33
import NavLink from "../../../../components/navbar/components/navlink";
44
import SearchBar from "../../../../components/navbar/components/searchbar";
55
import { useNavigate } from "react-router-dom";
6+
import { useDispatch } from "react-redux";
7+
import { LogoutUser } from "../../../../actions/user_actions";
68
const NavBarBrowseScreen = () => {
79
const navigate = useNavigate();
10+
const dispatch = useDispatch();
811
const handleLogout = () => {
912
dispatch(LogoutUser());
10-
window.location = "https://www.coursehubiitg.in/logout";
13+
window.location = "http://localhost:8080/api/auth/logout";
1114
};
1215
return (
1316
<nav className="nav-browse">

client/src/screens/dashboard/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ const Dashboard = () => {
104104
}, []);
105105

106106
const handleClick = (code) => {
107-
dispatch(ChangeCurrentCourse(null, code.toUpperCase()));
107+
let Code=code.replaceAll(" ","");
108+
dispatch(ChangeCurrentCourse(null, Code.toUpperCase()));
108109
navigate("/browse");
109110
};
110111
// console.log(user);

0 commit comments

Comments
 (0)