@@ -16,7 +16,14 @@ limitations under the License.
1616*/
1717
1818import React from 'react' ;
19+ import ReactDOM from 'react-dom' ;
1920import 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' ;
25+
26+ const CALLOUT_ANIM_DURATION = 1000 ;
2027
2128module . exports = React . createClass ( {
2229 displayName : 'BottomLeftMenu' ,
@@ -25,6 +32,136 @@ module.exports = React.createClass({
2532 collapsed : React . PropTypes . bool . isRequired ,
2633 } ,
2734
35+ getInitialState : function ( ) {
36+ return ( {
37+ directoryHover : false ,
38+ roomsHover : false ,
39+ homeHover : false ,
40+ peopleHover : false ,
41+ settingsHover : false ,
42+ } ) ;
43+ } ,
44+
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+
57+ // Room events
58+ onDirectoryClick : function ( ) {
59+ dis . dispatch ( { action : 'view_room_directory' } ) ;
60+ } ,
61+
62+ onDirectoryMouseEnter : function ( ) {
63+ this . setState ( { directoryHover : true } ) ;
64+ } ,
65+
66+ onDirectoryMouseLeave : function ( ) {
67+ this . setState ( { directoryHover : false } ) ;
68+ } ,
69+
70+ onRoomsClick : function ( ) {
71+ dis . dispatch ( { action : 'view_create_room' } ) ;
72+ } ,
73+
74+ onRoomsMouseEnter : function ( ) {
75+ this . setState ( { roomsHover : true } ) ;
76+ } ,
77+
78+ onRoomsMouseLeave : function ( ) {
79+ this . setState ( { roomsHover : false } ) ;
80+ } ,
81+
82+ // Home button events
83+ onHomeClick : function ( ) {
84+ dis . dispatch ( { action : 'view_home_page' } ) ;
85+ } ,
86+
87+ onHomeMouseEnter : function ( ) {
88+ this . setState ( { homeHover : true } ) ;
89+ } ,
90+
91+ onHomeMouseLeave : function ( ) {
92+ this . setState ( { homeHover : false } ) ;
93+ } ,
94+
95+ // People events
96+ onPeopleClick : function ( ) {
97+ dis . dispatch ( { action : 'view_create_chat' } ) ;
98+ } ,
99+
100+ onPeopleMouseEnter : function ( ) {
101+ this . setState ( { peopleHover : true } ) ;
102+ } ,
103+
104+ onPeopleMouseLeave : function ( ) {
105+ this . setState ( { peopleHover : false } ) ;
106+ } ,
107+
108+ // Settings events
109+ onSettingsClick : function ( ) {
110+ dis . dispatch ( { action : 'view_user_settings' } ) ;
111+ } ,
112+
113+ onSettingsMouseEnter : function ( ) {
114+ this . setState ( { settingsHover : true } ) ;
115+ } ,
116+
117+ onSettingsMouseLeave : function ( ) {
118+ this . setState ( { settingsHover : false } ) ;
119+ } ,
120+
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+
145+ // Get the label/tooltip to show
146+ getLabel : function ( label , show ) {
147+ if ( show ) {
148+ var RoomTooltip = sdk . getComponent ( "rooms.RoomTooltip" ) ;
149+ return < RoomTooltip className = "mx_BottomLeftMenu_tooltip" label = { label } /> ;
150+ }
151+ } ,
152+
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+
28165 render : function ( ) {
29166 const HomeButton = sdk . getComponent ( 'elements.HomeButton' ) ;
30167 const StartChatButton = sdk . getComponent ( 'elements.StartChatButton' ) ;
@@ -41,9 +178,9 @@ module.exports = React.createClass({
41178 < div className = "mx_BottomLeftMenu" >
42179 < div className = "mx_BottomLeftMenu_options" >
43180 { homeButton }
44- < StartChatButton tooltip = { true } />
45- < RoomDirectoryButton tooltip = { true } />
46- < CreateRoomButton tooltip = { true } />
181+ < StartChatButton ref = { this . _collectPeopleButton } tooltip = { true } />
182+ < RoomDirectoryButton ref = { this . _collectDirectoryButton } tooltip = { true } />
183+ < CreateRoomButton ref = { this . _collectCreateRoomButton } tooltip = { true } />
47184 < span className = "mx_BottomLeftMenu_settings" >
48185 < SettingsButton tooltip = { true } />
49186 </ span >
0 commit comments