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-25 16:43:02 +02:00
|
|
|
import {Disambiguator} from "./disambiguator.js";
|
2021-06-11 20:21:55 +02:00
|
|
|
|
|
|
|
export class MemberListViewModel extends ViewModel {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2021-06-22 14:03:31 +02:00
|
|
|
this.memberTileViewModels = this._mapTileViewModels(this._filterJoinedMembers(options.members))
|
|
|
|
.sortValues(createMemberComparator(options.powerLevels));
|
2021-06-25 16:43:02 +02:00
|
|
|
this.nameDisambiguator = new Disambiguator();
|
2021-06-26 11:02:39 +02:00
|
|
|
this.mediaRepository = options.mediaRepository;
|
2021-06-11 20:21:55 +02:00
|
|
|
}
|
|
|
|
|
2021-06-27 11:35:35 +02:00
|
|
|
get type() { return "member-list"; }
|
|
|
|
|
2021-06-11 20:21:55 +02:00
|
|
|
_filterJoinedMembers(members) {
|
|
|
|
return members.filterValues(member => member.membership === "join");
|
|
|
|
}
|
|
|
|
|
|
|
|
_mapTileViewModels(members) {
|
2021-06-25 16:43:02 +02:00
|
|
|
const mapper = (member, emitChange) => {
|
2021-06-26 11:02:39 +02:00
|
|
|
const mediaRepository = this.mediaRepository;
|
|
|
|
const vm = new MemberTileViewModel(this.childOptions({member, emitChange, mediaRepository}));
|
2021-06-25 16:43:02 +02:00
|
|
|
this.nameDisambiguator.disambiguate(vm);
|
|
|
|
return vm;
|
2021-06-22 12:22:05 +02:00
|
|
|
}
|
2021-06-25 16:43:02 +02:00
|
|
|
const updater = (vm, params, newMember) => {
|
|
|
|
vm.updateFrom(newMember);
|
|
|
|
this.nameDisambiguator.disambiguate(vm);
|
|
|
|
};
|
2021-06-22 14:03:31 +02:00
|
|
|
return members.mapValues(mapper, updater);
|
2021-06-11 20:21:55 +02:00
|
|
|
}
|
2021-06-25 16:43:02 +02:00
|
|
|
|
2021-06-11 20:21:55 +02:00
|
|
|
}
|