From c651b5773be04f5e0a44f7ffcd28ef0ee998150e Mon Sep 17 00:00:00 2001 From: Richard Park Date: Wed, 16 Oct 2019 10:20:49 +0900 Subject: [PATCH] refactoring --- .../left-sidenav/group.component.html | 2 ++ .../left-sidenav/group.component.ts | 33 ++++++++----------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/group.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/group.component.html index 17475b8b..1804ecb4 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/group.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/group.component.html @@ -64,6 +64,7 @@ style="visibility: hidden; position: fixed" [style.left]="profileContextMenuPosition.x" [style.top]="profileContextMenuPosition.y" + #profileContextMenuTrigger="matMenuTrigger" [matMenuTriggerFor]="profileContextMenu" > @@ -120,6 +121,7 @@ style="visibility: hidden; position: fixed" [style.left]="groupContextMenuPosition.x" [style.top]="groupContextMenuPosition.y" + #groupContextMenuTrigger="matMenuTrigger" [matMenuTriggerFor]="groupContextMenu" > diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/group.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/group.component.ts index b99e22f2..01e4f721 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/group.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/group.component.ts @@ -1,14 +1,7 @@ -import { - Component, - OnInit, - ViewChild, - ViewChildren, - QueryList, - OnDestroy -} from '@angular/core'; +import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core'; import { Observable, combineLatest, Subscription } from 'rxjs'; -import { map, tap, take } from 'rxjs/operators'; +import { map, tap } from 'rxjs/operators'; import { Store, select } from '@ngrx/store'; @@ -35,7 +28,7 @@ import { UserInfoF, UserInfoDN } from '@ucap-webmessenger/protocol-query'; -import { MatMenuTrigger, MatMenu } from '@angular/material'; +import { MatMenuTrigger } from '@angular/material'; import { VersionInfo2Response } from '@ucap-webmessenger/api-public'; import { KEY_VER_INFO } from '@app/types/ver-info.type'; @@ -49,7 +42,11 @@ export class GroupComponent implements OnInit, OnDestroy { @ViewChild('groupExpansionPanel', { static: true }) groupExpansionPanel: GroupExpansionPanelComponent; - @ViewChildren(MatMenuTrigger) menuTriggerList: QueryList; + @ViewChild('profileContextMenuTrigger', { static: true }) + profileContextMenuTrigger: MatMenuTrigger; + + @ViewChild('groupContextMenuTrigger', { static: true }) + groupContextMenuTrigger: MatMenuTrigger; profileContextMenuPosition = { x: '0px', y: '0px' }; groupContextMenuPosition = { x: '0px', y: '0px' }; @@ -228,10 +225,9 @@ export class GroupComponent implements OnInit, OnDestroy { this.profileContextMenuPosition.x = event.clientX + 'px'; this.profileContextMenuPosition.y = event.clientY + 'px'; - const contextMenuTrigger = this.menuTriggerList.toArray()[1]; - contextMenuTrigger.menu.focusFirstItem('mouse'); - contextMenuTrigger.menuData = { userInfo }; - contextMenuTrigger.openMenu(); + this.profileContextMenuTrigger.menu.focusFirstItem('mouse'); + this.profileContextMenuTrigger.menuData = { userInfo }; + this.profileContextMenuTrigger.openMenu(); } onClickGroupContextMenu(menuType: string, group: GroupDetailData) { @@ -250,9 +246,8 @@ export class GroupComponent implements OnInit, OnDestroy { this.groupContextMenuPosition.x = params.event.clientX + 'px'; this.groupContextMenuPosition.y = params.event.clientY + 'px'; - const contextMenuTrigger = this.menuTriggerList.toArray()[2]; - contextMenuTrigger.menu.focusFirstItem('mouse'); - contextMenuTrigger.menuData = { group: params.group }; - contextMenuTrigger.openMenu(); + this.groupContextMenuTrigger.menu.focusFirstItem('mouse'); + this.groupContextMenuTrigger.menuData = { group: params.group }; + this.groupContextMenuTrigger.openMenu(); } }