11/*
22Copyright 2015, 2016 OpenMarket Ltd
3+ Copyright 2017 Vector Creations Ltd
34
45Licensed under the Apache License, Version 2.0 (the "License");
56you may not use this file except in compliance with the License.
@@ -14,13 +15,15 @@ See the License for the specific language governing permissions and
1415limitations under the License.
1516*/
1617
17- 'use strict' ;
18+ import React from 'react' ;
19+ import ReactDOM from 'react-dom' ;
20+ import sdk from 'matrix-react-sdk' ;
21+ import dis from 'matrix-react-sdk/lib/dispatcher' ;
22+ import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton' ;
23+ import Velocity from 'velocity-vector' ;
24+ import 'velocity-vector/velocity.ui' ;
1825
19- var React = require ( 'react' ) ;
20- var ReactDOM = require ( 'react-dom' ) ;
21- var sdk = require ( 'matrix-react-sdk' )
22- var dis = require ( 'matrix-react-sdk/lib/dispatcher' ) ;
23- var AccessibleButton = require ( 'matrix-react-sdk/lib/components/views/elements/AccessibleButton' ) ;
26+ const CALLOUT_ANIM_DURATION = 1000 ;
2427
2528module . exports = React . createClass ( {
2629 displayName : 'BottomLeftMenu' ,
@@ -39,6 +42,18 @@ module.exports = React.createClass({
3942 } ) ;
4043 } ,
4144
45+ componentWillMount : function ( ) {
46+ this . _dispatcherRef = dis . register ( this . onAction ) ;
47+ this . _peopleButton = null ;
48+ this . _directoryButton = null ;
49+ this . _createRoomButton = null ;
50+ this . _lastCallouts = { } ;
51+ } ,
52+
53+ componentWillUnmount : function ( ) {
54+ dis . unregister ( this . _dispatcherRef ) ;
55+ } ,
56+
4257 // Room events
4358 onDirectoryClick : function ( ) {
4459 dis . dispatch ( { action : 'view_room_directory' } ) ;
@@ -103,6 +118,30 @@ module.exports = React.createClass({
103118 this . setState ( { settingsHover : false } ) ;
104119 } ,
105120
121+ onAction : function ( payload ) {
122+ let calloutElement ;
123+ switch ( payload . action ) {
124+ // Incoming instruction: dance!
125+ case 'callout_start_chat' :
126+ calloutElement = this . _peopleButton ;
127+ break ;
128+ case 'callout_room_directory' :
129+ calloutElement = this . _directoryButton ;
130+ break ;
131+ case 'callout_create_room' :
132+ calloutElement = this . _createRoomButton ;
133+ break ;
134+ }
135+ if ( calloutElement ) {
136+ const lastCallout = this . _lastCallouts [ payload . action ] ;
137+ const now = Date . now ( ) ;
138+ if ( lastCallout == undefined || lastCallout < now - CALLOUT_ANIM_DURATION ) {
139+ this . _lastCallouts [ payload . action ] = now ;
140+ Velocity ( ReactDOM . findDOMNode ( calloutElement ) , "callout.bounce" , CALLOUT_ANIM_DURATION ) ;
141+ }
142+ }
143+ } ,
144+
106145 // Get the label/tooltip to show
107146 getLabel : function ( label , show ) {
108147 if ( show ) {
@@ -111,31 +150,46 @@ module.exports = React.createClass({
111150 }
112151 } ,
113152
153+ _collectPeopleButton : function ( e ) {
154+ this . _peopleButton = e ;
155+ } ,
156+
157+ _collectDirectoryButton : function ( e ) {
158+ this . _directoryButton = e ;
159+ } ,
160+
161+ _collectCreateRoomButton : function ( e ) {
162+ this . _createRoomButton = e ;
163+ } ,
164+
114165 render : function ( ) {
115- var TintableSvg = sdk . getComponent ( 'elements.TintableSvg' ) ;
166+ const HomeButton = sdk . getComponent ( 'elements.HomeButton' ) ;
167+ const StartChatButton = sdk . getComponent ( 'elements.StartChatButton' ) ;
168+ const RoomDirectoryButton = sdk . getComponent ( 'elements.RoomDirectoryButton' ) ;
169+ const CreateRoomButton = sdk . getComponent ( 'elements.CreateRoomButton' ) ;
170+ const SettingsButton = sdk . getComponent ( 'elements.SettingsButton' ) ;
171+
172+ var homeButton ;
173+ if ( this . props . teamToken ) {
174+ homeButton = < HomeButton tooltip = { true } /> ;
175+ }
176+
116177 return (
117178 < div className = "mx_BottomLeftMenu" >
118179 < div className = "mx_BottomLeftMenu_options" >
119- < AccessibleButton className = "mx_BottomLeftMenu_homePage" onClick = { this . onHomeClick } onMouseEnter = { this . onHomeMouseEnter } onMouseLeave = { this . onHomeMouseLeave } >
120- < TintableSvg src = "img/icons-home.svg" width = "25" height = "25" />
121- { this . getLabel ( "Welcome page" , this . state . homeHover ) }
122- </ AccessibleButton >
123- < AccessibleButton className = "mx_BottomLeftMenu_people" onClick = { this . onPeopleClick } onMouseEnter = { this . onPeopleMouseEnter } onMouseLeave = { this . onPeopleMouseLeave } >
124- < TintableSvg src = "img/icons-people.svg" width = "25" height = "25" />
125- { this . getLabel ( "Start chat" , this . state . peopleHover ) }
126- </ AccessibleButton >
127- < AccessibleButton className = "mx_BottomLeftMenu_directory" onClick = { this . onDirectoryClick } onMouseEnter = { this . onDirectoryMouseEnter } onMouseLeave = { this . onDirectoryMouseLeave } >
128- < TintableSvg src = "img/icons-directory.svg" width = "25" height = "25" />
129- { this . getLabel ( "Room directory" , this . state . directoryHover ) }
130- </ AccessibleButton >
131- < AccessibleButton className = "mx_BottomLeftMenu_createRoom" onClick = { this . onRoomsClick } onMouseEnter = { this . onRoomsMouseEnter } onMouseLeave = { this . onRoomsMouseLeave } >
132- < TintableSvg src = "img/icons-create-room.svg" width = "25" height = "25" />
133- { this . getLabel ( "Create new room" , this . state . roomsHover ) }
134- </ AccessibleButton >
135- < AccessibleButton className = "mx_BottomLeftMenu_settings" onClick = { this . onSettingsClick } onMouseEnter = { this . onSettingsMouseEnter } onMouseLeave = { this . onSettingsMouseLeave } >
136- < TintableSvg src = "img/icons-settings.svg" width = "25" height = "25" />
137- { this . getLabel ( "Settings" , this . state . settingsHover ) }
138- </ AccessibleButton >
180+ { homeButton }
181+ < div ref = { this . _collectPeopleButton } >
182+ < StartChatButton tooltip = { true } />
183+ </ div >
184+ < div ref = { this . _collectDirectoryButton } >
185+ < RoomDirectoryButton tooltip = { true } />
186+ </ div >
187+ < div ref = { this . _collectCreateRoomButton } >
188+ < CreateRoomButton tooltip = { true } />
189+ </ div >
190+ < span className = "mx_BottomLeftMenu_settings" >
191+ < SettingsButton tooltip = { true } />
192+ </ span >
139193 </ div >
140194 </ div >
141195 ) ;
0 commit comments