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

This commit is contained in:
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() { getRoomLists: function() {
var s = { lists: {} }; 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) { MatrixClientPeg.get().getRooms().forEach(function(room) {
var me = room.getMember(MatrixClientPeg.get().credentials.userId); var me = room.getMember(MatrixClientPeg.get().credentials.userId);
if (me && me.membership == "invite") { if (me && me.membership == "invite") {
s.lists["m.invite"] = s.lists["m.invite"] || [];
s.lists["m.invite"].push(room); s.lists["m.invite"].push(room);
} }
else { else {
@ -172,7 +177,6 @@ module.exports = {
} }
} }
else { else {
s.lists["m.recent"] = s.lists["m.recent"] || [];
s.lists["m.recent"].push(room); s.lists["m.recent"].push(room);
} }
} }

View file

@ -96,6 +96,7 @@ var roomTileSource = {
} }
else { else {
// cancel the drop and reset our original position // cancel the drop and reset our original position
console.log("cancelling drop & drag");
props.roomSubList.moveRoomTile(item.room, item.originalIndex); props.roomSubList.moveRoomTile(item.room, item.originalIndex);
if (item.targetList && item.targetList !== item.originalList) { if (item.targetList && item.targetList !== item.originalList) {
item.targetList.removeRoomTile(item.room); item.targetList.removeRoomTile(item.room);
@ -111,13 +112,16 @@ var roomTileTarget = {
hover: function(props, monitor) { hover: function(props, monitor) {
var item = monitor.getItem(); 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); //console.log("item.targetList=" + item.targetList + ", roomSubList=" + props.roomSubList);
var switchedTarget = false;
if (item.targetList !== props.roomSubList) { if (item.targetList !== props.roomSubList) {
// we've switched target, so remove the tile from the previous target. // we've switched target, so remove the tile from the previous target.
// n.b. the previous target might actually be the source list. // n.b. the previous target might actually be the source list.
console.log("switched target");
switchedTarget = true;
item.targetList.removeRoomTile(item.room); item.targetList.removeRoomTile(item.room);
item.targetList = props.roomSubList; item.targetList = props.roomSubList;
} }
@ -130,12 +134,13 @@ var roomTileTarget = {
props.roomSubList.moveRoomTile(item.room, roomTile.index); props.roomSubList.moveRoomTile(item.room, roomTile.index);
} }
} }
else { else if (switchedTarget) {
if (!props.roomSubList.findRoomTile(item.room).room) { if (!props.roomSubList.findRoomTile(item.room).room) {
// add to the list in the right place // add to the list in the right place
props.roomSubList.moveRoomTile(item.room, 0); 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'] } <RoomSubList list={ self.state.lists['m.recent'] }
label="Conversations" label="Conversations"
editable={ true } editable={ true }
verb="restore"
order="recent" order="recent"
activityMap={ self.state.activityMap } activityMap={ self.state.activityMap }
selectedRoom={ self.props.selectedRoom } selectedRoom={ self.props.selectedRoom }

View file

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