mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-22 12:41:11 +00:00
List gather joins
This commit is contained in:
parent
703944a709
commit
1645c296e5
5 changed files with 120 additions and 21 deletions
|
@ -5,6 +5,7 @@
|
|||
*
|
||||
* Server API
|
||||
* gather:refresh - Refreshes active gather
|
||||
* gather:notification - Creates a notification
|
||||
*
|
||||
* Client API
|
||||
* gather:join - Assigns user to gather
|
||||
|
@ -13,23 +14,38 @@
|
|||
*/
|
||||
|
||||
var Gather = require("./gather");
|
||||
var latestGather = new Gather();
|
||||
var gather = new Gather();
|
||||
|
||||
module.exports = function (namespace) {
|
||||
var refreshGather = function () {
|
||||
namespace.emit("gather:refresh", {
|
||||
gather: gather
|
||||
gather: gather.toJson()
|
||||
});
|
||||
};
|
||||
|
||||
namespace.on("connection", function (socket) {
|
||||
|
||||
socket.on("gather:join", function (data) {
|
||||
if (gather.can("addGatherer")) {
|
||||
gather.addGatherer(socket._user);
|
||||
refreshGather();
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("gather:leave", function (data) {
|
||||
if (gather.can("removeGatherer")) {
|
||||
gather.removeGatherer(socket._user);
|
||||
refreshGather();
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("disconnect", function () {
|
||||
|
||||
});
|
||||
|
||||
socket.on("gather:vote", function (data) {
|
||||
|
||||
});
|
||||
|
||||
refreshGather();
|
||||
});
|
||||
};
|
||||
|
|
|
@ -136,9 +136,8 @@ Gather.prototype.marines = function () {
|
|||
|
||||
Gather.prototype.toJson = function () {
|
||||
return {
|
||||
lobby: this.lobby(),
|
||||
marines: this.marines(),
|
||||
aliens: this.aliens()
|
||||
gatherers: this.gatherers,
|
||||
state: this.current
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -67,6 +67,12 @@ var UserLine = React.createClass({
|
|||
});
|
||||
|
||||
var UserMenu = React.createClass({
|
||||
getDefaultProps: function () {
|
||||
return {
|
||||
count: 0,
|
||||
users: []
|
||||
};
|
||||
},
|
||||
componentDidMount: function () {
|
||||
socket.on('userCount', this.updateUsers);
|
||||
},
|
||||
|
@ -93,6 +99,11 @@ var UserMenu = React.createClass({
|
|||
});
|
||||
|
||||
var Chatroom = React.createClass({
|
||||
getDefaultProps: function () {
|
||||
return {
|
||||
history: []
|
||||
};
|
||||
},
|
||||
componentDidMount: function () {
|
||||
var self = this;
|
||||
var TIMER_INTERVAL = 60000; // Every minute
|
||||
|
@ -129,7 +140,6 @@ var Chatroom = React.createClass({
|
|||
},
|
||||
scrollToBottom: function () {
|
||||
var node = React.findDOMNode(this.refs.messageContainer);
|
||||
console.log(node)
|
||||
node.scrollTop = node.scrollHeight;
|
||||
},
|
||||
render: function () {
|
||||
|
@ -234,16 +244,40 @@ var MessageBar = React.createClass({
|
|||
});
|
||||
|
||||
var Gather = React.createClass({
|
||||
getDefaultProps: function () {
|
||||
return {
|
||||
gather: {
|
||||
gatherers: []
|
||||
}
|
||||
}
|
||||
},
|
||||
componentDidMount: function () {
|
||||
var self = this;
|
||||
socket.on("gather:refresh", function (data) {
|
||||
self.setProps({
|
||||
gather: data.gather
|
||||
});
|
||||
});
|
||||
},
|
||||
joinGather: function (e) {
|
||||
e.preventDefault();
|
||||
alert("Joined gather!");
|
||||
socket.emit("gather:join", {});
|
||||
},
|
||||
render: function () {
|
||||
var gatherers = this.props.gather.gatherers.map(function (gatherer) {
|
||||
console.log(gatherer)
|
||||
return (<Gatherer gatherer={gatherer} />);
|
||||
})
|
||||
return (
|
||||
<div className="panel panel-default">
|
||||
<div className="panel-heading">
|
||||
Current Gather
|
||||
</div>
|
||||
<table className="table">
|
||||
<tbody>
|
||||
{gatherers}
|
||||
</tbody>
|
||||
</table>
|
||||
<div className="panel-body">
|
||||
</div>
|
||||
<div className="panel-footer">
|
||||
|
@ -257,6 +291,14 @@ var Gather = React.createClass({
|
|||
}
|
||||
});
|
||||
|
||||
var Gatherer = React.createClass({
|
||||
render: function () {
|
||||
return (
|
||||
<tr><td>{this.props.gatherer.user.username}</td></tr>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
var socket;
|
||||
|
||||
function initialiseComponents () {
|
||||
|
@ -272,9 +314,9 @@ function initialiseComponents () {
|
|||
console.log("Disconnected")
|
||||
});
|
||||
|
||||
React.render(<UserMenu count={0} users={[]} />, document.getElementById('side-menu'));
|
||||
React.render(<Chatroom history={[]}/>, document.getElementById('chatroom'));
|
||||
React.render(<Gather history={[]}/>, document.getElementById('gathers'));
|
||||
React.render(<UserMenu />, document.getElementById('side-menu'));
|
||||
React.render(<Chatroom />, document.getElementById('chatroom'));
|
||||
React.render(<Gather />, document.getElementById('gathers'));
|
||||
};
|
||||
|
||||
initialiseComponents();
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
this.time_zone = user['time_zone'];
|
||||
this.avatar = client.baseUrl + user['avatar'];
|
||||
this.admin = user['admin'];
|
||||
this.steam = {
|
||||
url: user['steam']['url'],
|
||||
nickname: user['steam']['nickname']
|
||||
};
|
||||
// this.steam = {
|
||||
// url: user['steam']['url'],
|
||||
// nickname: user['steam']['nickname']
|
||||
// };
|
||||
}
|
||||
|
||||
module.exports = User;
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue