Handle groups being joined and left

This commit is contained in:
Luke Barnard 2017-12-11 18:03:19 +00:00
parent 8d2d3e62cd
commit a120335130
2 changed files with 20 additions and 2 deletions

View file

@ -97,11 +97,28 @@ class TagOrderStore extends Store {
_updateOrderedTags() {
this._setState({
orderedTags: this._state.hasSynced && this._state.hasFetchedJoinedGroups ?
this._state.orderedTagsAccountData || this._state.joinedGroupIds : null,
orderedTags:
this._state.hasSynced &&
this._state.hasFetchedJoinedGroups ?
this._mergeGroupsAndTags() : null,
});
}
_mergeGroupsAndTags() {
const groupIds = this._state.joinedGroupIds || [];
const tags = this._state.orderedTagsAccountData || [];
const tagsToKeep = tags.filter(
(t) => t[0] !== '+' || groupIds.includes(t),
);
const groupIdsToAdd = groupIds.filter(
(groupId) => !tags.includes(groupId),
);
return tagsToKeep.concat(groupIdsToAdd);
}
getOrderedTags() {
return this._state.orderedTags;
}