mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-16 03:41:30 +03:00
Completed notification functionality
Minor code cleanup
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<div *ngFor="let notification of notifications; let i = index;">
|
||||
<mat-divider class="notification-divider"></mat-divider>
|
||||
<div style="display: inline-block">
|
||||
<ng-container *ngIf="NOTIFICATION_PREFIX[notification.type]">
|
||||
{{NOTIFICATION_PREFIX[notification.type]}}
|
||||
</ng-container>
|
||||
<ng-container *ngIf="NOTIFICATION_SUFFIX_KEY[notification.type]">
|
||||
{{notification['data'][NOTIFICATION_SUFFIX_KEY[notification.type]]}}
|
||||
</ng-container>
|
||||
</div>
|
||||
<div style="margin-left: 10px; float: right;" *ngIf="notification.actions?.length > 0">
|
||||
<button (click)="emitDeleteNotification(notification.uid)" mat-icon-button><mat-icon>close</mat-icon></button>
|
||||
<span *ngFor="let action of notification.actions">
|
||||
<button [matTooltip]="NOTIFICATION_ACTION_TO_STRING[action]" (click)="emitNotificationAction(notification)" mat-icon-button><mat-icon>{{NOTIFICATION_ICON[action]}}</mat-icon></button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,4 @@
|
||||
.notification-divider {
|
||||
margin-bottom: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NotificationsListComponent } from './notifications-list.component';
|
||||
|
||||
describe('NotificationsListComponent', () => {
|
||||
let component: NotificationsListComponent;
|
||||
let fixture: ComponentFixture<NotificationsListComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ NotificationsListComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(NotificationsListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||
import { Notification } from 'api-types';
|
||||
import { NotificationAction } from 'api-types/models/NotificationAction';
|
||||
import { NotificationType } from 'api-types/models/NotificationType';
|
||||
|
||||
@Component({
|
||||
selector: 'app-notifications-list',
|
||||
templateUrl: './notifications-list.component.html',
|
||||
styleUrls: ['./notifications-list.component.scss']
|
||||
})
|
||||
export class NotificationsListComponent {
|
||||
@Input() notifications = null;
|
||||
@Output() deleteNotification = new EventEmitter<string>();
|
||||
@Output() notificationAction = new EventEmitter<{notification: Notification, action: NotificationAction}>();
|
||||
|
||||
NOTIFICATION_PREFIX: { [key in NotificationType]: string } = {
|
||||
download_complete: $localize`Finished downloading:`,
|
||||
download_error: $localize`Download failed:`
|
||||
}
|
||||
|
||||
// Attaches string to the end of the notification text
|
||||
NOTIFICATION_SUFFIX_KEY: { [key in NotificationType]: string } = {
|
||||
download_complete: 'file_title',
|
||||
download_error: 'file_url'
|
||||
}
|
||||
|
||||
NOTIFICATION_ACTION_TO_STRING: { [key in NotificationAction]: string } = {
|
||||
play: $localize`Play`,
|
||||
retry_download: $localize`Retry download`,
|
||||
view_download_error: $localize`View error`
|
||||
}
|
||||
|
||||
NOTIFICATION_COLOR: { [key in NotificationAction]: string } = {
|
||||
play: 'primary',
|
||||
retry_download: 'primary',
|
||||
view_download_error: 'warn'
|
||||
}
|
||||
|
||||
NOTIFICATION_ICON: { [key in NotificationAction]: string } = {
|
||||
play: 'smart_display',
|
||||
retry_download: 'restart_alt',
|
||||
view_download_error: 'warning'
|
||||
}
|
||||
|
||||
emitNotificationAction(notification: Notification, action: NotificationAction): void {
|
||||
this.notificationAction.emit({notification: notification, action: action});
|
||||
}
|
||||
|
||||
emitDeleteNotification(uid: string): void {
|
||||
this.deleteNotification.emit(uid);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user