]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/notification/notifier.service.ts
Fetch things in bulk for the homepage
[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, sticky?: boolean) {
11 if (!title) title = $localize`Info`
12
13 console.info(`${title}: ${text}`)
14 return this.notify('info', text, title, timeout, sticky)
15 }
16
17 error (text: string, title?: string, timeout?: number, sticky?: boolean) {
18 if (!title) title = $localize`Error`
19
20 console.error(`${title}: ${text}`)
21 return this.notify('error', text, title, timeout, sticky)
22 }
23
24 success (text: string, title?: string, timeout?: number, sticky?: boolean) {
25 if (!title) title = $localize`Success`
26
27 console.log(`${title}: ${text}`)
28 return this.notify('success', text, title, timeout, sticky)
29 }
30
31 private notify (severity: 'success' | 'info' | 'warn' | 'error', text: string, title: string, timeout?: number, sticky?: boolean) {
32 this.messageService.add({
33 severity,
34 summary: title,
35 detail: text,
36 closable: true,
37 life: timeout || this.TIMEOUT,
38 sticky
39 })
40 }
41 }