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