@@ -30,13 +30,14 @@ import VectorConferenceHandler from '../../VectorConferenceHandler';
3030var LeftPanel = React . createClass ( {
3131 displayName : 'LeftPanel' ,
3232
33+ // NB. If you add props, don't forget to update
34+ // shouldComponentUpdate!
3335 propTypes : {
3436 collapsed : React . PropTypes . bool . isRequired ,
3537 } ,
3638
3739 getInitialState : function ( ) {
3840 return {
39- showCallElement : null ,
4041 searchFilter : '' ,
4142 } ;
4243 } ,
@@ -45,26 +46,25 @@ var LeftPanel = React.createClass({
4546 this . focusedElement = null ;
4647 } ,
4748
48- componentDidMount : function ( ) {
49- this . dispatcherRef = dis . register ( this . onAction ) ;
50- } ,
51-
52- componentWillReceiveProps : function ( newProps ) {
53- this . _recheckCallElement ( newProps . selectedRoom ) ;
54- } ,
55-
56- componentWillUnmount : function ( ) {
57- dis . unregister ( this . dispatcherRef ) ;
58- } ,
49+ shouldComponentUpdate : function ( nextProps , nextState ) {
50+ // MatrixChat will update whenever the user switches
51+ // rooms, but propagating this change all the way down
52+ // the react tree is quite slow, so we cut this off
53+ // here. The RoomTiles listen for the room change
54+ // events themselves to know when to update.
55+ // We just need to update if any of these things change.
56+ if (
57+ this . props . collapsed !== nextProps . collapsed ||
58+ this . props . opacity !== nextProps . opacity
59+ ) {
60+ return true ;
61+ }
5962
60- onAction : function ( payload ) {
61- switch ( payload . action ) {
62- // listen for call state changes to prod the render method, which
63- // may hide the global CallView if the call it is tracking is dead
64- case 'call_state' :
65- this . _recheckCallElement ( this . props . selectedRoom ) ;
66- break ;
63+ if ( this . state . searchFilter !== nextState . searchFilter ) {
64+ return true ;
6765 }
66+
67+ return false ;
6868 } ,
6969
7070 _onFocus : function ( ev ) {
@@ -152,74 +152,41 @@ var LeftPanel = React.createClass({
152152 }
153153 } ,
154154
155- _recheckCallElement : function ( selectedRoomId ) {
156- // if we aren't viewing a room with an ongoing call, but there is an
157- // active call, show the call element - we need to do this to make
158- // audio/video not crap out
159- var activeCall = CallHandler . getAnyActiveCall ( ) ;
160- var callForRoom = CallHandler . getCallForRoom ( selectedRoomId ) ;
161- var showCall = ( activeCall && activeCall . call_state === 'connected' && ! callForRoom ) ;
162- this . setState ( {
163- showCallElement : showCall
164- } ) ;
165- } ,
166-
167155 onHideClick : function ( ) {
168156 dis . dispatch ( {
169157 action : 'hide_left_panel' ,
170158 } ) ;
171159 } ,
172160
173- onCallViewClick : function ( ) {
174- var call = CallHandler . getAnyActiveCall ( ) ;
175- if ( call ) {
176- dis . dispatch ( {
177- action : 'view_room' ,
178- room_id : call . groupRoomId || call . roomId ,
179- } ) ;
180- }
181- } ,
182-
183161 onSearch : function ( term ) {
184162 this . setState ( { searchFilter : term } ) ;
185163 } ,
186164
187165 render : function ( ) {
188- var RoomList = sdk . getComponent ( 'rooms.RoomList' ) ;
189- var BottomLeftMenu = sdk . getComponent ( 'structures.BottomLeftMenu' ) ;
166+ const RoomList = sdk . getComponent ( 'rooms.RoomList' ) ;
167+ const BottomLeftMenu = sdk . getComponent ( 'structures.BottomLeftMenu' ) ;
168+ const CallPreview = sdk . getComponent ( 'voip.CallPreview' ) ;
190169
191- var topBox ;
170+ let topBox ;
192171 if ( MatrixClientPeg . get ( ) . isGuest ( ) ) {
193- var LoginBox = sdk . getComponent ( 'structures.LoginBox' ) ;
172+ const LoginBox = sdk . getComponent ( 'structures.LoginBox' ) ;
194173 topBox = < LoginBox collapsed = { this . props . collapsed } /> ;
195- }
196- else {
197- var SearchBox = sdk . getComponent ( 'structures.SearchBox' ) ;
174+ } else {
175+ const SearchBox = sdk . getComponent ( 'structures.SearchBox' ) ;
198176 topBox = < SearchBox collapsed = { this . props . collapsed } onSearch = { this . onSearch } /> ;
199177 }
200178
201- var classes = "mx_LeftPanel mx_fadable" ;
179+ let classes = "mx_LeftPanel mx_fadable" ;
202180 if ( this . props . collapsed ) {
203181 classes += " collapsed" ;
204182 }
205183
206- var callPreview ;
207- if ( this . state . showCallElement && ! this . props . collapsed ) {
208- var CallView = sdk . getComponent ( 'voip.CallView' ) ;
209- callPreview = (
210- < CallView
211- className = "mx_LeftPanel_callView" showVoice = { true } onClick = { this . onCallViewClick }
212- ConferenceHandler = { VectorConferenceHandler } />
213- ) ;
214- }
215-
216184 return (
217185 < aside className = { classes } style = { { opacity : this . props . opacity } }
218186 onKeyDown = { this . _onKeyDown } onFocus = { this . _onFocus } onBlur = { this . _onBlur } >
219187 { topBox }
220- { callPreview }
188+ < CallPreview ConferenceHandler = { VectorConferenceHandler } />
221189 < RoomList
222- selectedRoom = { this . props . selectedRoom }
223190 collapsed = { this . props . collapsed }
224191 searchFilter = { this . state . searchFilter }
225192 ConferenceHandler = { VectorConferenceHandler } />
0 commit comments