This repository has been archived by the owner on Jun 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notifications): navbar dropdown implemented
- Loading branch information
1 parent
dd79cb2
commit 729b82e
Showing
22 changed files
with
411 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
left: 0; | ||
right: 0; | ||
z-index: 10; | ||
border-bottom: 1px solid $app-background-color-darker; | ||
} | ||
|
||
#content { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/app/navbar/navbar-notifications/navbar-notifications.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<div class="notifications"> | ||
<div class="notifications-wrapper"> | ||
|
||
<a matBadge="{{ (newNotifications$ | async).length }}" | ||
matBadgeHidden="{{ (newNotifications$ | async).length === 0 }}" | ||
matBadgeColor="accent" | ||
(focus)="toggleFocus()" | ||
(blur)="toggleBlur()" | ||
mat-button>NOTIFICATIONS</a> | ||
|
||
<ul class="notifications-results" | ||
*ngIf="notificationsToggle || notificationsHover" | ||
(mouseleave)="leftNotifications()" | ||
(mouseenter)="enterNotifications()"> | ||
|
||
<h3 *ngIf="(newNotifications$ | async).length > 0">New notifications</h3> | ||
<li *ngFor="let notification of newNotifications$ | async" | ||
[ngClass]="{'not-seen': !notification.seenAt}" | ||
(click)="openNotification(notification)"> | ||
<button mat-icon-button> | ||
<img aria-label="Profile" | ||
src="https://imageserver.eveonline.com/Character/96361892_64.jpg"/> | ||
</button> | ||
<div class="notification-content"> | ||
<p><strong>Nyota Walker</strong> has posted on <strong>your wall</strong>.</p> | ||
<small class="mat-caption"> | ||
{{ notification.createdAt | amTimeAgo }} {{ notification.seenAt ? '' : ' - Not Seen'}} | ||
</small> | ||
</div> | ||
</li> | ||
|
||
<h3 *ngIf="(otherNotifications$ | async).length > 0">Other notifications</h3> | ||
<li *ngFor="let notification of otherNotifications$ | async" | ||
[ngClass]="{'not-seen': !notification.seenAt}" | ||
(click)="openNotification(notification)"> | ||
<button mat-icon-button> | ||
<img aria-label="Profile" | ||
src="https://imageserver.eveonline.com/Character/96361892_64.jpg"/> | ||
</button> | ||
<div class="notification-content"> | ||
<p><strong>Nyota Walker</strong> has posted on <strong>your wall</strong>.</p> | ||
<small class="mat-caption"> | ||
{{ notification.createdAt | amTimeAgo }} | ||
</small> | ||
</div> | ||
</li> | ||
</ul> | ||
|
||
</div> | ||
</div> | ||
|
||
|
||
|
88 changes: 88 additions & 0 deletions
88
src/app/navbar/navbar-notifications/navbar-notifications.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
@import "../../../variables"; | ||
@import '~@angular/material/theming'; | ||
|
||
.notifications { | ||
|
||
display: flex; | ||
align-items: center; | ||
height: 100%; | ||
width: 100%; | ||
position: relative; | ||
margin: 0 0.5em; | ||
|
||
.notifications-wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
|
||
input { | ||
width: 100%; | ||
border: none; | ||
} | ||
|
||
.notifications-results { | ||
color: #333; | ||
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2), | ||
0 2px 2px 0 rgba(0, 0, 0, 0.14), | ||
0 1px 5px 0 rgba(0, 0, 0, 0.12); | ||
background-color: #f3f3f3; | ||
position: absolute; | ||
width: 350px; | ||
max-height: 70vh; | ||
list-style: none; | ||
padding: 0; | ||
margin: 0; | ||
margin-top: 36px; | ||
overflow: auto; | ||
|
||
h3 { | ||
font-size: 0.6em; | ||
line-height: 2em; | ||
padding-left: 1em; | ||
background: lighten($app-background-color, 50%); | ||
text-transform: uppercase; | ||
} | ||
|
||
li { | ||
display: flex; | ||
flex-direction: row; | ||
padding: .5em; | ||
|
||
&.not-seen { | ||
background: #ffff; | ||
} | ||
|
||
&:hover { | ||
cursor: pointer; | ||
background: lighten($app-background-color, 60%); | ||
} | ||
|
||
.mat-icon-button { | ||
width: 48px; | ||
height: 48px; | ||
margin-right: 12px; | ||
|
||
img { | ||
width: 48px; | ||
height: 48px; | ||
border-radius: 50%; | ||
} | ||
} | ||
|
||
.notification-content { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-around; | ||
|
||
p { | ||
padding: 0; | ||
margin: 0; | ||
white-space: pre-line; // Fixes line going out of parent | ||
font-size: 0.7em; | ||
line-height: 1.2em; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
76 changes: 76 additions & 0 deletions
76
src/app/navbar/navbar-notifications/navbar-notifications.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { select, Store } from '@ngrx/store'; | ||
import { IAppState } from '../../app.store'; | ||
import { DNotification, DNotificationList } from '../../services/notification/notification.dto'; | ||
import { Observable, of } from 'rxjs/index'; | ||
import { filter, map, mergeMap } from 'rxjs/internal/operators'; | ||
import { SeenNotification } from '../../services/notification/notification.actions'; | ||
import * as moment from 'moment'; | ||
|
||
@Component({ | ||
selector: 'app-navbar-notifications', | ||
templateUrl: './navbar-notifications.component.html', | ||
styleUrls: ['./navbar-notifications.component.scss'], | ||
}) | ||
export class NavbarNotificationsComponent implements OnInit { | ||
|
||
notifications$: Observable<DNotificationList>; | ||
newNotifications$: Observable<DNotification[]> = of([]); | ||
otherNotifications$: Observable<DNotification[]> = of([]); | ||
|
||
notificationsHover: boolean = false; | ||
notificationsToggle: boolean = false; | ||
|
||
constructor( | ||
private store: Store<IAppState>, | ||
private router: Router, | ||
) { | ||
this.notifications$ = this.store.pipe(select('notification', 'list')); | ||
} | ||
|
||
ngOnInit() { | ||
this.newNotifications$ = this.notifications$.pipe( | ||
map(notificationsData => notificationsData ? notificationsData.data : []), | ||
map(notifications => notifications.filter(notification => { | ||
return !notification.seenAt && | ||
// Not older than 2 days | ||
moment(notification.createdAt).isAfter(moment().subtract(2, 'day')); | ||
})), | ||
); | ||
this.otherNotifications$ = this.newNotifications$.pipe( | ||
mergeMap(newNotifications => { | ||
return this.notifications$.pipe( | ||
map(notificationsData => notificationsData ? notificationsData.data : []), | ||
map(notifications => notifications.filter(notification => { | ||
return !newNotifications.find( | ||
newNotification => newNotification.id === notification.id); | ||
}), | ||
), | ||
); | ||
}), | ||
); | ||
} | ||
|
||
openNotification(notification: DNotification) { | ||
console.log('Opening notification', notification); | ||
this.store.dispatch(new SeenNotification(notification.id)); | ||
} | ||
|
||
leftNotifications() { | ||
this.notificationsHover = false; | ||
} | ||
|
||
enterNotifications() { | ||
this.notificationsHover = true; | ||
} | ||
|
||
toggleBlur() { | ||
this.notificationsToggle = false; | ||
} | ||
|
||
toggleFocus() { | ||
this.notificationsToggle = true; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/app/navbar/navbar-notifications/navbar-notifications.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { RouterModule } from '@angular/router'; | ||
import { MatBadgeModule, MatButtonModule } from '@angular/material'; | ||
import { NavbarNotificationsComponent } from './navbar-notifications.component'; | ||
import { MomentModule } from 'angular2-moment'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
RouterModule, | ||
MatButtonModule, | ||
MatBadgeModule, | ||
MomentModule, | ||
], | ||
declarations: [NavbarNotificationsComponent], | ||
exports: [NavbarNotificationsComponent], | ||
}) | ||
export class NavbarNotificationsModule { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.