1
0
mirror of https://github.com/fspc/workstand.git synced 2025-04-04 10:03:22 -04:00
2017-01-01 22:41:55 -06:00

47 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { PropTypes } from 'react';
import { ListItem } from 'material-ui/List';
import moment from 'moment';
export default class SignedInList extends React.Component {
static propTypes = {
members: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number,
purpose: PropTypes.string,
at: PropTypes.instanceOf(moment),
})),
}
constructor(props) {
super(props);
this.state = { tick: 0 };
this.componentDidMount = this.componentDidMount.bind(this);
this.componentWillUnmount = this.componentWillUnmount.bind(this);
this.tick = this.tick.bind(this);
}
componentDidMount() {
this.timer = setInterval(this.tick, 50);
}
componentWillUnmount() {
clearInterval(this.timer);
}
tick() {
this.setState({ tick: this.state.tick += 1 });
}
render() {
const members = this.props.members.sort((l, r) => l.at.diff(r.at))
.reverse()
.map(member => <ListItem key={member.id} primaryText={member.text} secondaryText={`${member.purpose} ${member.at.fromNow()}`} />);
return (
<div className="mdl-cell mdl-cell--12-col">
<h3>Members signed in</h3>
{members.length ? members : 'No members currently signed in.'}
</div>
);
}
}