]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/confirm/confirm.service.ts
Add messages about privacy concerns (P2P)
[github/Chocobozzz/PeerTube.git] / client / src / app / core / confirm / confirm.service.ts
index f12ff184800e7ca2b0eec46f8dc59bcdead51860..d99226f053496f6bf6058b278d1ff5723705c689 100644 (file)
@@ -1,15 +1,30 @@
 import { Injectable } from '@angular/core'
 import { Subject } from 'rxjs/Subject'
 import 'rxjs/add/operator/first'
+import 'rxjs/add/operator/toPromise'
+
+type ConfirmOptions = {
+  title: string
+  message: string
+  inputLabel?: string
+  expectedInputValue?: string
+  confirmButtonText?: string
+}
 
 @Injectable()
 export class ConfirmService {
-  showConfirm = new Subject<{ title, message }>()
+  showConfirm = new Subject<ConfirmOptions>()
   confirmResponse = new Subject<boolean>()
 
-  confirm (message = '', title = '') {
-    this.showConfirm.next({ title, message })
+  confirm (message: string, title = '', confirmButtonText?: string) {
+    this.showConfirm.next({ title, message, confirmButtonText })
+
+    return this.confirmResponse.asObservable().first().toPromise()
+  }
+
+  confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) {
+    this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText })
 
-    return this.confirmResponse.asObservable().first()
+    return this.confirmResponse.asObservable().first().toPromise()
   }
 }