]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/confirm/confirm.service.ts
Merge branch 'develop' into unused-imports
[github/Chocobozzz/PeerTube.git] / client / src / app / core / confirm / confirm.service.ts
CommitLineData
db400f44 1import { first } from 'rxjs/operators'
df98563e 2import { Injectable } from '@angular/core'
db400f44 3import { Subject } from 'rxjs'
5769e1db 4
22b59e80
C
5type ConfirmOptions = {
6 title: string
7 message: string
8 inputLabel?: string
9 expectedInputValue?: string
10 confirmButtonText?: string
11}
12
5769e1db
C
13@Injectable()
14export class ConfirmService {
22b59e80 15 showConfirm = new Subject<ConfirmOptions>()
df98563e 16 confirmResponse = new Subject<boolean>()
5769e1db 17
22b59e80
C
18 confirm (message: string, title = '', confirmButtonText?: string) {
19 this.showConfirm.next({ title, message, confirmButtonText })
5769e1db 20
db400f44 21 return this.confirmResponse.asObservable().pipe(first()).toPromise()
1f30a185
C
22 }
23
22b59e80
C
24 confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) {
25 this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText })
1f30a185 26
db400f44 27 return this.confirmResponse.asObservable().pipe(first()).toPromise()
5769e1db
C
28 }
29}