2021-06-11 20:21:55 +02:00
|
|
|
import {ViewModel} from "../../ViewModel.js";
|
|
|
|
import {MemberTileViewModel} from "./MemberTileViewModel.js";
|
2021-06-18 09:46:23 +02:00
|
|
|
import {createMemberComparator} from "./comparator.js";
|
2021-06-22 12:22:05 +02:00
|
|
|
import {MappedList} from "../../../observable/list/MappedList.js";
|
2021-06-11 20:21:55 +02:00
|
|
|
|
|
|
|
export class MemberListViewModel extends ViewModel {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2021-06-22 12:22:05 +02:00
|
|
|
this.memberTileViewModels = this._mapTileViewModels(this._filterJoinedMembers(options.members)
|
|
|
|
.sortValues(createMemberComparator(options.powerLevels)));
|
2021-06-11 20:21:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_filterJoinedMembers(members) {
|
|
|
|
return members.filterValues(member => member.membership === "join");
|
|
|
|
}
|
|
|
|
|
|
|
|
_mapTileViewModels(members) {
|
2021-06-22 12:22:05 +02:00
|
|
|
const mapper = (member) => {
|
|
|
|
return new MemberTileViewModel(this.childOptions({member}));
|
|
|
|
}
|
|
|
|
const updater = (vm, params, newMember) => vm.updateFrom(newMember);
|
|
|
|
return new MappedList(members, mapper, updater);
|
2021-06-11 20:21:55 +02:00
|
|
|
}
|
|
|
|
}
|