Commit 5c580b14 authored by Florent Chehab's avatar Florent Chehab

Removed custom... from frontend, use of super instead

parent 75bbbf1b
Pipeline #35534 passed with stages
in 6 minutes and 45 seconds
......@@ -4505,12 +4505,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
......@@ -4531,12 +4533,14 @@
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
......@@ -4653,7 +4657,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"ini": {
"version": "1.3.5",
......@@ -4680,6 +4685,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
......@@ -4693,6 +4699,7 @@
"version": "2.2.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
......@@ -4804,6 +4811,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
......@@ -4925,6 +4933,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
......@@ -5675,7 +5684,6 @@
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
......@@ -5690,8 +5698,7 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
......@@ -5702,8 +5709,7 @@
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
......@@ -5820,8 +5826,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
......@@ -5833,7 +5838,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
......@@ -5848,7 +5852,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
......@@ -5856,14 +5859,12 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
......@@ -5882,7 +5883,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
......@@ -5963,8 +5963,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"object-assign": {
"version": "4.1.1",
......@@ -5976,7 +5975,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
......@@ -6098,7 +6096,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
......
......@@ -34,40 +34,17 @@ class CustomComponentForAPI extends Component {
/////
componentDidMount() {
this.readPropsIfNeeded();
this.customComponentDidMount();
this.forceUpdate(); // bug otherwise
}
customComponentDidMount() { }
shouldComponentUpdate(nextProps, nextState) {
// Below is buggy with redux connect
// if (this.nextProps && typeof this.nextProps.visible != 'undefined' && !this.nextProps.visible) {
// // don't rerender components that won't be visible.
// return false;
// }
// if (this.props.visible === false && !this.nextProps) {
// // don't rerender components if it is still not visible
// return false;
// }
// // if (this.nextProps && typeof this.nextProps.visible != 'undefined' && this.nextProps.visible) {
// // // render if nextprops should be visible
// // return true;
// // }
return this.customShouldComponentUpdate(nextProps, nextState);
}
// eslint-disable-next-line no-unused-vars
customShouldComponentUpdate(nextProps, nextState) { return true; }
// eslint-disable-next-line no-unused-vars
componentDidUpdate(prevProps, prevState, snapshot) {
// TODO add expire date
// extends the default behavior of react to load props (api related) if needed on update.
this.readPropsIfNeeded();
this.customComponentDidUpdate(prevProps, prevState, snapshot);
}
customComponentDidUpdate() { }
// Override of the default render behaviour to wait for data to arrive.
render() {
// Override of the default react render behavior to wait for data to arrive.
// You should use `customRender` instead of `render` in your components.
if (this.checkPropsFailed()) {
return <p>Une erreur est survenue lors du téléchargement des données. Merci de recharger la page et si l'erreur persiste, merci de contacter les administrateurs du site.</p>;
}
......@@ -79,6 +56,15 @@ class CustomComponentForAPI extends Component {
return this.customRender();
}
/**
* Function to use instead of `render`.
*
* @memberof CustomComponentForAPI
*/
customRender() {
// eslint-disable-next-line no-console
console.error("Dev: you forget to define the `customRender` function that is used when rendering within a subClass of CustomComponentForAPI");
}
// End of react functions override
......@@ -270,7 +256,7 @@ class CustomComponentForAPI extends Component {
/**
* Funciton to get the city and the country of a university given a university id
* 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)
......@@ -299,7 +285,7 @@ class CustomComponentForAPI extends Component {
}
CustomComponentForAPI.propTypes = {
api: PropTypes.object
api: PropTypes.object.isRequired
};
export default CustomComponentForAPI;
......@@ -23,7 +23,9 @@ import { saveAppTheme } from "../actions/theme";
class ThemeProvider extends CustomComponentForAPI {
state = { theme: this.props.themeSavedInTheApp.theme };
customComponentDidUpdate() {
componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
if (!this.allApiDataIsReady()) {
return;
}
......
......@@ -42,9 +42,10 @@ class UnivMap extends CustomComponentForAPI {
this.updateDimensions();
}
customComponentDidMount() {
componentDidMount() {
// add an event listener to resize the map when needed
window.addEventListener("resize", this.updateDimensions.bind(this));
super.componentDidMount();
}
componentWillUnmount() {
......
......@@ -33,7 +33,9 @@ import {
*/
class PageUniversity extends CustomComponentForAPI {
customComponentDidUpdate() {
componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
if (this.props.universities.readSucceeded.readAt) {
// we have the university data
const universities = this.getReadData("universities"),
......
......@@ -66,7 +66,9 @@ class ColorTool extends CustomComponentForAPI {
}
customComponentDidUpdate() {
componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
if (!this.allApiDataIsReady()) {
return;
}
......
......@@ -136,7 +136,9 @@ class Editor extends CustomComponentForAPI {
}
}
customComponentDidUpdate() {
componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
// usefull for handling moderation
const { dataToSave } = this.props;
if (dataToSave) {
......
......@@ -8,7 +8,9 @@ class Module extends CustomComponentForAPI {
this.props.invalidateData(true);
}
customComponentDidUpdate() {
componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
this.getListPropsNeedRead()
.forEach(propName => this.performReadFromApi(propName));
}
......
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