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 => ({ ...@@ -38,6 +38,7 @@ const useStyles = makeStyles(theme => ({
const DOWNSHIFT_COUNTRIES_ID = uuid(); const DOWNSHIFT_COUNTRIES_ID = uuid();
const DOWNSHIFT_SEMESTERS_ID = uuid(); const DOWNSHIFT_SEMESTERS_ID = uuid();
const DOWNSHIFT_MAJORS_ID = uuid(); const DOWNSHIFT_MAJORS_ID = uuid();
const MINIMUM_NUMBER_OPEN_DESTINATIONS = 100;
/** /**
* Implementation of a filter component * Implementation of a filter component
...@@ -52,14 +53,18 @@ function Filter() { ...@@ -52,14 +53,18 @@ function Filter() {
"filter-semesters", "filter-semesters",
[...FilterService.defaultSemesters].reverse() [...FilterService.defaultSemesters].reverse()
); );
const [majorMinors, setMajorMinors] = useGlobalState( const [majorMinors, setMajorMinors] = useGlobalState(
"filter-major-minors", "filter-major-minors",
[] []
); );
const enoughDestinationsAreOpen =
FilterService.destinationOpenCount >= MINIMUM_NUMBER_OPEN_DESTINATIONS;
const [onlyOpenDestinations, setOnlyOpenDestinations] = useGlobalState( const [onlyOpenDestinations, setOnlyOpenDestinations] = useGlobalState(
"filter-only-open-destinations", "filter-only-open-destinations",
false enoughDestinationsAreOpen
); );
useEffect(() => { useEffect(() => {
......
...@@ -14,6 +14,8 @@ class FilterService { ...@@ -14,6 +14,8 @@ class FilterService {
_majorMinorOptions = undefined; _majorMinorOptions = undefined;
_destinationOpenCount = 0;
initialize() { initialize() {
const universities = UniversityService.getUniversities(); const universities = UniversityService.getUniversities();
...@@ -46,6 +48,10 @@ class FilterService { ...@@ -46,6 +48,10 @@ class FilterService {
value: el, value: el,
label: el label: el
})); }));
this._destinationOpenCount = universities.filter(
u => u.denormalized_infos.is_destination_open === true
).length;
} }
get universityIdsCountries() { get universityIdsCountries() {
...@@ -74,6 +80,13 @@ class FilterService { ...@@ -74,6 +80,13 @@ class FilterService {
return this._defaultSemesters; return this._defaultSemesters;
} }
/**
* @return {number}
*/
get _destinationOpenCount() {
return this._destinationOpenCount;
}
getMajorInUniv(univObj) { getMajorInUniv(univObj) {
return [ return [
...new Set( ...new Set(
......
Supports Markdown
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