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