change icon's color when new notification #55
This commit is contained in:
parent
22b39b3c53
commit
06a9e4abff
|
@ -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;
|
||||||
|
@ -20,12 +23,39 @@ export class ManageAccountComponent implements OnInit {
|
||||||
subPanel = 'account';
|
subPanel = 'account';
|
||||||
hasNotifications = false;
|
hasNotifications = false;
|
||||||
hasMentions = 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 {
|
loadSubPanel(subpanel: string): boolean {
|
||||||
|
|
|
@ -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);
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue