Commit 8583ed58 authored by Florent Chehab's avatar Florent Chehab

Visible tweaks

parent d199d7ab
...@@ -31,18 +31,19 @@ class MyComponent extends Component { ...@@ -31,18 +31,19 @@ class MyComponent extends Component {
myComponentDidMount() { }; myComponentDidMount() { };
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
if (this.nextProps && typeof this.nextProps.visible != 'undefined' && !this.nextProps.visible) { // Below is buggy with redux connect
// don't rerender components that won't be visible. // if (this.nextProps && typeof this.nextProps.visible != 'undefined' && !this.nextProps.visible) {
return false; // // 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 // if (this.props.visible === false && !this.nextProps) {
return false; // // 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;
// } // }
// // if (this.nextProps && typeof this.nextProps.visible != 'undefined' && this.nextProps.visible) {
// // // render if nextprops should be visible
// // return true;
// // }
return this.myShouldComponentUpdate(nextProps, nextState); return this.myShouldComponentUpdate(nextProps, nextState);
} }
myShouldComponentUpdate(nextProps, nextState) { return true; } myShouldComponentUpdate(nextProps, nextState) { return true; }
......
import React from 'react';
const VisibilityContext = React.createContext();
export default VisibilityContext;
\ No newline at end of file
...@@ -24,15 +24,19 @@ import PreviousDeparturesTab from './tabs/PreviousDeparturesTab'; ...@@ -24,15 +24,19 @@ import PreviousDeparturesTab from './tabs/PreviousDeparturesTab';
import ScholarshipsTab from './tabs/ScholarshipsTab'; import ScholarshipsTab from './tabs/ScholarshipsTab';
import MoreTab from './tabs/MoreTab'; import MoreTab from './tabs/MoreTab';
import VisibilityContext from '../shared/VisibilityContext';
function TabContainer(props) { function TabContainer(props) {
let style = { padding: 8 * 3 }; let style = { padding: 8 * 3 };
if (props.visible === false) { if (props.visible === false) {
style = { display: 'none' } style = { display: 'none' }
} }
return ( return (
<Typography component="div" style={style}> <VisibilityContext.Provider value={props.visible}>
{props.children} <Typography component="div" style={style}>
</Typography> {props.children}
</Typography>
</VisibilityContext.Provider>
); );
} }
......
...@@ -2,7 +2,7 @@ import React from 'react'; ...@@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import __pick from 'lodash/pick'; import __pick from 'lodash/pick';
import UnivContext from '../../shared/UnivContext'; import UnivContext from '../../shared/UnivContext';
import VisibilityContext from '../../shared/VisibilityContext';
class UnivInfoConsumer extends React.PureComponent { class UnivInfoConsumer extends React.PureComponent {
render() { render() {
...@@ -11,7 +11,15 @@ class UnivInfoConsumer extends React.PureComponent { ...@@ -11,7 +11,15 @@ class UnivInfoConsumer extends React.PureComponent {
<UnivContext.Consumer> <UnivContext.Consumer>
{ {
value => ( value => (
// <VisibilityContext.Consumer>
// {
// visible => (
// <this.props.renderAndAddPropsTo {...__pick(value, add)} univId={value.univId} visible={visible} />
// )
// }
// </VisibilityContext.Consumer>
<this.props.renderAndAddPropsTo {...__pick(value, add)} univId={value.univId} /> <this.props.renderAndAddPropsTo {...__pick(value, add)} univId={value.univId} />
) )
} }
</UnivContext.Consumer> </UnivContext.Consumer>
......
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