Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in filtering students #31

Merged
merged 1 commit into from
Mar 16, 2023
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
5 changes: 3 additions & 2 deletions src/components/CoursePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ const CourseForm = () => {

//update database
const course = id; //"CS 35L – Software Construction Lab";
console.log(filterUsers(checkValues.years, checkValues.interests, course));
// console.log(filterUsers(checkValues.years, checkValues.interests, course));

const promise = filterUsers(
checkValues.years,
checkValues.interests,
course
course,
allStudentsInCourse
);
promise.then((value) => {
setStudents(value);
Expand Down
9 changes: 7 additions & 2 deletions src/components/utils/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,17 @@ export const getUserDataFromName = async (id) => {
};

const dbRef = collection(db, "ProfileFormData");
export const filterUsers = async (filterYear, filterInterests, filterCourse) => {
export const filterUsers = async (filterYear, filterInterests, filterCourse, studentsInCourse) => {
let iList = [];
let cList = [];
let yList = [];
let retList = [];

console.log("students in course", studentsInCourse);
if (studentsInCourse.length === 0) {
console.log("no students in this course, returning early");
alert("Cannot filter students in an empty class");
return;
}
if (filterCourse.length !== 0) {
const c = query(dbRef, where("courses", "array-contains", filterCourse) );

Expand Down