fix various edge cases when dragging stuff back to the conversations list

pull/342/head
Matthew Hodgson 2015-11-06 23:30:57 +01:00
parent 89327bd38f
commit fe442f5c24
4 changed files with 19 additions and 8 deletions

View File

@ -135,11 +135,16 @@ module.exports = {
getRoomLists: function() {
var s = { lists: {} };
s.lists["m.invite"] = [];
s.lists["m.favourite"] = [];
s.lists["m.recent"] = [];
s.lists["m.lowpriority"] = [];
s.lists["m.archived"] = [];
MatrixClientPeg.get().getRooms().forEach(function(room) {
var me = room.getMember(MatrixClientPeg.get().credentials.userId);
if (me && me.membership == "invite") {
s.lists["m.invite"] = s.lists["m.invite"] || [];
s.lists["m.invite"].push(room);
}
else {
@ -172,7 +177,6 @@ module.exports = {
}
}
else {
s.lists["m.recent"] = s.lists["m.recent"] || [];
s.lists["m.recent"].push(room);
}
}

View File

@ -96,6 +96,7 @@ var roomTileSource = {
}
else {
// cancel the drop and reset our original position
console.log("cancelling drop & drag");
props.roomSubList.moveRoomTile(item.room, item.originalIndex);
if (item.targetList && item.targetList !== item.originalList) {
item.targetList.removeRoomTile(item.room);
@ -111,13 +112,16 @@ var roomTileTarget = {
hover: function(props, monitor) {
var item = monitor.getItem();
console.log("hovering on room " + props.room.roomId + ", isOver=" + monitor.isOver());
//console.log("hovering on room " + props.room.roomId + ", isOver=" + monitor.isOver());
//console.log("item.targetList=" + item.targetList + ", roomSubList=" + props.roomSubList);
var switchedTarget = false;
if (item.targetList !== props.roomSubList) {
// we've switched target, so remove the tile from the previous target.
// n.b. the previous target might actually be the source list.
console.log("switched target");
switchedTarget = true;
item.targetList.removeRoomTile(item.room);
item.targetList = props.roomSubList;
}
@ -130,12 +134,13 @@ var roomTileTarget = {
props.roomSubList.moveRoomTile(item.room, roomTile.index);
}
}
else {
else if (switchedTarget) {
if (!props.roomSubList.findRoomTile(item.room).room) {
// add to the list in the right place
props.roomSubList.moveRoomTile(item.room, 0);
props.roomSubList.sortList();
}
// we have to sort the list whatever to recalculate it
props.roomSubList.sortList();
}
},
};

View File

@ -65,6 +65,7 @@ module.exports = React.createClass({
<RoomSubList list={ self.state.lists['m.recent'] }
label="Conversations"
editable={ true }
verb="restore"
order="recent"
activityMap={ self.state.activityMap }
selectedRoom={ self.props.selectedRoom }

View File

@ -64,7 +64,7 @@ var RoomSubList = React.createClass({
},
componentWillMount: function() {
this.sortList();
this.sortList(this.props.list, this.props.order);
},
componentWillReceiveProps: function(newProps) {
@ -100,13 +100,14 @@ var RoomSubList = React.createClass({
},
sortList: function(list, order) {
if (list === undefined) list = this.props.list;
if (list === undefined) list = this.state.sortedList;
if (order === undefined) order = this.props.order;
var comparator;
list = list || [];
if (order === "manual") comparator = this.manualComparator;
if (order === "recent") comparator = this.recentsComparator;
// console.log("sorting list for room " + this.props.label + " with length " + list.length + ", this.props.list = " + this.props.list);
this.setState({ sortedList: list.sort(comparator) });
},
@ -146,7 +147,7 @@ var RoomSubList = React.createClass({
findRoomTile: function(room) {
var index = this.state.sortedList.indexOf(room);
if (index >= 0) {
console.log("found: room: " + room + " with id " + room.roomId);
//console.log("found: room: " + room + " with id " + room.roomId);
}
else {
console.log("didn't find room");