Unverified Commit a023e005 authored by Gautier D's avatar Gautier D Committed by Florent Chehab
Browse files

refacto(frontend): removing city api call

parent 820a7491
...@@ -64,7 +64,7 @@ class CampusViewSet(BaseModelViewSet): ...@@ -64,7 +64,7 @@ class CampusViewSet(BaseModelViewSet):
permission_classes = (ReadOnly,) permission_classes = (ReadOnly,)
queryset = Campus.objects.all() # pylint: disable=E1101 queryset = Campus.objects.all() # pylint: disable=E1101
serializer_class = CampusSerializer serializer_class = CampusSerializer
end_point_route = "campuses" end_point_route = "campuses-deprecated"
class MainCampusViewSet(BaseModelViewSet): class MainCampusViewSet(BaseModelViewSet):
......
...@@ -39,4 +39,4 @@ class CityViewSet(BaseModelViewSet): ...@@ -39,4 +39,4 @@ class CityViewSet(BaseModelViewSet):
queryset = City.objects.all() # pylint: disable=E1101 queryset = City.objects.all() # pylint: disable=E1101
serializer_class = CitySerializer serializer_class = CitySerializer
permission_classes = (ReadOnly,) permission_classes = (ReadOnly,)
end_point_route = "cities" end_point_route = "cities-deprecated"
...@@ -25,7 +25,7 @@ import PageAboutUnlinkedPartners from "../pages/PageAboutUnlinkedPartners"; ...@@ -25,7 +25,7 @@ import PageAboutUnlinkedPartners from "../pages/PageAboutUnlinkedPartners";
import PageLogout from "../pages/PageLogout"; import PageLogout from "../pages/PageLogout";
import withNetworkWrapper, { NetWrapParam } from "../../hoc/withNetworkWrapper"; import withNetworkWrapper, { NetWrapParam } from "../../hoc/withNetworkWrapper";
import UniversityService from "../../services/data/UniversityService"; import UniversityService from "../../services/data/UniversityService";
import CityService from "../../services/data/CityService"; // import CityService from "../../services/data/CityService";
import CountryService from "../../services/data/CountryService"; import CountryService from "../../services/data/CountryService";
import CurrencyService from "../../services/data/CurrencyService"; import CurrencyService from "../../services/data/CurrencyService";
import LanguageService from "../../services/data/LanguageService"; import LanguageService from "../../services/data/LanguageService";
...@@ -34,7 +34,7 @@ import useOnBeforeComponentMount from "../../hooks/useOnBeforeComponentMount"; ...@@ -34,7 +34,7 @@ import useOnBeforeComponentMount from "../../hooks/useOnBeforeComponentMount";
const SERVICES_TO_INITIALIZE = [ const SERVICES_TO_INITIALIZE = [
UniversityService, UniversityService,
CityService, // CityService,
CountryService, CountryService,
CurrencyService, CurrencyService,
LanguageService, LanguageService,
...@@ -104,9 +104,9 @@ App.propTypes = {}; ...@@ -104,9 +104,9 @@ App.propTypes = {};
export default compose( export default compose(
withNetworkWrapper([ withNetworkWrapper([
new NetWrapParam("countries", "all"), new NetWrapParam("countries", "all"),
new NetWrapParam("cities", "all"), //new NetWrapParam("cities", "all"),
new NetWrapParam("universities", "all"), new NetWrapParam("universities", "all"),
new NetWrapParam("mainCampuses", "all"), //new NetWrapParam("mainCampuses", "all"),
new NetWrapParam("currencies", "all"), new NetWrapParam("currencies", "all"),
new NetWrapParam("languages", "all"), new NetWrapParam("languages", "all"),
new NetWrapParam("serverModerationStatus", "all") // not needed for server moderation status new NetWrapParam("serverModerationStatus", "all") // not needed for server moderation status
......
...@@ -50,7 +50,6 @@ const ALL_MAPS = {}; ...@@ -50,7 +50,6 @@ const ALL_MAPS = {};
* If an id is provided, the state of the map will be automatically saved and regenerated. * If an id is provided, the state of the map will be automatically saved and regenerated.
*/ */
function BaseMap({ id, universities }) { function BaseMap({ id, universities }) {
console.log("iciciciiojoij", universities);
const theme = useTheme(); const theme = useTheme();
const classes = useStyles(); const classes = useStyles();
......
...@@ -5,6 +5,7 @@ import BaseMap from "./BaseMap"; ...@@ -5,6 +5,7 @@ import BaseMap from "./BaseMap";
import "./map.scss"; import "./map.scss";
import UniversityService from "../../services/data/UniversityService"; import UniversityService from "../../services/data/UniversityService";
import CountryService from "../../services/data/CountryService";
import { useSelectedUniversities } from "../../hooks/wrappers/useSelectedUniversities"; import { useSelectedUniversities } from "../../hooks/wrappers/useSelectedUniversities";
const MAIN_MAP_ID = uuid(); const MAIN_MAP_ID = uuid();
...@@ -27,7 +28,7 @@ function MainMap() { ...@@ -27,7 +28,7 @@ function MainMap() {
univName: univ.name, univName: univ.name,
univLogoUrl: univ.logo, univLogoUrl: univ.logo,
cityName: univ.city, cityName: univ.city,
countryName: univ.country, countryName: CountryService.getCountryForCountryId(univ.country).name,
main_campus_lat: parseFloat(univ.main_campus_lat), main_campus_lat: parseFloat(univ.main_campus_lat),
main_campus_lon: parseFloat(univ.main_campus_lon), main_campus_lon: parseFloat(univ.main_campus_lon),
univId: univ.id, univId: univ.id,
......
...@@ -2,6 +2,7 @@ import React from "react"; ...@@ -2,6 +2,7 @@ import React from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import UnivContext from "../../contexts/UnivContext"; import UnivContext from "../../contexts/UnivContext";
import UniversityService from "../../services/data/UniversityService"; import UniversityService from "../../services/data/UniversityService";
import CountryService from "../../services/data/CountryService";
/** /**
* Univ info provider to pre-fetch some data and make it available down the tree very easily * Univ info provider to pre-fetch some data and make it available down the tree very easily
...@@ -9,21 +10,18 @@ import UniversityService from "../../services/data/UniversityService"; ...@@ -9,21 +10,18 @@ import UniversityService from "../../services/data/UniversityService";
function UnivInfoProvider({ univId, children }) { function UnivInfoProvider({ univId, children }) {
const univIdParsed = parseInt(univId, 10); const univIdParsed = parseInt(univId, 10);
const univ = UniversityService.getUniversityById(univIdParsed); const univ = UniversityService.getUniversityById(univIdParsed);
const { city, country } = UniversityService.getUnivCityAndCountry( const country = CountryService.getCountryForCountryId(univ.country)
univIdParsed const city = univ.city
);
const countryId = country.id; const countryId = country.id;
const cityId = city.id;
return ( return (
<UnivContext.Provider <UnivContext.Provider
value={{ value ={{
univId: univIdParsed, univId: univIdParsed,
countryId, countryId,
univ, univ,
cityId, city,
city, country
country
}} }}
> >
{children} {children}
......
...@@ -79,7 +79,7 @@ CoreComponent.propTypes = { ...@@ -79,7 +79,7 @@ CoreComponent.propTypes = {
}).isRequired }).isRequired
}; };
function UniversityGeneral({ university, city, country }) { function UniversityGeneral({ university, country, city }) {
return ( return (
<ModuleWrapper <ModuleWrapper
buildTitle={() => "Présentation"} buildTitle={() => "Présentation"}
...@@ -88,7 +88,7 @@ function UniversityGeneral({ university, city, country }) { ...@@ -88,7 +88,7 @@ function UniversityGeneral({ university, city, country }) {
CoreComponent={props => ( CoreComponent={props => (
<CoreComponent <CoreComponent
{...props} {...props}
cityName={city.name} cityName={city}
countryName={country.name} countryName={country.name}
/> />
)} )}
...@@ -97,7 +97,7 @@ function UniversityGeneral({ university, city, country }) { ...@@ -97,7 +97,7 @@ function UniversityGeneral({ university, city, country }) {
} }
UniversityGeneral.propTypes = { UniversityGeneral.propTypes = {
city: PropTypes.object.isRequired, city: PropTypes.string.isRequired,
country: PropTypes.object.isRequired, country: PropTypes.object.isRequired,
university: PropTypes.object.isRequired university: PropTypes.object.isRequired
}; };
......
...@@ -20,7 +20,7 @@ class FilterService { ...@@ -20,7 +20,7 @@ class FilterService {
universities.forEach(univ => { universities.forEach(univ => {
this._universitiesCountriesCache.set( this._universitiesCountriesCache.set(
univ.id, univ.id,
UniversityService.getUnivCityAndCountry(univ.id).country CountryService.getCountryForCountryId(univ.country)
); );
}); });
......
import arrayOfInstancesToMap from "../../utils/arrayOfInstancesToMap"; // import arrayOfInstancesToMap from "../../utils/arrayOfInstancesToMap";
import { getLatestApiReadData } from "../../hooks/useGlobalState"; // import { getLatestApiReadData } from "../../hooks/useGlobalState";
class CityService { // class CityService {
/** // /**
* Stores the cities by its id // * Stores the cities by its id
* @type {Map<number, object>} // * @type {Map<number, object>}
* @private // * @private
*/ // */
_citiesById = new Map(); // _citiesById = new Map();
/** // /**
* Must be called once before accessing other methods. // * Must be called once before accessing other methods.
*/ // */
initialize() { // initialize() {
const cities = this.getCities(); // const cities = this.getCities();
this._citiesById = arrayOfInstancesToMap(cities); // this._citiesById = arrayOfInstancesToMap(cities);
} // }
/** // /**
* Get the city object for a city id // * Get the city object for a city id
* // *
* @param {number} cityId // * @param {number} cityId
* @returns {Object} // * @returns {Object}
*/ // */
getCityForCityId(cityId) { // getCityForCityId(cityId) {
return this._citiesById.get(cityId); // return this._citiesById.get(cityId);
} // }
getCities() { // getCities() {
return getLatestApiReadData("cities-all"); // return getLatestApiReadData("cities-all");
} // }
} // }
export default new CityService(); // export default new CityService();
import CityService from "./CityService"; // import CityService from "./CityService";
import CountryService from "./CountryService"; // import CountryService from "./CountryService";
import arrayOfInstancesToMap from "../../utils/arrayOfInstancesToMap"; import arrayOfInstancesToMap from "../../utils/arrayOfInstancesToMap";
import { getLatestApiReadData } from "../../hooks/useGlobalState"; import { getLatestApiReadData } from "../../hooks/useGlobalState";
...@@ -11,12 +11,7 @@ class UniversityService { ...@@ -11,12 +11,7 @@ class UniversityService {
*/ */
_universitiesById = new Map(); _universitiesById = new Map();
/**
* Stores the mainCampuses by university id for quick join
* @type {Map<number, object>}
* @private
*/
_mainCampusesByUnivId = new Map();
/** /**
* @private * @private
...@@ -31,12 +26,6 @@ class UniversityService { ...@@ -31,12 +26,6 @@ class UniversityService {
const universities = this.getUniversities(); const universities = this.getUniversities();
this._universitiesById = arrayOfInstancesToMap(universities); this._universitiesById = arrayOfInstancesToMap(universities);
const mainCampuses = this.getMainCampuses();
mainCampuses.forEach(campus => {
this._mainCampusesByUnivId.set(campus.university, campus);
});
this._options = universities.map(el => ({ this._options = universities.map(el => ({
value: el.id, value: el.id,
label: el.name, label: el.name,
...@@ -56,14 +45,6 @@ class UniversityService { ...@@ -56,14 +45,6 @@ class UniversityService {
return this._options; return this._options;
} }
/**
* Get the full list of main campuses in the app
* @returns {array<Object>}
*/
getMainCampuses() {
return getLatestApiReadData("mainCampuses-all");
}
/** /**
* @param {number} univId * @param {number} univId
* @returns {Object} * @returns {Object}
...@@ -81,33 +62,6 @@ class UniversityService { ...@@ -81,33 +62,6 @@ class UniversityService {
return this._universitiesById.has(univId); return this._universitiesById.has(univId);
} }
/**
* Get the campus object associated with the university given its id.
*
* @param {number} univId
* @returns {Object}
*/
getCampusForUnivId(univId) {
return this._mainCampusesByUnivId.get(univId);
}
/**
* Function to get the city and the country of a university given a university id
*
* @param {number} univId
* @returns {object} Object with city and country instance of the university (main campus)
*/
getUnivCityAndCountry(univId) {
const univ = this.getUniversityById(univId);
const city = univ.city;
const country = univ.country;
return {
city,
country
};
}
/** /**
* *
* @param {number} univId * @param {number} univId
......
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