close panel if already open #75

This commit is contained in:
Nicolas Constant 2019-04-07 16:47:29 -04:00
parent 4da2e3f0ed
commit 35c8a8fee5
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 48 additions and 13 deletions

View File

@ -1,16 +1,18 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { faTimes } from "@fortawesome/free-solid-svg-icons";
import { NavigationService, LeftPanelType } from '../../services/navigation.service';
import { AccountWrapper } from '../../models/account.models';
import { OpenThreadEvent } from '../../services/tools.service';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-floating-column',
templateUrl: './floating-column.component.html',
styleUrls: ['./floating-column.component.scss']
})
export class FloatingColumnComponent implements OnInit {
export class FloatingColumnComponent implements OnInit, OnDestroy {
faTimes = faTimes;
overlayActive: boolean;
overlayAccountToBrowse: string;
@ -19,31 +21,58 @@ export class FloatingColumnComponent implements OnInit {
userAccountUsed: AccountWrapper;
openPanel: string;
openPanel: string = '';
private activatedPanelSub: Subscription;
constructor(private readonly navigationService: NavigationService) { }
ngOnInit() {
this.navigationService.activatedPanelSubject.subscribe((type: LeftPanelType) => {
this.activatedPanelSub = this.navigationService.activatedPanelSubject.subscribe((type: LeftPanelType) => {
switch (type) {
case LeftPanelType.Closed:
this.openPanel = '';
break;
case LeftPanelType.AddNewAccount:
this.openPanel = 'addNewAccount';
if (this.openPanel === 'addNewAccount') {
this.closePanel();
} else {
this.openPanel = 'addNewAccount';
}
break;
case LeftPanelType.CreateNewStatus:
this.openPanel = 'createNewStatus';
if (this.openPanel === 'createNewStatus') {
this.closePanel();
} else {
this.openPanel = 'createNewStatus';
}
break;
case LeftPanelType.ManageAccount:
this.userAccountUsed = this.navigationService.getAccountToManage();
this.openPanel = 'manageAccount';
let lastUserAccountId = '';
if (this.userAccountUsed && this.userAccountUsed.info) {
lastUserAccountId = this.userAccountUsed.info.id;
}
this.userAccountUsed = this.navigationService.getAccountToManage();
if (this.openPanel === 'manageAccount' && this.userAccountUsed.info.id === lastUserAccountId) {
this.closePanel();
} else {
this.openPanel = 'manageAccount';
}
break;
case LeftPanelType.Search:
this.openPanel = 'search';
if (this.openPanel === 'search') {
this.closePanel();
} else {
this.openPanel = 'search';
}
break;
case LeftPanelType.Settings:
this.openPanel = 'settings';
if (this.openPanel === 'settings') {
this.closePanel();
} else {
this.openPanel = 'settings';
}
break;
default:
this.openPanel = '';
@ -51,6 +80,12 @@ export class FloatingColumnComponent implements OnInit {
});
}
ngOnDestroy(): void {
if(this.activatedPanelSub) {
this.activatedPanelSub.unsubscribe();
}
}
closePanel(): boolean {
this.navigationService.closePanel();
return false;
@ -60,21 +95,21 @@ export class FloatingColumnComponent implements OnInit {
this.overlayAccountToBrowse = account;
this.overlayHashtagToBrowse = null;
this.overlayThreadToBrowse = null;
this.overlayActive = true;
this.overlayActive = true;
}
browseHashtag(hashtag: string): void {
this.overlayAccountToBrowse = null;
this.overlayHashtagToBrowse = hashtag;
this.overlayThreadToBrowse = null;
this.overlayActive = true;
this.overlayActive = true;
}
browseThread(openThreadEvent: OpenThreadEvent): void {
this.overlayAccountToBrowse = null;
this.overlayHashtagToBrowse = null;
this.overlayThreadToBrowse = openThreadEvent;
this.overlayActive = true;
this.overlayActive = true;
}
closeOverlay(): boolean {