Merge pull request #1743 from matrix-org/luke/feature-tag-panel-tile-context-menu

Add context menu to TagTile
This commit is contained in:
Luke Barnard 2018-02-13 17:28:43 +00:00 committed by GitHub
commit c670b76ec8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 3 deletions

View file

@ -55,6 +55,7 @@ class TagOrderStore extends Store {
const tagOrderingEventContent = tagOrderingEvent ? tagOrderingEvent.getContent() : {};
this._setState({
orderedTagsAccountData: tagOrderingEventContent.tags || null,
removedTagsAccountData: tagOrderingEventContent.removedTags || null,
hasSynced: true,
});
this._updateOrderedTags();
@ -70,6 +71,7 @@ class TagOrderStore extends Store {
this._setState({
orderedTagsAccountData: payload.event_content ? payload.event_content.tags : null,
removedTagsAccountData: payload.event_content ? payload.event_content.removedTags : null,
});
this._updateOrderedTags();
break;
@ -90,6 +92,14 @@ class TagOrderStore extends Store {
});
break;
}
case 'TagOrderActions.removeTag.pending': {
// Optimistic update of a removed tag
this._setState({
removedTagsAccountData: payload.request.removedTags,
});
this._updateOrderedTags();
break;
}
case 'select_tag': {
let newTags = [];
// Shift-click semantics
@ -165,13 +175,15 @@ class TagOrderStore extends Store {
_mergeGroupsAndTags() {
const groupIds = this._state.joinedGroupIds || [];
const tags = this._state.orderedTagsAccountData || [];
const removedTags = new Set(this._state.removedTagsAccountData || []);
const tagsToKeep = tags.filter(
(t) => t[0] !== '+' || groupIds.includes(t),
(t) => (t[0] !== '+' || groupIds.includes(t)) && !removedTags.has(t),
);
const groupIdsToAdd = groupIds.filter(
(groupId) => !tags.includes(groupId),
(groupId) => !tags.includes(groupId) && !removedTags.has(groupId),
);
return tagsToKeep.concat(groupIdsToAdd);
@ -181,6 +193,10 @@ class TagOrderStore extends Store {
return this._state.orderedTags;
}
getRemovedTagsAccountData() {
return this._state.removedTagsAccountData;
}
getStoreId() {
// Generate a random ID to prevent this store from clobbering its
// state with redundant remote echos.