Skip to content

Commit

Permalink
Merge pull request #659 from asuc-octo/auto-fill-course-fc
Browse files Browse the repository at this point in the history
Enable autofill for enrollment and grades
  • Loading branch information
xyntechx authored Dec 1, 2023
2 parents b14c40f + d0aeb72 commit 70b3479
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
15 changes: 13 additions & 2 deletions frontend/src/components/ClassSearchBar/EnrollmentSearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ export default function EnrollmentSearchBar({
fromCatalog
}) {
const [selectedClass, setSelectedClass] = useState(0);
const { sections, selectPrimary, selectSecondary } = useSelector((state) => state.enrollment);
const { sections, selectPrimary, selectSecondary, selectedCourses } = useSelector(
(state) => state.enrollment
);
const [localSelectPrimary, setLocalSelectPrimary] = useState(selectPrimary);
const [localSelectSecondary, setLocalSelectSecondary] = useState(selectSecondary);
const [selectedClassVal, setSelectedClassVal] = useState(undefined);
const dispatch = useDispatch();

const handleClassSelect = useCallback(
Expand All @@ -103,6 +106,7 @@ export default function EnrollmentSearchBar({
}

setSelectedClass(updatedClass.value);
setSelectedClassVal(updatedClass);
setLocalSelectPrimary('');
setLocalSelectSecondary('');
dispatch(fetchEnrollSelected(updatedClass));
Expand All @@ -117,6 +121,13 @@ export default function EnrollmentSearchBar({

useEffect(() => setLocalSelectPrimary(selectPrimary), [selectPrimary]);
useEffect(() => setLocalSelectSecondary(selectSecondary), [selectSecondary]);
useEffect(() => {
if (selectedCourses && selectedCourses.length > 0) {
const course = selectedCourses[selectedCourses.length - 1];
const payload = { value: course.courseID, label: course.course, course };
handleClassSelect(payload);
}
}, [selectedCourses]);

const handlePrimarySelect = (primary) => {
setLocalSelectPrimary(primary ? primary.value : '');
Expand Down Expand Up @@ -222,7 +233,7 @@ export default function EnrollmentSearchBar({
courseSearch
name="selectClass"
placeholder="Choose a class..."
// value={selectedClass}
value={selectedClassVal}
options={buildCoursesOptions(classes)}
onChange={handleClassSelect}
components={{
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/components/ClassSearchBar/GradesSearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ const customStyles = {
};

export default function GradesSearchBar({ fromCatalog, addCourse, isFull, isMobile, classes }) {
const { sections, selectPrimary, selectSecondary } = useSelector((state) => state.grade);
const { sections, selectPrimary, selectSecondary, selectedCourses } = useSelector(
(state) => state.grade
);
const [localSelectPrimary, setLocalSelectPrimary] = useState(selectPrimary);
const [localSelectSecondary, setLocalSelectSecondary] = useState(selectSecondary);
const [selectedClassVal, setSelectedClassVal] = useState(undefined);
const [selectedClass, setSelectedClass] = useState(0);
const [selectType, setSelectType] = useState('instructor');
const dispatch = useDispatch();
Expand All @@ -168,6 +171,7 @@ export default function GradesSearchBar({ fromCatalog, addCourse, isFull, isMobi
}

setSelectedClass(updatedClass.value);
setSelectedClassVal(updatedClass);
dispatch(fetchGradeSelected(updatedClass));
},
[dispatch]
Expand All @@ -183,6 +187,13 @@ export default function GradesSearchBar({ fromCatalog, addCourse, isFull, isMobi

useEffect(() => setLocalSelectPrimary(selectPrimary), [selectPrimary]);
useEffect(() => setLocalSelectSecondary(selectSecondary), [selectSecondary]);
useEffect(() => {
if (selectedCourses && selectedCourses.length > 0) {
const course = selectedCourses[selectedCourses.length - 1];
const payload = { value: course.courseID, label: course.course, course };
handleClassSelect(payload);
}
}, [selectedCourses]);

const handleSortSelect = (sortBy) => {
setSelectType(sortBy.value);
Expand Down Expand Up @@ -301,6 +312,7 @@ export default function GradesSearchBar({ fromCatalog, addCourse, isFull, isMobi
courseSearch
name="selectClass"
placeholder="Choose a class..."
value={selectedClassVal}
options={buildCoursesOptions(classes)}
onChange={handleClassSelect}
components={{
Expand Down

0 comments on commit 70b3479

Please sign in to comment.