From e1c906f08b301b96b567e148841f8c7cec0023b1 Mon Sep 17 00:00:00 2001 From: Sercan Yemen Date: Tue, 10 Jul 2018 14:55:30 +0300 Subject: [PATCH] (Chat Panel) Don't unfold the panel on hover (Chat Panel) Always keep the contacts list in view --- .../chat-panel/chat-panel.component.html | 66 +++++++-------- .../chat-panel/chat-panel.component.scss | 26 +++++- .../chat-panel/chat-panel.component.ts | 80 ++++++++++--------- .../chat-panel/chat-panel.module.ts | 3 +- .../layout-1/layout-1.component.html | 2 +- .../vertical/layout-1/layout-1.component.html | 2 +- .../vertical/layout-2/layout-2.component.html | 2 +- .../vertical/layout-3/layout-3.component.html | 2 +- 8 files changed, 105 insertions(+), 78 deletions(-) diff --git a/src/app/layout/components/chat-panel/chat-panel.component.html b/src/app/layout/components/chat-panel/chat-panel.component.html index 86c6af91..585f2a8c 100644 --- a/src/app/layout/components/chat-panel/chat-panel.component.html +++ b/src/app/layout/components/chat-panel/chat-panel.component.html @@ -1,6 +1,6 @@
- +
chat @@ -9,21 +9,17 @@ - +
- - -

{{contact.name}}

+ +

{{selectedContact.name}}

-
- +
+ - - -

- {{contact.name}} -

-
{{contact.unread}}
+ - - - - +
-
+
-
0"> + +
- + + +
+
{{message.message}}
+
{{message.time | date:'short'}}
+
-
-
{{message.message}}
-
{{message.time | date:'short'}}
-
+ - +
chat @@ -115,5 +114,6 @@
+ - \ No newline at end of file +
\ No newline at end of file diff --git a/src/app/layout/components/chat-panel/chat-panel.component.scss b/src/app/layout/components/chat-panel/chat-panel.component.scss index fbd52c1f..93b0d321 100644 --- a/src/app/layout/components/chat-panel/chat-panel.component.scss +++ b/src/app/layout/components/chat-panel/chat-panel.component.scss @@ -4,9 +4,9 @@ chat-panel { display: flex; flex-direction: column; flex: 1 1 auto; - width: 280px; - min-width: 280px; - max-width: 280px; + width: 360px; + min-width: 360px; + max-width: 360px; z-index: 99; overflow: hidden; @@ -31,11 +31,28 @@ chat-panel { #contacts-list { padding: 8px 0; overflow: auto; + width: 72px; + min-width: 72px; + max-width: 72px; + + // Perfect scrollbar + .ps__rail-y { + width: 3px !important; + + .ps__thumb-y { + width: 3px !important; + } + } .mat-list-item { cursor: pointer; position: relative; + &.active { + background-color: mat-color(mat-palette($mat-grey, 300)); + @include mat-elevation(2); + } + &.offline { .mat-list-item-content { @@ -316,6 +333,9 @@ chat-panel { fuse-sidebar { &.chat-panel { + width: 360px; + min-width: 360px; + max-width: 360px; // Folded &.folded { diff --git a/src/app/layout/components/chat-panel/chat-panel.component.ts b/src/app/layout/components/chat-panel/chat-panel.component.ts index 2eba8086..cf7c04f9 100644 --- a/src/app/layout/components/chat-panel/chat-panel.component.ts +++ b/src/app/layout/components/chat-panel/chat-panel.component.ts @@ -1,4 +1,4 @@ -import { Component, ElementRef, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; +import { AfterViewInit, Component, ElementRef, OnDestroy, OnInit, QueryList, ViewChild, ViewChildren, ViewEncapsulation } from '@angular/core'; import { NgForm } from '@angular/forms'; import { HttpClient } from '@angular/common/http'; @@ -15,20 +15,13 @@ import { ChatPanelService } from 'app/layout/components/chat-panel/chat-panel.se styleUrls : ['./chat-panel.component.scss'], encapsulation: ViewEncapsulation.None }) -export class ChatPanelComponent implements OnInit, OnDestroy +export class ChatPanelComponent implements OnInit, AfterViewInit, OnDestroy { contacts: any[]; - contact: any; chat: any; + selectedContact: any; sidebarFolded: boolean; user: any; - view: string; - - @ViewChild(FusePerfectScrollbarDirective) - set fusePerfectScrollbarDirective(content: FusePerfectScrollbarDirective) - { - this._fusePerfectScrollbarDirective = content; - } @ViewChild('replyForm') set replyForm(content: NgForm) @@ -42,8 +35,11 @@ export class ChatPanelComponent implements OnInit, OnDestroy this._replyInput = content; } + @ViewChildren(FusePerfectScrollbarDirective) + private _fusePerfectScrollbarDirectives: QueryList; + // Private - private _fusePerfectScrollbarDirective: FusePerfectScrollbarDirective; + private _chatViewScrollbar: FusePerfectScrollbarDirective; private _replyForm: NgForm; private _replyInput: ElementRef; private _unsubscribeAll: Subject; @@ -62,9 +58,8 @@ export class ChatPanelComponent implements OnInit, OnDestroy ) { // Set the defaults - this.contact = null; + this.selectedContact = null; this.sidebarFolded = true; - this.view = 'contacts'; // Set the private defaults this._unsubscribeAll = new Subject(); @@ -94,6 +89,16 @@ export class ChatPanelComponent implements OnInit, OnDestroy }); } + /** + * After view init + */ + ngAfterViewInit(): void + { + this._chatViewScrollbar = this._fusePerfectScrollbarDirectives.find((directive) => { + return directive.elementRef.nativeElement.id === 'messages'; + }); + } + /** * On destroy */ @@ -122,12 +127,12 @@ export class ChatPanelComponent implements OnInit, OnDestroy this._replyInput.nativeElement.focus(); // Scroll to the bottom of the messages list - if ( this._fusePerfectScrollbarDirective ) + if ( this._chatViewScrollbar ) { - this._fusePerfectScrollbarDirective.update(); + this._chatViewScrollbar.update(); setTimeout(() => { - this._fusePerfectScrollbarDirective.scrollToBottom(0); + this._chatViewScrollbar.scrollToBottom(0); }); } }); @@ -145,6 +150,22 @@ export class ChatPanelComponent implements OnInit, OnDestroy this._fuseSidebarService.getSidebar('chatPanel').toggleFold(); } + /** + * Fold the temporarily unfolded sidebar back + */ + foldSidebarTemporarily(): void + { + this._fuseSidebarService.getSidebar('chatPanel').foldTemporarily(); + } + + /** + * Unfold the sidebar temporarily + */ + unfoldSidebarTemporarily(): void + { + this._fuseSidebarService.getSidebar('chatPanel').unfoldTemporarily(); + } + /** * Toggle sidebar opened status */ @@ -163,8 +184,8 @@ export class ChatPanelComponent implements OnInit, OnDestroy shouldShowContactAvatar(message, i): boolean { return ( - message.who === this.contact.id && - ((this.chat.dialog[i + 1] && this.chat.dialog[i + 1].who !== this.contact.id) || !this.chat.dialog[i + 1]) + message.who === this.selectedContact.id && + ((this.chat.dialog[i + 1] && this.chat.dialog[i + 1].who !== this.selectedContact.id) || !this.chat.dialog[i + 1]) ); } @@ -199,11 +220,11 @@ export class ChatPanelComponent implements OnInit, OnDestroy */ goToChat(contact): void { - // Change the view - this.view = 'chat'; + // Unfold the sidebar temporarily + this.unfoldSidebarTemporarily(); - // Set the current contact - this.contact = contact; + // Set the selected contact + this.selectedContact = contact; // Load the chat this._chatPanelService.getChat(contact.id).then((chat) => { @@ -216,21 +237,6 @@ export class ChatPanelComponent implements OnInit, OnDestroy }); } - /** - * Go to contact view - */ - goToContacts(): void - { - // Change the view - this.view = 'contacts'; - - // Set the current contact as null - this.contact = null; - - // Clear the chat data - this.chat = null; - } - /** * Reply */ diff --git a/src/app/layout/components/chat-panel/chat-panel.module.ts b/src/app/layout/components/chat-panel/chat-panel.module.ts index 8963e64d..5d9eb29b 100644 --- a/src/app/layout/components/chat-panel/chat-panel.module.ts +++ b/src/app/layout/components/chat-panel/chat-panel.module.ts @@ -1,5 +1,5 @@ import { NgModule } from '@angular/core'; -import { MatButtonModule, MatFormFieldModule, MatIconModule, MatInputModule, MatListModule, MatRippleModule, MatTabsModule } from '@angular/material'; +import { MatButtonModule, MatFormFieldModule, MatIconModule, MatInputModule, MatListModule, MatRippleModule, MatTabsModule, MatTooltipModule } from '@angular/material'; import { FuseSharedModule } from '@fuse/shared.module'; @@ -20,6 +20,7 @@ import { ChatPanelService } from 'app/layout/components/chat-panel/chat-panel.se MatInputModule, MatListModule, MatTabsModule, + MatTooltipModule, MatRippleModule, FuseSharedModule diff --git a/src/app/layout/horizontal/layout-1/layout-1.component.html b/src/app/layout/horizontal/layout-1/layout-1.component.html index 7b80c4d4..355985eb 100644 --- a/src/app/layout/horizontal/layout-1/layout-1.component.html +++ b/src/app/layout/horizontal/layout-1/layout-1.component.html @@ -57,7 +57,7 @@ diff --git a/src/app/layout/vertical/layout-1/layout-1.component.html b/src/app/layout/vertical/layout-1/layout-1.component.html index 9a7ff897..4dbbfcd0 100644 --- a/src/app/layout/vertical/layout-1/layout-1.component.html +++ b/src/app/layout/vertical/layout-1/layout-1.component.html @@ -69,7 +69,7 @@ diff --git a/src/app/layout/vertical/layout-2/layout-2.component.html b/src/app/layout/vertical/layout-2/layout-2.component.html index 3b9aa221..46ccb007 100644 --- a/src/app/layout/vertical/layout-2/layout-2.component.html +++ b/src/app/layout/vertical/layout-2/layout-2.component.html @@ -69,7 +69,7 @@ diff --git a/src/app/layout/vertical/layout-3/layout-3.component.html b/src/app/layout/vertical/layout-3/layout-3.component.html index fe908e44..2229d5dc 100644 --- a/src/app/layout/vertical/layout-3/layout-3.component.html +++ b/src/app/layout/vertical/layout-3/layout-3.component.html @@ -55,7 +55,7 @@