2021-06-11 23:51:55 +05:30
|
|
|
import {ViewModel} from "../../ViewModel.js";
|
|
|
|
import {MemberTileViewModel} from "./MemberTileViewModel.js";
|
2021-07-15 21:50:40 +05:30
|
|
|
import {createMemberComparator} from "./members/comparator.js";
|
|
|
|
import {Disambiguator} from "./members/disambiguator.js";
|
2021-06-11 23:51:55 +05:30
|
|
|
|
|
|
|
export class MemberListViewModel extends ViewModel {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2021-07-15 16:49:30 +05:30
|
|
|
const list = options.members;
|
|
|
|
this.track(() => list.release());
|
2021-07-15 17:19:27 +05:30
|
|
|
|
|
|
|
const powerLevelsObservable = options.powerLevelsObservable;
|
|
|
|
this.track(powerLevelsObservable.subscribe(() => { /*resort based on new power levels here*/ }));
|
|
|
|
|
|
|
|
const powerLevels = powerLevelsObservable.get();
|
2021-07-15 16:49:30 +05:30
|
|
|
this.memberTileViewModels = this._mapTileViewModels(this._filterJoinedMembers(list.members))
|
2021-07-14 12:59:44 +05:30
|
|
|
.sortValues(createMemberComparator(powerLevels));
|
2021-06-25 20:13:02 +05:30
|
|
|
this.nameDisambiguator = new Disambiguator();
|
2021-06-26 14:32:39 +05:30
|
|
|
this.mediaRepository = options.mediaRepository;
|
2021-06-11 23:51:55 +05:30
|
|
|
}
|
|
|
|
|
2021-06-27 15:05:35 +05:30
|
|
|
get type() { return "member-list"; }
|
|
|
|
|
2021-07-15 13:08:05 +05:30
|
|
|
get shouldShowBackButton() { return true; }
|
|
|
|
|
|
|
|
get previousSegmentName() { return "details"; }
|
|
|
|
|
2021-06-11 23:51:55 +05:30
|
|
|
_filterJoinedMembers(members) {
|
|
|
|
return members.filterValues(member => member.membership === "join");
|
|
|
|
}
|
|
|
|
|
|
|
|
_mapTileViewModels(members) {
|
2021-06-25 20:13:02 +05:30
|
|
|
const mapper = (member, emitChange) => {
|
2021-06-26 14:32:39 +05:30
|
|
|
const mediaRepository = this.mediaRepository;
|
|
|
|
const vm = new MemberTileViewModel(this.childOptions({member, emitChange, mediaRepository}));
|
2021-06-25 20:13:02 +05:30
|
|
|
this.nameDisambiguator.disambiguate(vm);
|
|
|
|
return vm;
|
2021-06-22 15:52:05 +05:30
|
|
|
}
|
2021-06-25 20:13:02 +05:30
|
|
|
const updater = (vm, params, newMember) => {
|
|
|
|
vm.updateFrom(newMember);
|
|
|
|
this.nameDisambiguator.disambiguate(vm);
|
|
|
|
};
|
2021-06-22 17:33:31 +05:30
|
|
|
return members.mapValues(mapper, updater);
|
2021-06-11 23:51:55 +05:30
|
|
|
}
|
2021-06-25 20:13:02 +05:30
|
|
|
|
2021-06-11 23:51:55 +05:30
|
|
|
}
|