1- import { ChangeDetectionStrategy , Component , Input , OnDestroy } from "@angular/core" ;
1+ import { ChangeDetectionStrategy , ChangeDetectorRef , Component , Input , OnDestroy } from "@angular/core" ;
22import { EMPTY , Subject } from "rxjs" ;
33import { Store , select } from "@ngrx/store" ;
4- import { concatMap , mergeMap , takeUntil } from "rxjs/operators" ;
4+ import { concatMap , filter , finalize , mergeMap , takeUntil , throttleTime } from "rxjs/operators" ;
55
66import { CORE_ACTIONS , DB_VIEW_ACTIONS } from "src/web/src/app/store/actions" ;
77import { DbAccountPk , MAIL_FOLDER_TYPE , Mail , View } from "src/shared/model/database" ;
@@ -19,6 +19,8 @@ import {ToggleFolderMetadataPropEmitter} from "./db-view-mails.component";
1919 changeDetection : ChangeDetectionStrategy . OnPush ,
2020} )
2121export class DbViewMailTabComponent extends NgChangesObservableComponent implements OnDestroy {
22+ exporting ?: boolean ;
23+
2224 @Input ( )
2325 dbAccountPk ! : DbAccountPk ;
2426
@@ -65,6 +67,7 @@ export class DbViewMailTabComponent extends NgChangesObservableComponent impleme
6567 constructor (
6668 private store : Store < State > ,
6769 private api : ElectronService ,
70+ private changeDetectorRef : ChangeDetectorRef ,
6871 ) {
6972 super ( ) ;
7073 }
@@ -87,9 +90,23 @@ export class DbViewMailTabComponent extends NgChangesObservableComponent impleme
8790
8891 export ( ) {
8992 this . api . ipcMainClient ( { timeoutMs : ONE_SECOND_MS * 60 * 5 } ) ( "dbExport" ) ( this . dbAccountPk )
90- . pipe ( takeUntil ( this . unSubscribe$ ) )
93+ . pipe (
94+ takeUntil ( this . unSubscribe$ ) ,
95+ filter ( ( value ) => "progress" in value ) ,
96+ throttleTime ( ONE_SECOND_MS / 2 ) ,
97+ finalize ( ( ) => {
98+ delete this . exporting ;
99+ this . changeDetectorRef . detectChanges ( ) ;
100+ } ) ,
101+ )
91102 . subscribe (
92- ( ) => { } ,
103+ ( ) => {
104+ if ( this . exporting ) {
105+ return ;
106+ }
107+ this . exporting = true ;
108+ this . changeDetectorRef . detectChanges ( ) ;
109+ } ,
93110 ( error ) => this . store . dispatch ( CORE_ACTIONS . Fail ( error ) ) ,
94111 ) ;
95112 }
0 commit comments