Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Better leave page warning modal

Chocobozzz75089d7dc2cf
diff --git a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts
index f85809873e..26b60de852 100644
--- a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts
+++ b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts
@@ -159,7 +159,7 @@ export class PluginListInstalledComponent implements OnInit {
const res = await this.confirmService.confirm(
$localize`This is a major plugin upgrade. Please go on the plugin homepage to check potential release notes.`,
$localize`Upgrade`,
- $localize`Proceed upgrade`
+ { confirmButtonText: $localize`Proceed upgrade` }
)
if (res === false) return
diff --git a/client/src/app/core/confirm/confirm.service.ts b/client/src/app/core/confirm/confirm.service.ts
index abe163aae3..5d70c61d57 100644
--- a/client/src/app/core/confirm/confirm.service.ts
+++ b/client/src/app/core/confirm/confirm.service.ts
@@ -1,35 +1,49 @@
import { firstValueFrom, map, Observable, Subject } from 'rxjs'
import { Injectable } from '@angular/core'
-type ConfirmOptions = {
- title: string
- message: string
- errorMessage?: string
-} & (
- {
- type: 'confirm'
- confirmButtonText?: string
- } |
- {
- type: 'confirm-password'
- confirmButtonText?: string
- isIncorrectPassword?: boolean
- } |
- {
- type: 'confirm-expected-input'
- inputLabel?: string
- expectedInputValue?: string
+type ConfirmOptions =
+ & {
+ title: string
+ message: string
+ errorMessage?: string
confirmButtonText?: string
+ cancelButtonText?: string
}
-)
+ & (
+ | {
+ type: 'confirm'
+ }
+ | {
+ type: 'confirm-password'
+ isIncorrectPassword?: boolean
+ }
+ | {
+ type: 'confirm-expected-input'
+ inputLabel?: string
+ expectedInputValue?: string
+ }
+ )
@Injectable()
export class ConfirmService {
showConfirm = new Subject<ConfirmOptions>()
confirmResponse = new Subject<{ confirmed: boolean, value?: string }>()
- confirm (message: string, title = '', confirmButtonText?: string) {
- this.showConfirm.next({ type: 'confirm', title, message, confirmButtonText })
+ confirm (
+ message: string,
+ title = '',
+ options: {
+ confirmButtonText?: string
+ cancelButtonText?: string
+ } = {}
+ ) {
+ this.showConfirm.next({
+ type: 'confirm',
+ title,
+ message,
+ confirmButtonText: options.confirmButtonText,
+ cancelButtonText: options.cancelButtonText
+ })
return firstValueFrom(this.extractConfirmed(this.confirmResponse.asObservable()))
}
diff --git a/client/src/app/core/routing/can-deactivate-guard.service.ts b/client/src/app/core/routing/can-deactivate-guard.service.ts
index ff617bcd36..677732b0a7 100644
--- a/client/src/app/core/routing/can-deactivate-guard.service.ts
+++ b/client/src/app/core/routing/can-deactivate-guard.service.ts
@@ -3,7 +3,10 @@ import { Observable } from 'rxjs'
import { Injectable, inject } from '@angular/core'
import { ConfirmService } from '@app/core/confirm'
-export type CanComponentDeactivateResult = { text?: string, canDeactivate: Observable<boolean> | boolean }
+export type CanComponentDeactivateResult = {
+ canDeactivate: Observable<boolean> | boolean
+ text?: string
+}
const debugLogger = debug('peertube:routing:CanComponentDeactivate')
@@ -19,12 +22,17 @@ export class CanDeactivateGuard {
const result = component.canDeactivate()
debugLogger('Checking if component can deactivate', result)
+ if (result.canDeactivate) return true
const text = result.text || $localize`All unsaved data will be lost, are you sure you want to leave this page?`
- return result.canDeactivate || this.confirmService.confirm(
+ return this.confirmService.confirm(
text,
- $localize`Warning`
- )
+ $localize`Warning`,
+ {
+ confirmButtonText: $localize`Stay on page`,
+ cancelButtonText: $localize`Leave page`
+ }
+ ).then(result => !result) // Inverse the result, "stay on page" is the primary/default button so we don't leave the page by accident
}
}
diff --git a/client/src/app/modal/confirm.component.html b/client/src/app/modal/confirm.component.html
index 584f6eff04..ae1aa715a3 100644
--- a/client/src/app/modal/confirm.component.html
+++ b/client/src/app/modal/confirm.component.html
@@ -14,16 +14,18 @@
<div *ngIf="inputLabel" class="form-group mt-3">
<label for="confirmInput">{{ inputLabel }}</label>
- <input
- *ngIf="!isPasswordInput" type="text"
- myAutofocus id="confirmInput" name="confirmInput"
- [(ngModel)]="inputValue" (keyup.enter)="confirm()"
- />
-
- <my-input-text
- *ngIf="isPasswordInput" [autofocus]="true" autocomplete="on"
- inputId="confirmInput" [(ngModel)]="inputValue" (keyup.enter)="confirm()"
- ></my-input-text>
+ @if (isPasswordInput) {
+ <my-input-text
+ [autofocus]="true" autocomplete="on"
+ inputId="confirmInput" [(ngModel)]="inputValue" (keyup.enter)="confirm()"
+ ></my-input-text>
+ } @else {
+ <input
+ type="text" myAutofocus id="confirmInput" name="confirmInput"
+ [(ngModel)]="inputValue" (keyup.enter)="confirm()"
+ />
+ }
+
</div>
<div *ngIf="hasError()" class="text-danger">{{ errorMessage }}</div>
@@ -31,7 +33,7 @@
<div class="modal-footer inputs">
<input
- type="button" role="button" i18n-value value="Cancel" class="peertube-button secondary-button"
+ type="button" role="button" [value]="cancelButtonText" class="peertube-button secondary-button"
(click)="dismiss()" (key.enter)="dismiss()"
>
diff --git a/client/src/app/modal/confirm.component.ts b/client/src/app/modal/confirm.component.ts
index f6053cc8f6..2be201a267 100644
--- a/client/src/app/modal/confirm.component.ts
+++ b/client/src/app/modal/confirm.component.ts
@@ -28,6 +28,7 @@ export class ConfirmComponent implements OnInit {
inputLabel = ''
inputValue = ''
+ cancelButtonText = ''
confirmButtonText = ''
errorMessage = ''
@@ -49,7 +50,7 @@ export class ConfirmComponent implements OnInit {
this.isPasswordInput = false
this.errorMessage = ''
- const { type, title, message, confirmButtonText, errorMessage } = payload
+ const { type, title, message, confirmButtonText, cancelButtonText, errorMessage } = payload
this.title = title
@@ -63,6 +64,7 @@ export class ConfirmComponent implements OnInit {
}
this.confirmButtonText = confirmButtonText || $localize`Confirm`
+ this.cancelButtonText = cancelButtonText || $localize`Cancel`
this.html.toSimpleSafeHtml(message)
.then(html => {