Skip to content

Commit

Permalink
feat: display search on course filter
Browse files Browse the repository at this point in the history
  • Loading branch information
01001110J committed Nov 29, 2024
1 parent 6248444 commit abc4e7d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/features/Courses/CoursesFilters/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ const CoursesFilters = () => {
const [courseOptions, setCourseOptions] = useState([]);
const [courseSelected, setCourseSelected] = useState(null);
const [inputCourse, setInputCourse] = useState('');
const [defaultOption, setDefaultOption] = useState(allResultsOption);

const filterOptions = (option, input) => {
if (input) {
return option.label.toLowerCase().includes(input) || option.value === allResultsOption.value;
return option.label.toLowerCase().includes(input) || option.value === defaultOption.value;
}
return true;
};

const handleInputChange = (value, { action }) => {
if (action === 'input-change') {
setInputCourse(value);
setDefaultOption({
...defaultOption,
label: `${allResultsOption.label} for ${value}`,
});
}
};

Expand All @@ -46,19 +51,20 @@ const CoursesFilters = () => {
}))
: [];

setCourseOptions([allResultsOption, ...options]);
}, [courses]);
setCourseOptions([defaultOption, ...options]);
}, [courses, defaultOption]);

useEffect(() => {
if (Object.keys(selectedInstitution).length > 0) {
const params = {};

if (courseSelected) {
params.course_name = courseSelected.value === allResultsOption.value
params.course_name = courseSelected.value === defaultOption.value
? inputCourse : courseSelected.value;
}
dispatch(fetchCoursesData(selectedInstitution.id, initialPage, params));
setInputCourse('');
setDefaultOption(allResultsOption);
dispatch(updateFilters(params));
dispatch(updateCurrentPage(initialPage));
}
Expand Down

0 comments on commit abc4e7d

Please sign in to comment.