Skip to content

Commit 2926154

Browse files
committed
Modify LeftPanel to include a DragDropContext
that handles drag and drop for TagPanel and RoomList. This is to allow the future feature of dragging between the two components.
1 parent 37b5de2 commit 2926154

File tree

2 files changed

+78
-12
lines changed

2 files changed

+78
-12
lines changed

src/components/structures/LeftPanel.js

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,32 @@ limitations under the License.
1717
'use strict';
1818

1919
import React from 'react';
20+
import PropTypes from 'prop-types';
2021
import classNames from 'classnames';
22+
import { DragDropContext } from 'react-beautiful-dnd';
23+
import { MatrixClient } from 'matrix-js-sdk';
2124
import { KeyCode } from 'matrix-react-sdk/lib/Keyboard';
2225
import sdk from 'matrix-react-sdk';
2326
import dis from 'matrix-react-sdk/lib/dispatcher';
2427
import 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';
2728
import 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+
2935
var 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
});

src/skins/vector/css/vector-web/structures/_LeftPanel.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ limitations under the License.
2121
flex-direction: column;
2222
}
2323

24+
.mx_LeftPanel_container {
25+
display: flex;
26+
}
27+
2428
.mx_LeftPanel_hideButton {
2529
position: absolute;
2630
top: 10px;

0 commit comments

Comments
 (0)