@@ -17,22 +17,32 @@ limitations under the License.
1717'use strict' ;
1818
1919import React from 'react' ;
20+ import PropTypes from 'prop-types' ;
2021import classNames from 'classnames' ;
22+ import { DragDropContext } from 'react-beautiful-dnd' ;
23+ import { MatrixClient } from 'matrix-js-sdk' ;
2124import { KeyCode } from 'matrix-react-sdk/lib/Keyboard' ;
2225import sdk from 'matrix-react-sdk' ;
2326import dis from 'matrix-react-sdk/lib/dispatcher' ;
2427import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg' ;
25- import CallHandler from 'matrix-react-sdk/lib/CallHandler' ;
26- import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton' ;
2728import VectorConferenceHandler from '../../VectorConferenceHandler' ;
2829
30+ import SettingsStore from "matrix-react-sdk/lib/settings/SettingsStore" ;
31+ import TagOrderActions from 'matrix-react-sdk/lib/actions/TagOrderActions' ;
32+ import RoomListActions from 'matrix-react-sdk/lib/actions/RoomListActions' ;
33+
34+
2935var LeftPanel = React . createClass ( {
3036 displayName : 'LeftPanel' ,
3137
3238 // NB. If you add props, don't forget to update
3339 // shouldComponentUpdate!
3440 propTypes : {
35- collapsed : React . PropTypes . bool . isRequired ,
41+ collapsed : PropTypes . bool . isRequired ,
42+ } ,
43+
44+ contextTypes : {
45+ matrixClient : PropTypes . instanceOf ( MatrixClient ) ,
3646 } ,
3747
3848 getInitialState : function ( ) {
@@ -161,8 +171,54 @@ var LeftPanel = React.createClass({
161171 this . setState ( { searchFilter : term } ) ;
162172 } ,
163173
174+ onDragEnd : function ( result ) {
175+ // Dragged to an invalid destination, not onto a droppable
176+ if ( ! result . destination ) {
177+ return ;
178+ }
179+
180+ const dest = result . destination . droppableId ;
181+
182+ if ( dest === 'tag-panel-droppable' ) {
183+ // Dispatch synchronously so that the TagPanel receives an
184+ // optimistic update from TagOrderStore before the previous
185+ // state is shown.
186+ dis . dispatch ( TagOrderActions . moveTag (
187+ this . context . matrixClient ,
188+ result . draggableId ,
189+ result . destination . index ,
190+ ) , true ) ;
191+ } else {
192+ this . onRoomTileEndDrag ( result ) ;
193+ }
194+ } ,
195+
196+ onRoomTileEndDrag : function ( result ) {
197+ let newTag = result . destination . droppableId . split ( '_' ) [ 1 ] ;
198+ let prevTag = result . source . droppableId . split ( '_' ) [ 1 ] ;
199+ if ( newTag === 'undefined' ) newTag = undefined ;
200+ if ( prevTag === 'undefined' ) prevTag = undefined ;
201+
202+ const roomId = result . draggableId . split ( '_' ) [ 1 ] ;
203+
204+ const oldIndex = result . source . index ;
205+ const newIndex = result . destination . index ;
206+
207+ dis . dispatch ( RoomListActions . tagRoom (
208+ this . context . matrixClient ,
209+ MatrixClientPeg . get ( ) . getRoom ( roomId ) ,
210+ prevTag , newTag ,
211+ oldIndex , newIndex ,
212+ ) , true ) ;
213+ } ,
214+
215+ collectRoomList : function ( ref ) {
216+ this . _roomList = ref ;
217+ } ,
218+
164219 render : function ( ) {
165220 const RoomList = sdk . getComponent ( 'rooms.RoomList' ) ;
221+ const TagPanel = sdk . getComponent ( 'structures.TagPanel' ) ;
166222 const BottomLeftMenu = sdk . getComponent ( 'structures.BottomLeftMenu' ) ;
167223 const CallPreview = sdk . getComponent ( 'voip.CallPreview' ) ;
168224
@@ -184,15 +240,21 @@ var LeftPanel = React.createClass({
184240 ) ;
185241
186242 return (
187- < aside className = { classes } onKeyDown = { this . _onKeyDown } onFocus = { this . _onFocus } onBlur = { this . _onBlur } >
188- { topBox }
189- < CallPreview ConferenceHandler = { VectorConferenceHandler } />
190- < RoomList
191- collapsed = { this . props . collapsed }
192- searchFilter = { this . state . searchFilter }
193- ConferenceHandler = { VectorConferenceHandler } />
194- < BottomLeftMenu collapsed = { this . props . collapsed } />
195- </ aside >
243+ < DragDropContext onDragEnd = { this . onDragEnd } >
244+ < div className = "mx_LeftPanel_container" >
245+ { SettingsStore . isFeatureEnabled ( "feature_tag_panel" ) ? < TagPanel /> : < div /> }
246+ < aside className = { classes } onKeyDown = { this . _onKeyDown } onFocus = { this . _onFocus } onBlur = { this . _onBlur } >
247+ { topBox }
248+ < CallPreview ConferenceHandler = { VectorConferenceHandler } />
249+ < RoomList
250+ ref = { this . collectRoomList }
251+ collapsed = { this . props . collapsed }
252+ searchFilter = { this . state . searchFilter }
253+ ConferenceHandler = { VectorConferenceHandler } />
254+ < BottomLeftMenu collapsed = { this . props . collapsed } />
255+ </ aside >
256+ </ div >
257+ </ DragDropContext >
196258 ) ;
197259 }
198260} ) ;
0 commit comments