Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
[MM-17353] Wait for transition on RHS before rendering expensive sub …
Browse files Browse the repository at this point in the history
…components (#3594)

* [MM-17353] Wait for transition on RHS before rendering expensive sub components

* Style fix

* Fixed an issue on resize when the RHS is open
  • Loading branch information
devinbinnie committed Sep 6, 2019
1 parent b6493e5 commit 18bffc5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion components/search_results/search_results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default class SearchResults extends React.Component {
channelDisplayName: PropTypes.string.isRequired,
dataRetentionEnableMessageDeletion: PropTypes.bool.isRequired,
dataRetentionMessageRetentionDays: PropTypes.string,
isOpened: PropTypes.bool,
actions: PropTypes.shape({
getMorePostsForSearch: PropTypes.func.isRequired,
}),
Expand Down Expand Up @@ -181,7 +182,8 @@ export default class SearchResults extends React.Component {
if (
this.props.isSearchingTerm ||
this.props.isSearchingFlaggedPost ||
this.props.isSearchingPinnedPost
this.props.isSearchingPinnedPost ||
!this.props.isOpened
) {
ctls = (
<div className='sidebar--right__subheader'>
Expand Down
44 changes: 44 additions & 0 deletions components/sidebar_right/sidebar_right.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ export default class SidebarRight extends React.PureComponent {
}),
};

constructor(props) {
super(props);

this.sidebarRight = React.createRef();
this.state = {
isOpened: false,
};
}

componentDidMount() {
window.addEventListener('resize', this.determineTransition);
this.determineTransition();
}

componentWillUnmount() {
window.removeEventListener('resize', this.determineTransition);
if (this.sidebarRight.current) {
this.sidebarRight.current.removeEventListener('transitionend', this.onFinishTransition);
}
}

componentDidUpdate(prevProps) {
const wasOpen = prevProps.searchVisible || prevProps.postRightVisible;
const isOpen = this.props.searchVisible || this.props.postRightVisible;
Expand All @@ -55,6 +76,27 @@ export default class SidebarRight extends React.PureComponent {
}
}

determineTransition = () => {
const transitionInfo = window.getComputedStyle(this.sidebarRight.current).getPropertyValue('transition');
const hasTransition = transitionInfo !== 'all 0s ease 0s';

if (this.sidebarRight.current && hasTransition) {
this.setState({isOpened: this.props.isOpen});
this.sidebarRight.current.addEventListener('transitionend', this.onFinishTransition);
} else {
this.setState({isOpened: true});
if (this.sidebarRight.current) {
this.sidebarRight.current.removeEventListener('transitionend', this.onFinishTransition);
}
}
}

onFinishTransition = (e) => {
if (e.propertyName === 'transform') {
this.setState({isOpened: this.props.isOpen});
}
}

onShrink = () => {
this.props.actions.setRhsExpanded(false);
};
Expand Down Expand Up @@ -105,6 +147,7 @@ export default class SidebarRight extends React.PureComponent {
toggleSize={this.toggleSize}
shrink={this.onShrink}
channelDisplayName={channelDisplayName}
isOpened={this.state.isOpened}
/>
</div>
);
Expand Down Expand Up @@ -145,6 +188,7 @@ export default class SidebarRight extends React.PureComponent {
<div
className={classNames('sidebar--right', expandedClass, {'move--left': this.props.isOpen})}
id='sidebar-right'
ref={this.sidebarRight}
>
<div
onClick={this.onShrink}
Expand Down

0 comments on commit 18bffc5

Please sign in to comment.