Skip to content

Commit fd7e811

Browse files
author
Luke Barnard
committed
Less coupling between HeaderButton and RightPanel
Use isHighlighted as a prop instead of computing based on phases and currentPhase
1 parent 28e9fdc commit fd7e811

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

‎src/components/structures/RightPanel.js‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class HeaderButton extends React.Component {
4444
render() {
4545
const TintableSvg = sdk.getComponent("elements.TintableSvg");
4646
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");
47-
const isHighlighted = this.props.phases.includes(this.props.currentPhase);
4847

4948
return <AccessibleButton
5049
className="mx_RightPanel_headerButton"
@@ -55,16 +54,14 @@ class HeaderButton extends React.Component {
5554
{ this.props.badge ? this.props.badge : <span>&nbsp;</span>}
5655
</div>
5756
<TintableSvg src={this.props.iconSrc} width="25" height="25"/>
58-
{ isHighlighted ? <div className="mx_RightPanel_headerButton_highlight"></div> : <div/> }
57+
{ this.props.isHighlighted ? <div className="mx_RightPanel_headerButton_highlight"></div> : <div/> }
5958
</AccessibleButton>;
6059
}
6160
}
6261

6362
HeaderButton.propTypes = {
64-
// If currentPhase is one of the specified phases, the button will be highlighted
65-
phases: PropTypes.arrayOf(PropTypes.string).isRequired,
66-
// The currentPhase of the RightPanel
67-
currentPhase: PropTypes.string.isRequired,
63+
// Whether this button is highlighted
64+
isHighlighted: PropTypes.bool.isRequired,
6865
// The phase to swap to when the button is clicked
6966
clickPhase: PropTypes.string.isRequired,
7067
// The source file of the icon to display
@@ -243,22 +240,18 @@ module.exports = React.createClass({
243240
if (this.props.roomId) {
244241
headerButtons = [
245242
<HeaderButton key="_membersButton" title={_t('Members')} iconSrc="img/icons-people.svg"
246-
phases={[this.Phase.RoomMemberList, this.Phase.RoomMemberInfo]}
243+
isHighlighted={[this.Phase.RoomMemberList, this.Phase.RoomMemberInfo].includes(this.state.phase)}
247244
clickPhase={this.Phase.RoomMemberList}
248-
currentPhase={this.state.phase}
249245
badge={membersBadge}
250246
analytics={['Right Panel', 'Member List Button', 'click']}
251247
/>,
252248
<HeaderButton key="_filesButton" title={_t('Files')} iconSrc="img/icons-files.svg"
253-
phases={[this.Phase.FilePanel]}
254-
clickPhase={this.Phase.FilePanel}
255-
currentPhase={this.state.phase}
249+
isHighlighted={this.state.phase === this.Phase.FilePanel}
256250
analytics={['Right Panel', 'File List Button', 'click']}
257251
/>,
258252
<HeaderButton key="_notifsButton" title={_t('Notifications')} iconSrc="img/icons-notifications.svg"
259-
phases={[this.Phase.NotificationPanel]}
253+
isHighlighted={this.state.phase === this.Phase.NotificationPanel}
260254
clickPhase={this.Phase.NotificationPanel}
261-
currentPhase={this.state.phase}
262255
analytics={['Right Panel', 'Notification List Button', 'click']}
263256
/>,
264257
];

0 commit comments

Comments
 (0)