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 { faBell, faEnvelope, faUser, faStar } from "@fortawesome/free-regular-svg-icons";
import { Subscription } from 'rxjs';
import { AccountWrapper } from '../../../models/account.models';
import { UserNotificationServiceService, UserNotification } from '../../../services/user-notification-service.service';
@Component({
selector: 'app-manage-account',
templateUrl: './manage-account.component.html',
styleUrls: ['./manage-account.component.scss']
})
export class ManageAccountComponent implements OnInit {
export class ManageAccountComponent implements OnInit, OnDestroy {
faAt = faAt;
faBell = faBell;
faEnvelope = faEnvelope;
@ -20,12 +23,39 @@ export class ManageAccountComponent implements OnInit {
subPanel = 'account';
hasNotifications = false;
hasMentions = false;
@Input() account: AccountWrapper;
constructor() { }
@Input('account')
set account(acc: AccountWrapper) {
console.warn('account');
this._account = acc;
this.checkNotifications();
}
get account(): AccountWrapper {
return this._account;
}
ngOnInit() {
private userNotificationServiceSub: Subscription;
private _account: AccountWrapper;
constructor(
private readonly userNotificationService: UserNotificationServiceService) { }
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 {

View File

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