Skip to content

Commit

Permalink
#175 make users aware of unsaved changes when closing browser tab
Browse files Browse the repository at this point in the history
  • Loading branch information
a-kikhia committed Jan 6, 2025
1 parent 05ca02c commit 356970c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AfterViewInit,
ChangeDetectorRef,
Component,
HostListener,
OnInit,
ViewChild,
} from '@angular/core';
Expand Down Expand Up @@ -31,6 +32,7 @@ import {
} from './domain/entities/constants';
import { MatSnackBar } from '@angular/material/snack-bar';
import { ModelerService } from './tools/modeler/services/modeler.service';
import { DirtyFlagService } from './domain/services/dirty-flag.service';

@Component({
selector: 'app-root',
Expand Down Expand Up @@ -73,6 +75,7 @@ export class AppComponent implements OnInit, AfterViewInit {
private snackbar: MatSnackBar,
replayService: ReplayService,
private modelerService: ModelerService,
private dirtyFlagService: DirtyFlagService,
) {
this.showSettings$ = new BehaviorSubject(false);
this.showDescription$ = new BehaviorSubject(true);
Expand Down Expand Up @@ -164,4 +167,11 @@ export class AppComponent implements OnInit, AfterViewInit {
this.autosaveService.loadLatestDraft();
this.cd.detectChanges();
}

@HostListener('window:beforeunload', ['$event'])
onWindowClose(event: any): void {
if (this.dirtyFlagService.dirty) {
event.returnValue = true;
}
}
}

0 comments on commit 356970c

Please sign in to comment.