]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/notification/notifier.service.ts
Migrate to $localize
[github/Chocobozzz/PeerTube.git] / client / src / app / core / notification / notifier.service.ts
1 import { MessageService } from 'primeng/api'
2 import { Injectable } from '@angular/core'
3
4 @Injectable()
5 export class Notifier {
6 readonly TIMEOUT = 5000
7
8 constructor (private messageService: MessageService) { }
9
10 info (text: string, title?: string, timeout?: number) {
11 if (!title) title = $localize`Info`
12
13 return this.notify('info', text, title, timeout)
14 }
15
16 error (text: string, title?: string, timeout?: number) {
17 if (!title) title = $localize`Error`
18
19 return this.notify('error', text, title, timeout)
20 }
21
22 success (text: string, title?: string, timeout?: number) {
23 if (!title) title = $localize`Success`
24
25 return this.notify('success', text, title, timeout)
26 }
27
28 private notify (severity: 'success' | 'info' | 'warn' | 'error', text: string, title: string, timeout?: number) {
29 this.messageService.add({
30 severity,
31 summary: title,
32 detail: text,
33 closable: true,
34 life: timeout || this.TIMEOUT
35 })
36 }
37 }