Merge pull request #175 from vector-im/matthew/userlist
Reskin the userlist as per the design
This commit is contained in:
commit
616b4fe0f1
17 changed files with 333 additions and 204 deletions
72
src/ContextualMenu.js
Normal file
72
src/ContextualMenu.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
Copyright 2015 OpenMarket Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var q = require('q');
|
||||
|
||||
// Shamelessly ripped off Modal.js. There's probably a better way
|
||||
// of doing reusable widgets like dialog boxes & menus where we go and
|
||||
// pass in a custom control as the actual body.
|
||||
|
||||
module.exports = {
|
||||
ContextualMenuContainerId: "mx_ContextualMenu_Container",
|
||||
|
||||
getOrCreateContainer: function() {
|
||||
var container = document.getElementById(this.ContextualMenuContainerId);
|
||||
|
||||
if (!container) {
|
||||
container = document.createElement("div");
|
||||
container.id = this.ContextualMenuContainerId;
|
||||
document.body.appendChild(container);
|
||||
}
|
||||
|
||||
return container;
|
||||
},
|
||||
|
||||
createMenu: function (Element, props) {
|
||||
var self = this;
|
||||
|
||||
var closeMenu = function() {
|
||||
React.unmountComponentAtNode(self.getOrCreateContainer());
|
||||
|
||||
if (props && props.onFinished) props.onFinished.apply(null, arguments);
|
||||
};
|
||||
|
||||
var position = {
|
||||
top: props.top - 20,
|
||||
right: props.right + 8,
|
||||
};
|
||||
|
||||
// FIXME: If a menu uses getDefaultProps it clobbers the onFinished
|
||||
// property set here so you can't close the menu from a button click!
|
||||
var menu = (
|
||||
<div className="mx_ContextualMenu_wrapper">
|
||||
<div className="mx_ContextualMenu" style={position}>
|
||||
<img className="mx_ContextualMenu_chevron" src="img/chevron-right.png" width="9" height="16" />
|
||||
<Element {...props} onFinished={closeMenu}/>
|
||||
</div>
|
||||
<div className="mx_ContextualMenu_background" onClick={closeMenu}></div>
|
||||
</div>
|
||||
);
|
||||
|
||||
React.render(menu, this.getOrCreateContainer());
|
||||
|
||||
return {close: closeMenu};
|
||||
},
|
||||
};
|
|
@ -47,11 +47,11 @@ module.exports = {
|
|||
// FIXME: If a dialog uses getDefaultProps it clobbers the onFinished
|
||||
// property set here so you can't close the dialog from a button click!
|
||||
var dialog = (
|
||||
<div className="mx_Dialog_Wrapper">
|
||||
<div className="mx_Dialog_wrapper">
|
||||
<div className="mx_Dialog">
|
||||
<Element {...props} onFinished={closeDialog}/>
|
||||
</div>
|
||||
<div className="mx_Dialog_Background" onClick={closeDialog}></div>
|
||||
<div className="mx_Dialog_background" onClick={closeDialog}></div>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
|
|
@ -16,8 +16,6 @@ limitations under the License.
|
|||
|
||||
/*
|
||||
* State vars:
|
||||
* 'presence' : string (online|offline|unavailable etc)
|
||||
* 'active' : number (ms ago; can be -1)
|
||||
* 'can': {
|
||||
* kick: boolean,
|
||||
* ban: boolean,
|
||||
|
@ -34,58 +32,21 @@ var dis = require("../../dispatcher");
|
|||
var Modal = require("../../Modal");
|
||||
var ComponentBroker = require('../../ComponentBroker');
|
||||
var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog");
|
||||
var QuestionDialog = ComponentBroker.get("organisms/QuestionDialog");
|
||||
var Loader = require("react-loader");
|
||||
|
||||
module.exports = {
|
||||
componentDidMount: function() {
|
||||
var self = this;
|
||||
// listen for presence changes
|
||||
function updateUserState(event, user) {
|
||||
if (!self.props.member) { return; }
|
||||
|
||||
if (user.userId === self.props.member.userId) {
|
||||
self.setState({
|
||||
presence: user.presence,
|
||||
active: user.lastActiveAgo
|
||||
});
|
||||
}
|
||||
}
|
||||
MatrixClientPeg.get().on("User.presence", updateUserState);
|
||||
this.userPresenceFn = updateUserState;
|
||||
|
||||
// listen for power level changes
|
||||
function updatePowerLevel(event, member) {
|
||||
if (!self.props.member) { return; }
|
||||
|
||||
if (member.roomId !== self.props.member.roomId) {
|
||||
return;
|
||||
}
|
||||
// only interested in changes to us or them
|
||||
var myUserId = MatrixClientPeg.get().credentials.userId;
|
||||
if ([myUserId, self.props.member.userId].indexOf(member.userId) === -1) {
|
||||
return;
|
||||
}
|
||||
self.setState(self._calculateOpsPermissions());
|
||||
}
|
||||
MatrixClientPeg.get().on("RoomMember.powerLevel", updatePowerLevel);
|
||||
this.updatePowerLevelFn = updatePowerLevel;
|
||||
|
||||
// work out the current state
|
||||
if (this.props.member) {
|
||||
var usr = MatrixClientPeg.get().getUser(this.props.member.userId) || {};
|
||||
var memberState = this._calculateOpsPermissions();
|
||||
memberState.presence = usr.presence || "offline";
|
||||
memberState.active = usr.lastActiveAgo || -1;
|
||||
this.setState(memberState);
|
||||
}
|
||||
},
|
||||
|
||||
componentWillUnmount: function() {
|
||||
MatrixClientPeg.get().removeListener("User.presence", this.userPresenceFn);
|
||||
MatrixClientPeg.get().removeListener(
|
||||
"RoomMember.powerLevel", this.updatePowerLevelFn
|
||||
);
|
||||
},
|
||||
|
||||
onKick: function() {
|
||||
var roomId = this.props.member.roomId;
|
||||
var target = this.props.member.userId;
|
||||
|
@ -100,6 +61,7 @@ module.exports = {
|
|||
description: err.message
|
||||
});
|
||||
});
|
||||
this.props.onFinished();
|
||||
},
|
||||
|
||||
onBan: function() {
|
||||
|
@ -116,6 +78,7 @@ module.exports = {
|
|||
description: err.message
|
||||
});
|
||||
});
|
||||
this.props.onFinished();
|
||||
},
|
||||
|
||||
onMuteToggle: function() {
|
||||
|
@ -124,12 +87,14 @@ module.exports = {
|
|||
var self = this;
|
||||
var room = MatrixClientPeg.get().getRoom(roomId);
|
||||
if (!room) {
|
||||
this.props.onFinished();
|
||||
return;
|
||||
}
|
||||
var powerLevelEvent = room.currentState.getStateEvents(
|
||||
"m.room.power_levels", ""
|
||||
);
|
||||
if (!powerLevelEvent) {
|
||||
this.props.onFinished();
|
||||
return;
|
||||
}
|
||||
var isMuted = this.state.muted;
|
||||
|
@ -157,6 +122,7 @@ module.exports = {
|
|||
description: err.message
|
||||
});
|
||||
});
|
||||
this.props.onFinished();
|
||||
},
|
||||
|
||||
onModToggle: function() {
|
||||
|
@ -164,16 +130,19 @@ module.exports = {
|
|||
var target = this.props.member.userId;
|
||||
var room = MatrixClientPeg.get().getRoom(roomId);
|
||||
if (!room) {
|
||||
this.props.onFinished();
|
||||
return;
|
||||
}
|
||||
var powerLevelEvent = room.currentState.getStateEvents(
|
||||
"m.room.power_levels", ""
|
||||
);
|
||||
if (!powerLevelEvent) {
|
||||
this.props.onFinished();
|
||||
return;
|
||||
}
|
||||
var me = room.getMember(MatrixClientPeg.get().credentials.userId);
|
||||
if (!me) {
|
||||
this.props.onFinished();
|
||||
return;
|
||||
}
|
||||
var defaultLevel = powerLevelEvent.getContent().users_default;
|
||||
|
@ -191,6 +160,7 @@ module.exports = {
|
|||
description: err.message
|
||||
});
|
||||
});
|
||||
this.props.onFinished();
|
||||
},
|
||||
|
||||
onChatClick: function() {
|
||||
|
@ -240,12 +210,40 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
}
|
||||
this.props.onFinished();
|
||||
},
|
||||
|
||||
// FIXME: this is horribly duplicated with MemberTile's onLeaveClick.
|
||||
// Not sure what the right solution to this is.
|
||||
onLeaveClick: function() {
|
||||
var roomId = this.props.member.roomId;
|
||||
Modal.createDialog(QuestionDialog, {
|
||||
title: "Leave room",
|
||||
description: "Are you sure you want to leave the room?",
|
||||
onFinished: function(should_leave) {
|
||||
if (should_leave) {
|
||||
var d = MatrixClientPeg.get().leave(roomId);
|
||||
|
||||
var modal = Modal.createDialog(Loader);
|
||||
|
||||
d.then(function() {
|
||||
modal.close();
|
||||
dis.dispatch({action: 'view_next_room'});
|
||||
}, function(err) {
|
||||
modal.close();
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: "Failed to leave room",
|
||||
description: err.toString()
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
this.props.onFinished();
|
||||
},
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
presence: "offline",
|
||||
active: -1,
|
||||
can: {
|
||||
kick: false,
|
||||
ban: false,
|
||||
|
|
|
@ -25,14 +25,23 @@ var Loader = require("react-loader");
|
|||
var MatrixClientPeg = require("../../MatrixClientPeg");
|
||||
|
||||
module.exports = {
|
||||
onClick: function() {
|
||||
dis.dispatch({
|
||||
action: 'view_user',
|
||||
user_id: this.props.member.userId
|
||||
});
|
||||
// onClick: function() {
|
||||
// dis.dispatch({
|
||||
// action: 'view_user',
|
||||
// user_id: this.props.member.userId
|
||||
// });
|
||||
// },
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
hover: false,
|
||||
menu: false,
|
||||
}
|
||||
},
|
||||
|
||||
onLeaveClick: function() {
|
||||
onLeaveClick: function(ev) {
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
var roomId = this.props.member.roomId;
|
||||
Modal.createDialog(QuestionDialog, {
|
||||
title: "Leave room",
|
||||
|
@ -56,5 +65,5 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -61,7 +61,9 @@ module.exports = {
|
|||
function updateUserState(event, user) {
|
||||
var tile = self.refs[user.userId];
|
||||
if (tile) {
|
||||
tile.forceUpdate();
|
||||
// update the whole list to get the order right, not just this cell...
|
||||
self.forceUpdate();
|
||||
// tile.forceUpdate();
|
||||
}
|
||||
}
|
||||
MatrixClientPeg.get().on("User.presence", updateUserState);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue