Merge pull request #3033 from dpalou/MOBILE-3952

MOBILE-3952 context-menu: Fix menu displayed when no items
main
Pau Ferrer Ocaña 2021-12-21 15:16:01 +01:00 committed by GitHub
commit 26eb51a570
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Component, Input, OnInit, OnDestroy, ElementRef } from '@angular/core'; import { Component, Input, OnInit, OnDestroy, ElementRef, ChangeDetectorRef } from '@angular/core';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { auditTime } from 'rxjs/operators'; import { auditTime } from 'rxjs/operators';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
@ -43,16 +43,17 @@ export class CoreContextMenuComponent implements OnInit, OnDestroy {
protected parentContextMenu?: CoreContextMenuComponent; protected parentContextMenu?: CoreContextMenuComponent;
protected expanded = false; protected expanded = false;
constructor(elementRef: ElementRef) { constructor(elementRef: ElementRef, changeDetector: ChangeDetectorRef) {
// Create the stream and subscribe to it. We ignore successive changes during 250ms. // Create the stream and subscribe to it. We ignore successive changes during 250ms.
this.itemsChangedStream = new Subject<void>(); this.itemsChangedStream = new Subject<void>();
this.itemsChangedStream.pipe(auditTime(250)); this.itemsChangedStream.pipe(auditTime(250)).subscribe(() => {
this.itemsChangedStream.subscribe(() => {
// Hide the menu if all items are hidden. // Hide the menu if all items are hidden.
this.hideMenu = !this.items.some((item) => !item.hidden); this.hideMenu = !this.items.some((item) => !item.hidden);
// Sort the items by priority. // Sort the items by priority.
this.items.sort((a, b) => (a.priority || 0) <= (b.priority || 0) ? 1 : -1); this.items.sort((a, b) => (a.priority || 0) <= (b.priority || 0) ? 1 : -1);
changeDetector.detectChanges();
}); });
// Calculate the unique ID. // Calculate the unique ID.
@ -118,7 +119,7 @@ export class CoreContextMenuComponent implements OnInit, OnDestroy {
// Remove all items from the current menu. // Remove all items from the current menu.
this.items = []; this.items = [];
this.itemsChanged(); this.itemsChangedStream.next();
} }
/** /**