Basic barebones of memberlist view

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-06-11 23:51:55 +05:30
parent 7177fc1a03
commit 69237fce85
4 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,24 @@
import {ViewModel} from "../../ViewModel.js";
import {MemberTileViewModel} from "./MemberTileViewModel.js";
function comparator(member, otherMember) {
return member.displayName?.localeCompare(otherMember.displayName);
}
export class MemberListViewModel extends ViewModel {
constructor(options) {
super(options);
this.memberTileViewModels = this._mapTileViewModels(this._filterJoinedMembers(options.members))
.sortValues(comparator);
}
_filterJoinedMembers(members) {
return members.filterValues(member => member.membership === "join");
}
_mapTileViewModels(members) {
return members.mapValues((member, emitChange) => {
return new MemberTileViewModel(this.childOptions({member, emitChange}));
});
}
}

View file

@ -0,0 +1,12 @@
import {ViewModel} from "../../ViewModel.js";
export class MemberTileViewModel extends ViewModel {
constructor(options) {
super(options);
this.member = options.member;
}
get displayName() {
return this.member.displayName;
}
}

View file

@ -0,0 +1,9 @@
import {TemplateView} from "../../general/TemplateView.js";
import {ListView} from "../../general/ListView.js";
import {MemberTileView} from "./MemberTileView.js";
export class MemberListView extends TemplateView {
render(t, vm) {
return t.view(new ListView({list: vm.memberTileViewModels}, tileViewModel => new MemberTileView(tileViewModel)));
}
}

View file

@ -0,0 +1,7 @@
import {TemplateView} from "../../general/TemplateView.js";
export class MemberTileView extends TemplateView {
render(t, vm) {
return t.div(vm.displayName);
}
}