gamja-old/components/member-list.js

44 lines
948 B
JavaScript
Raw Normal View History

import { html, Component } from "../lib/index.js";
import { getNickURL } from "../state.js";
2020-06-26 08:32:56 -04:00
class MemberItem extends Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
shouldComponentUpdate(nextProps) {
return this.props.nick !== nextProps.nick;
}
handleClick(event) {
2020-06-26 08:32:56 -04:00
event.preventDefault();
this.props.onClick();
2020-06-26 08:32:56 -04:00
}
render() {
return html`
<li>
2020-07-15 12:47:33 -04:00
<a href=${getNickURL(this.props.nick)} class="nick" onClick=${this.handleClick}>${this.props.nick}</a>
</li>
`;
}
2020-06-26 08:32:56 -04:00
}
export default class MemberList extends Component {
shouldComponentUpdate(nextProps) {
return this.props.members !== nextProps.members;
}
render() {
return html`
<ul>
${Array.from(this.props.members).sort().map(([nick, membership]) => html`
<${MemberItem} key=${nick} nick=${nick} membership=${membership} onClick=${() => this.props.onNickClick(nick)}/>
`)}
</ul>
`;
}
2020-06-26 08:32:56 -04:00
}