From 420bdde5d31235bf14066bc7b1ea128788a88498 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Fri, 26 Jan 2024 17:59:49 +0200 Subject: [PATCH] RED-8375: fixed bugs. --- .../file-preview-screen.component.ts | 28 +++++++++---------- .../services/file-preview-state.service.ts | 10 ++----- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index f06dde159..8ea6478b0 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -597,27 +597,25 @@ export class FilePreviewScreenComponent .pipe(tap(() => this._handleDeletedFile())) .subscribe(); - const viewModeChanged$ = combineLatest([ - this._documentViewer.loaded$, - this._viewModeService.viewMode$, - this.state.updateExcludedPagesStyle$, - ]).pipe( - map(([loaded, viewMode, shouldUpdate]) => { - if (loaded) { - this._stampService.stampPDF().then(); - } - return viewMode; - }), - ); - - this.addActiveScreenSubscription = combineLatest([viewModeChanged$, this.state.file$]) + this.addActiveScreenSubscription = combineLatest([this._viewModeService.viewMode$, this.state.file$]) .pipe( filter(([viewMode, file]) => viewMode === ViewModes.TEXT_HIGHLIGHTS && !file.hasHighlights), tap(() => this._viewModeService.switchToStandard()), ) .subscribe(); - this.addActiveScreenSubscription = combineLatest([this._documentViewer.pageComplete$, this.state.updateExcludedPagesStyle$]) + this.addActiveScreenSubscription = combineLatest([this._documentViewer.loaded$, this._viewModeService.viewMode$, this.state.file$]) + .pipe( + filter(([loaded, viewMode, shouldUpdate]) => loaded && !!viewMode), + tap(async ([loaded, viewMode, shouldUpdate]) => { + if (loaded) { + await this._stampService.stampPDF(); + } + }), + ) + .subscribe(); + + this.addActiveScreenSubscription = combineLatest([this._documentViewer.pageComplete$, this.state.file$]) .pipe(tap(() => this._setExcludedPageStyles())) .subscribe(); diff --git a/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts b/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts index cc23d5856..44e334477 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts @@ -1,5 +1,5 @@ import { Injectable, Injector } from '@angular/core'; -import { BehaviorSubject, combineLatest, firstValueFrom, from, merge, Observable, of, pairwise, Subject, switchMap } from 'rxjs'; +import { combineLatest, firstValueFrom, from, merge, Observable, of, pairwise, Subject, switchMap } from 'rxjs'; import { Dictionary, Dossier, DOSSIER_ID, DOSSIER_TEMPLATE_ID, File, FILE_ID } from '@red/domain'; import { Router } from '@angular/router'; import { FilesMapService } from '@services/files/files-map.service'; @@ -37,7 +37,6 @@ export class FilePreviewStateService { readonly dossierFileChange$: Observable; readonly isReadonly$: Observable; readonly isWritable$: Observable; - readonly updateExcludedPagesStyle$: Observable; readonly dossierId: string = getParam(DOSSIER_ID); readonly dossierTemplateId: string = getParam(DOSSIER_TEMPLATE_ID); @@ -47,7 +46,6 @@ export class FilePreviewStateService { file: File; #dossierDictionary: Dictionary; readonly #reloadBlob$ = new Subject(); - readonly #updateExcludedPagesStyle$ = new BehaviorSubject([]); constructor( router: Router, @@ -63,12 +61,8 @@ export class FilePreviewStateService { private readonly _loadingService: LoadingService, ) { const dossiersService = dossiersServiceResolver(_injector, router); - this.updateExcludedPagesStyle$ = this.#updateExcludedPagesStyle$.asObservable(); this.dossier$ = dossiersService.getEntityChanged$(this.dossierId).pipe(tap(dossier => (this.dossier = dossier))); - this.file$ = filesMapService.watch$(this.dossierId, this.fileId).pipe( - tap(file => (this.file = file)), - tap(file => this.#updateExcludedPagesStyle$.next(file.excludedPages)), - ); + this.file$ = filesMapService.watch$(this.dossierId, this.fileId).pipe(tap(file => (this.file = file))); [this.isReadonly$, this.isWritable$] = boolFactory( combineLatest([this.file$, this.dossier$]), ([file, dossier]) => !permissionsService.canPerformAnnotationActions(file, dossier),