Commit c05e3ccb authored by Imane Misrar's avatar Imane Misrar
Browse files

refacto(Filter.jsx/FilterService.js) : onlyOpenDestinations is checked if...

refacto(Filter.jsx/FilterService.js) : onlyOpenDestinations is checked if there are enough open destinations

Closes #148
parent 9ac5aa74
......@@ -38,6 +38,7 @@ const useStyles = makeStyles(theme => ({
const DOWNSHIFT_COUNTRIES_ID = uuid();
const DOWNSHIFT_SEMESTERS_ID = uuid();
const DOWNSHIFT_MAJORS_ID = uuid();
const MINIMUM_NUMBER_OPEN_DESTINATIONS = 100;
/**
* Implementation of a filter component
......@@ -52,14 +53,18 @@ function Filter() {
"filter-semesters",
[...FilterService.defaultSemesters].reverse()
);
const [majorMinors, setMajorMinors] = useGlobalState(
"filter-major-minors",
[]
);
const enoughDestinationsAreOpen =
FilterService.destinationOpenCount >= MINIMUM_NUMBER_OPEN_DESTINATIONS;
const [onlyOpenDestinations, setOnlyOpenDestinations] = useGlobalState(
"filter-only-open-destinations",
false
enoughDestinationsAreOpen
);
useEffect(() => {
......
......@@ -14,6 +14,8 @@ class FilterService {
_majorMinorOptions = undefined;
_destinationOpenCount = 0;
initialize() {
const universities = UniversityService.getUniversities();
......@@ -46,6 +48,10 @@ class FilterService {
value: el,
label: el
}));
this._destinationOpenCount = universities.filter(
u => u.denormalized_infos.is_destination_open === true
).length;
}
get universityIdsCountries() {
......@@ -74,6 +80,13 @@ class FilterService {
return this._defaultSemesters;
}
/**
* @return {number}
*/
get _destinationOpenCount() {
return this._destinationOpenCount;
}
getMajorInUniv(univObj) {
return [
...new Set(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment