Skip to content

Commit 935b85a

Browse files
author
Weblate
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 68f19f9 + a819add commit 935b85a

9 files changed

Lines changed: 83 additions & 239 deletions

File tree

‎.travis.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ dist: trusty
33

44
# we don't need sudo, so can run in a container, which makes startup much
55
# quicker.
6-
sudo: false
6+
#
7+
# unfortunately we do temporarily require sudo as a workaround for
8+
# https://github.com/travis-ci/travis-ci/issues/8836
9+
sudo: required
710

811
language: node_js
912
node_js:

‎package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@
7474
"pako": "^1.0.5",
7575
"prop-types": "^15.5.10",
7676
"react": "^15.6.0",
77-
"react-dnd": "^2.1.4",
78-
"react-dnd-html5-backend": "^2.1.2",
77+
"react-beautiful-dnd": "^4.0.1",
7978
"react-dom": "^15.6.0",
8079
"react-gemini-scrollbar": "matrix-org/react-gemini-scrollbar#5e97aef",
8180
"sanitize-html": "^1.11.1",

‎src/components/structures/RoomSubList.js‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ limitations under the License.
2020
var React = require('react');
2121
var ReactDOM = require('react-dom');
2222
var classNames = require('classnames');
23-
var DropTarget = require('react-dnd').DropTarget;
2423
var sdk = require('matrix-react-sdk');
24+
import { Droppable } from 'react-beautiful-dnd';
2525
import { _t } from 'matrix-react-sdk/lib/languageHandler';
2626
var dis = require('matrix-react-sdk/lib/dispatcher');
2727
var Unread = require('matrix-react-sdk/lib/Unread');
@@ -32,6 +32,7 @@ var AccessibleButton = require('matrix-react-sdk/lib/components/views/elements/A
3232
import Modal from 'matrix-react-sdk/lib/Modal';
3333
import { KeyCode } from 'matrix-react-sdk/lib/Keyboard';
3434

35+
3536
// turn this on for drop & drag console debugging galore
3637
var debug = false;
3738

@@ -326,9 +327,7 @@ var RoomSubList = React.createClass({
326327
});
327328
},
328329

329-
calcManualOrderTagData: function(room) {
330-
const index = this.state.sortedList.indexOf(room);
331-
330+
calcManualOrderTagData: function(index) {
332331
// we sort rooms by the lexicographic ordering of the 'order' metadata on their tags.
333332
// for convenience, we calculate this for now a floating point number between 0.0 and 1.0.
334333

@@ -375,12 +374,14 @@ var RoomSubList = React.createClass({
375374
makeRoomTiles: function() {
376375
var self = this;
377376
var DNDRoomTile = sdk.getComponent("rooms.DNDRoomTile");
378-
return this.state.sortedList.map(function(room) {
377+
return this.state.sortedList.map(function(room, index) {
379378
// XXX: is it evil to pass in self as a prop to RoomTile?
380379
return (
381380
<DNDRoomTile
381+
index={index} // For DND
382382
room={ room }
383383
roomSubList={ self }
384+
tagName={self.props.tagName}
384385
key={ room.roomId }
385386
collapsed={ self.props.collapsed || false}
386387
unread={ Unread.doesRoomHaveUnreadMessages(room) }
@@ -566,12 +567,18 @@ var RoomSubList = React.createClass({
566567
</TruncatedList>;
567568
}
568569

569-
return connectDropTarget(
570-
<div>
571-
{ this._getHeaderJsx() }
572-
{ subList }
573-
</div>
574-
);
570+
const subListContent = <div>
571+
{ this._getHeaderJsx() }
572+
{ subList }
573+
</div>;
574+
575+
return this.props.editable ? <Droppable droppableId={"room-sub-list-droppable_" + this.props.tagName}>
576+
{ (provided, snapshot) => (
577+
<div ref={provided.innerRef}>
578+
{ subListContent }
579+
</div>
580+
) }
581+
</Droppable> : subListContent;
575582
}
576583
else {
577584
var Loader = sdk.getComponent("elements.Spinner");
@@ -585,11 +592,4 @@ var RoomSubList = React.createClass({
585592
}
586593
});
587594

588-
// Export the wrapped version, inlining the 'collect' functions
589-
// to more closely resemble the ES7
590-
module.exports =
591-
DropTarget('RoomTile', roomListTarget, function(connect) {
592-
return {
593-
connectDropTarget: connect.dropTarget(),
594-
}
595-
})(RoomSubList);
595+
module.exports = RoomSubList;

‎src/components/views/rooms/DNDRoomTile.js‎

Lines changed: 40 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -14,227 +14,51 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
'use strict';
18-
1917
import React from 'react';
20-
import {DragSource} from 'react-dnd';
21-
import {DropTarget} from 'react-dnd';
22-
23-
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
24-
import sdk from 'matrix-react-sdk';
25-
import { _t } from 'matrix-react-sdk/lib/languageHandler';
18+
import { Draggable } from 'react-beautiful-dnd';
2619
import RoomTile from 'matrix-react-sdk/lib/components/views/rooms/RoomTile';
27-
import * as Rooms from 'matrix-react-sdk/lib/Rooms';
28-
import Modal from 'matrix-react-sdk/lib/Modal';
29-
30-
/**
31-
* Defines a new Component, DNDRoomTile that wraps RoomTile, making it draggable.
32-
* Requires extra props:
33-
* roomSubList: React.PropTypes.object.isRequired,
34-
* refreshSubList: React.PropTypes.func.isRequired,
35-
*/
36-
37-
/**
38-
* Specifies the drag source contract.
39-
* Only `beginDrag` function is required.
40-
*/
41-
var roomTileSource = {
42-
canDrag: function(props, monitor) {
43-
return props.roomSubList.props.editable;
44-
},
45-
46-
beginDrag: function (props) {
47-
// Return the data describing the dragged item
48-
var item = {
49-
room: props.room,
50-
originalList: props.roomSubList,
51-
originalIndex: props.roomSubList.findRoomTile(props.room).index,
52-
targetList: props.roomSubList, // at first target is same as original
53-
// lastTargetRoom: null,
54-
// lastYOffset: null,
55-
// lastYDelta: null,
56-
};
57-
58-
if (props.roomSubList.debug) console.log("roomTile beginDrag for " + item.room.roomId);
59-
60-
// doing this 'correctly' with state causes react-dnd to break seemingly due to the state transitions
61-
props.room._dragging = true;
62-
63-
return item;
64-
},
65-
66-
endDrag: function (props, monitor, component) {
67-
var item = monitor.getItem();
68-
69-
if (props.roomSubList.debug) console.log("roomTile endDrag for " + item.room.roomId + " with didDrop=" + monitor.didDrop());
70-
71-
props.room._dragging = false;
72-
if (monitor.didDrop()) {
73-
if (props.roomSubList.debug) console.log("force updating component " + item.targetList.props.label);
74-
item.targetList.forceUpdate(); // as we're not using state
75-
}
76-
77-
const prevTag = item.originalList.props.tagName;
78-
const newTag = item.targetList.props.tagName;
79-
80-
if (monitor.didDrop() && item.targetList.props.editable) {
81-
// Evil hack to get DMs behaving
82-
if ((prevTag === undefined && newTag === 'im.vector.fake.direct') ||
83-
(prevTag === 'im.vector.fake.direct' && newTag === undefined)
84-
) {
85-
Rooms.guessAndSetDMRoom(
86-
item.room, newTag === 'im.vector.fake.direct',
87-
).done(() => {
88-
item.originalList.removeRoomTile(item.room);
89-
}, (err) => {
90-
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
91-
console.error("Failed to set direct chat tag " + err);
92-
Modal.createTrackedDialog('Failed to set direct chat tag', '', ErrorDialog, {
93-
title: _t('Failed to set direct chat tag'),
94-
description: ((err && err.message) ? err.message : _t('Operation failed')),
95-
});
96-
});
97-
return;
98-
}
99-
100-
// More evilness: We will still be dealing with moving to favourites/low prio,
101-
// but we avoid ever doing a request with 'im.vector.fake.direct`.
10220

103-
// if we moved lists, remove the old tag
104-
if (prevTag && prevTag !== 'im.vector.fake.direct' &&
105-
item.targetList !== item.originalList
106-
) {
107-
// commented out attempts to set a spinner on our target component as component is actually
108-
// the original source component being dragged, not our target. To fix we just need to
109-
// move all of this to endDrop in the target instead. FIXME later.
21+
import classNames from 'classnames';
11022

111-
//component.state.set({ spinner: component.state.spinner ? component.state.spinner++ : 1 });
112-
MatrixClientPeg.get().deleteRoomTag(item.room.roomId, prevTag).finally(function() {
113-
//component.state.set({ spinner: component.state.spinner-- });
114-
}).catch(function(err) {
115-
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
116-
console.error("Failed to remove tag " + prevTag + " from room: " + err);
117-
Modal.createTrackedDialog('Failed to remove tag from room', '', ErrorDialog, {
118-
title: _t('Failed to remove tag %(tagName)s from room', {tagName: prevTag}),
119-
description: ((err && err.message) ? err.message : _t('Operation failed')),
120-
});
121-
});
122-
}
123-
124-
var newOrder= {};
125-
if (item.targetList.props.order === 'manual') {
126-
newOrder['order'] = item.targetList.calcManualOrderTagData(item.room);
127-
}
128-
129-
// if we moved lists or the ordering changed, add the new tag
130-
if (newTag && newTag !== 'im.vector.fake.direct' &&
131-
(item.targetList !== item.originalList || newOrder)
132-
) {
133-
MatrixClientPeg.get().setRoomTag(item.room.roomId, newTag, newOrder).catch(function(err) {
134-
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
135-
console.error("Failed to add tag " + newTag + " to room: " + err);
136-
Modal.createTrackedDialog('Failed to add tag to room', '', ErrorDialog, {
137-
title: _t('Failed to add tag %(tagName)s to room', {tagName: newTag}),
138-
description: ((err && err.message) ? err.message : _t('Operation failed')),
139-
});
140-
});
141-
}
142-
}
143-
else {
144-
// cancel the drop and reset our original position
145-
if (props.roomSubList.debug) console.log("cancelling drop & drag");
146-
props.roomSubList.moveRoomTile(item.room, item.originalIndex);
147-
if (item.targetList && item.targetList !== item.originalList) {
148-
item.targetList.removeRoomTile(item.room);
149-
}
150-
}
23+
export default class DNDRoomTile extends React.Component {
24+
constructor() {
25+
super();
26+
this.getClassName = this.getClassName.bind(this);
15127
}
152-
};
153-
154-
var roomTileTarget = {
155-
canDrop: function() {
156-
return false;
157-
},
158-
159-
hover: function(props, monitor) {
160-
var item = monitor.getItem();
161-
//var off = monitor.getClientOffset();
162-
// console.log("hovering on room " + props.room.roomId + ", isOver=" + monitor.isOver());
163-
164-
//console.log("item.targetList=" + item.targetList + ", roomSubList=" + props.roomSubList);
165-
166-
var switchedTarget = false;
167-
if (item.targetList !== props.roomSubList) {
168-
// we've switched target, so remove the tile from the previous target.
169-
// n.b. the previous target might actually be the source list.
170-
if (props.roomSubList.debug) console.log("switched target sublist");
171-
switchedTarget = true;
172-
item.targetList.removeRoomTile(item.room);
173-
item.targetList = props.roomSubList;
174-
}
175-
176-
if (!item.targetList.props.editable) return;
17728

178-
if (item.targetList.props.order === 'manual') {
179-
if (item.room.roomId !== props.room.roomId && props.room !== item.lastTargetRoom) {
180-
// find the offset of the target tile in the list.
181-
var roomTile = props.roomSubList.findRoomTile(props.room);
182-
// shuffle the list to add our tile to that position.
183-
props.roomSubList.moveRoomTile(item.room, roomTile.index);
184-
}
185-
186-
// stop us from flickering between our droptarget and the previous room.
187-
// whenever the cursor changes direction we have to reset the flicker-damping.
188-
/*
189-
var yDelta = off.y - item.lastYOffset;
190-
191-
if ((yDelta > 0 && item.lastYDelta < 0) ||
192-
(yDelta < 0 && item.lastYDelta > 0))
193-
{
194-
// the cursor changed direction - forget our previous room
195-
item.lastTargetRoom = null;
196-
}
197-
else {
198-
// track the last room we were hovering over so we can stop
199-
// bouncing back and forth if the droptarget is narrower than
200-
// the other list items. The other way to do this would be
201-
// to reduce the size of the hittarget on the list items, but
202-
// can't see an easy way to do that.
203-
item.lastTargetRoom = props.room;
204-
}
205-
206-
if (yDelta) item.lastYDelta = yDelta;
207-
item.lastYOffset = off.y;
208-
*/
209-
}
210-
else if (switchedTarget) {
211-
if (!props.roomSubList.findRoomTile(item.room).room) {
212-
// add to the list in the right place
213-
props.roomSubList.moveRoomTile(item.room, 0);
214-
}
215-
// we have to sort the list whatever to recalculate it
216-
props.roomSubList.sortList();
217-
}
218-
},
219-
};
29+
getClassName(isDragging) {
30+
return classNames({
31+
"mx_DNDRoomTile": true,
32+
"mx_DNDRoomTile_dragging": isDragging,
33+
});
34+
}
22035

221-
// Export the wrapped version, inlining the 'collect' functions
222-
// to more closely resemble the ES7
223-
module.exports =
224-
DropTarget('RoomTile', roomTileTarget, function(connect, monitor) {
225-
return {
226-
// Call this function inside render()
227-
// to let React DnD handle the drag events:
228-
connectDropTarget: connect.dropTarget(),
229-
isOver: monitor.isOver(),
36+
render() {
37+
const props = this.props;
38+
39+
return <div>
40+
<Draggable
41+
key={props.room.roomId}
42+
draggableId={props.tagName + '_' + props.room.roomId}
43+
index={props.index}
44+
>
45+
{ (provided, snapshot) => {
46+
return (
47+
<div>
48+
<div
49+
ref={provided.innerRef}
50+
{...provided.draggableProps}
51+
{...provided.dragHandleProps}
52+
>
53+
<div className={this.getClassName(snapshot.isDragging)}>
54+
<RoomTile {...props} />
55+
</div>
56+
</div>
57+
{ provided.placeholder }
58+
</div>
59+
);
60+
} }
61+
</Draggable>
62+
</div>;
23063
}
231-
})(
232-
DragSource('RoomTile', roomTileSource, function(connect, monitor) {
233-
return {
234-
// Call this function inside render()
235-
// to let React DnD handle the drag events:
236-
connectDragSource: connect.dragSource(),
237-
// You can ask the monitor about the current drag state:
238-
isDragging: monitor.isDragging()
239-
};
240-
})(RoomTile));
64+
}

‎src/skins/vector/css/matrix-react-sdk/views/rooms/_RoomTile.scss‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ limitations under the License.
2020
font-size: 13px;
2121
display: block;
2222
height: 34px;
23+
24+
background-color: $secondary-accent-color;
2325
}
2426

2527
.mx_RoomTile_tooltip {
@@ -155,6 +157,15 @@ limitations under the License.
155157
background-color: $roomtile-selected-bg-color;
156158
}
157159

160+
.mx_DNDRoomTile {
161+
transform: none;
162+
transition: transform 0.2s;
163+
}
164+
165+
.mx_DNDRoomTile_dragging {
166+
transform: scale(1.05, 1.05);
167+
}
168+
158169
.mx_RoomTile:focus {
159170
filter: none ! important;
160171
background-color: $roomtile-focused-bg-color;

0 commit comments

Comments
 (0)