mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Fix browser unsaved changes with custom guard
This commit is contained in:
20
src-ui/src/app/guards/dirty-doc.guard.ts
Normal file
20
src-ui/src/app/guards/dirty-doc.guard.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { CanDeactivate } from '@angular/router'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Observable } from 'rxjs'
|
||||
|
||||
export interface ComponentCanDeactivate {
|
||||
canDeactivate: () => boolean | Observable<boolean>
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DirtyDocGuard implements CanDeactivate<ComponentCanDeactivate> {
|
||||
canDeactivate(
|
||||
component: ComponentCanDeactivate
|
||||
): boolean | Observable<boolean> {
|
||||
return component.canDeactivate()
|
||||
? true
|
||||
: confirm(
|
||||
$localize`Warning: You have unsaved changes to your document(s).`
|
||||
)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user