change icon's color when new notification #55

This commit is contained in:
Nicolas Constant 2019-03-24 21:11:23 -04:00
parent 22b39b3c53
commit 06a9e4abff
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 37 additions and 7 deletions

View File

@ -1,15 +1,18 @@
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit, OnDestroy, Input } from '@angular/core';
import { faAt, faUserPlus } from "@fortawesome/free-solid-svg-icons"; import { faAt, faUserPlus } from "@fortawesome/free-solid-svg-icons";
import { faBell, faEnvelope, faUser, faStar } from "@fortawesome/free-regular-svg-icons"; import { faBell, faEnvelope, faUser, faStar } from "@fortawesome/free-regular-svg-icons";
import { Subscription } from 'rxjs';
import { AccountWrapper } from '../../../models/account.models'; import { AccountWrapper } from '../../../models/account.models';
import { UserNotificationServiceService, UserNotification } from '../../../services/user-notification-service.service';
@Component({ @Component({
selector: 'app-manage-account', selector: 'app-manage-account',
templateUrl: './manage-account.component.html', templateUrl: './manage-account.component.html',
styleUrls: ['./manage-account.component.scss'] styleUrls: ['./manage-account.component.scss']
}) })
export class ManageAccountComponent implements OnInit { export class ManageAccountComponent implements OnInit, OnDestroy {
faAt = faAt; faAt = faAt;
faBell = faBell; faBell = faBell;
faEnvelope = faEnvelope; faEnvelope = faEnvelope;
@ -21,11 +24,38 @@ export class ManageAccountComponent implements OnInit {
hasNotifications = false; hasNotifications = false;
hasMentions = false; hasMentions = false;
@Input() account: AccountWrapper; @Input('account')
set account(acc: AccountWrapper) {
console.warn('account');
this._account = acc;
this.checkNotifications();
}
get account(): AccountWrapper {
return this._account;
}
constructor() { } private userNotificationServiceSub: Subscription;
private _account: AccountWrapper;
constructor(
private readonly userNotificationService: UserNotificationServiceService) { }
ngOnInit() { ngOnInit() {
}
ngOnDestroy(): void {
this.userNotificationServiceSub.unsubscribe();
}
private checkNotifications(){
this.userNotificationServiceSub = this.userNotificationService.userNotifications.subscribe((userNotifications: UserNotification[]) => {
const userNotification = userNotifications.find(x => x.account.id === this.account.info.id);
if(userNotification){
this.hasNotifications = userNotification.hasNewNotifications;
this.hasMentions = userNotification.hasNewMentions;
}
});
} }
loadSubPanel(subpanel: string): boolean { loadSubPanel(subpanel: string): boolean {

View File

@ -27,7 +27,7 @@ export class UserNotificationServiceService {
let promises: Promise<any>[] = []; let promises: Promise<any>[] = [];
accounts.forEach(account => { accounts.forEach(account => {
let getNotificationPromise = this.mastodonService.getNotifications(account) let getNotificationPromise = this.mastodonService.getNotifications(account, null, null, null, 30)
.then((notifications: Notification[]) => { .then((notifications: Notification[]) => {
this.processNotifications(account, notifications); this.processNotifications(account, notifications);
}) })