]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/confirm/confirm.service.ts
Translated using Weblate (German)
[github/Chocobozzz/PeerTube.git] / client / src / app / core / confirm / confirm.service.ts
index b9796979591754d23999796d76748ed7084f7fc8..338b8762c97d83a3dcd5d96b9c6cc0f5f16dce24 100644 (file)
@@ -1,15 +1,28 @@
-import { Injectable } from '@angular/core';
-import { Subject } from 'rxjs/Subject';
-import 'rxjs/add/operator/first';
+import { firstValueFrom, Subject } from 'rxjs'
+import { Injectable } from '@angular/core'
+
+type ConfirmOptions = {
+  title: string
+  message: string
+  inputLabel?: string
+  expectedInputValue?: string
+  confirmButtonText?: string
+}
 
 @Injectable()
 export class ConfirmService {
-  showConfirm = new Subject<{ title, message }>();
-  confirmResponse = new Subject<boolean>();
+  showConfirm = new Subject<ConfirmOptions>()
+  confirmResponse = new Subject<boolean>()
+
+  confirm (message: string, title = '', confirmButtonText?: string) {
+    this.showConfirm.next({ title, message, confirmButtonText })
+
+    return firstValueFrom(this.confirmResponse.asObservable())
+  }
 
-  confirm(message: string = '', title: string = '') {
-    this.showConfirm.next({ title, message });
+  confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) {
+    this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText })
 
-    return this.confirmResponse.asObservable().first();
+    return firstValueFrom(this.confirmResponse.asObservable())
   }
 }