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