Skip to content

Commit

Permalink
🐛 fix bug related to selection when teacher is selecting attendance
Browse files Browse the repository at this point in the history
  • Loading branch information
lumi-tip committed Aug 28, 2024
1 parent ab13814 commit b6f1c38
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 32 deletions.
19 changes: 1 addition & 18 deletions src/common/components/AttendanceModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ function AttendanceModal({
useEffect(() => {
// Mark checkboxes with attendanceStudents {user.id}
if (attendanceTaken?.attendanceStudents) {
let checkedStudents = attendanceTaken?.attendanceStudents.map((student) => String(student.user.id));
// If user is currently changing something prioritize the changes instead of data coming from db
const studentsBeforeRefresh = JSON.parse(localStorage.getItem('students_checked_status')) || [];
//if user have not edited anything at all, use the data from the db
if (studentsBeforeRefresh?.length > 0) checkedStudents = studentsBeforeRefresh;
const checkedStudents = attendanceTaken?.attendanceStudents.map((student) => String(student.user.id));

setChecked(checkedStudents);
if (autoSelect) {
Expand Down Expand Up @@ -219,19 +215,6 @@ function AttendanceModal({
}
}, [attendanceList, students, currModuleData, day]);

useEffect(() => {
// if user is currently editing save the changes until it closes the modal
const currentChecked = students?.filter((item) => checked.includes(String(item.user.id))).map((item) => String(item.user.id));
localStorage.setItem('students_checked_status', JSON.stringify(currentChecked));
}, [checked]);

useEffect(() => {
// if user change day or module, discart changes
localStorage.clear('students_checked_id', JSON.stringify(checked));
}, [currModuleData, day]);

console.log(JSON.parse(localStorage.getItem('students_checked_status')) || []);

return (
<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
Expand Down
7 changes: 4 additions & 3 deletions src/common/components/LiveEvent/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,16 @@ function LiveEvent({

useEffect(() => {
let intervalVar;
// applyFilters();
updateTimes();

setTimeout(() => {
const timeoutId = setTimeout(() => {
updateTimes();
intervalVar = setInterval(updateTimes(), 60 * 1000);
intervalVar = setInterval(updateTimes, 60 * 1000);
}, secondsToNextMinute * 1000);

return () => {
clearInterval(intervalVar);
clearTimeout(timeoutId);
};
}, [mainClasses, otherEvents]);

Expand Down
11 changes: 0 additions & 11 deletions src/pages/cohort/[cohortSlug]/[slug]/[version]/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
includesToLowerCase,
getStorageItem,
sortToNearestTodayDate,
syncInterval,
getBrowserSize,
calculateDifferenceDays,
adjustNumberBeetwenMinMax,
Expand Down Expand Up @@ -266,16 +265,6 @@ function Dashboard() {
},
});
});
syncInterval(() => {
setLiveClasses((prev) => {
const validatedEventList = prev?.length > 0
? prev?.filter((l) => isValidDate(l?.starting_at) && isValidDate(l?.ending_at))
: [];
const sortDateToLiveClass = sortToNearestTodayDate(validatedEventList, TwelveHours);
const existentLiveClasses = sortDateToLiveClass?.filter((l) => l?.hash && l?.starting_at && l?.ending_at);
return existentLiveClasses;
});
});
}, []);

// Fetch cohort data with pathName structure
Expand Down

0 comments on commit b6f1c38

Please sign in to comment.