diff --git a/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.html b/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.html index 764e2454f..37411ebe8 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.html +++ b/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.html @@ -1,39 +1,34 @@ - - -
-
-
- {{ comment.user | name }} - {{ comment.date | date: 'sophisticatedDate' }} -
- -
- -
+ +
+
+
+ {{ comment.user | name }} + {{ comment.date | date: 'sophisticatedDate' }}
-
{{ comment.text }}
+
+ +
- - +
{{ comment.text }}
+
+ + + +
- -
- - - diff --git a/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.ts b/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.ts index 214246329..c239b296d 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.ts @@ -1,14 +1,21 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, HostBinding, Input, OnChanges, ViewChild } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component, HostBinding, Input, OnInit, ViewChild } from '@angular/core'; import { Dossier, File, IComment } from '@red/domain'; import { AnnotationWrapper } from '@models/file/annotation.wrapper'; import { UserService } from '@services/user.service'; import { PermissionsService } from '@services/permissions.service'; -import { AutoUnsubscribe, InputWithActionComponent, LoadingService, trackByFactory } from '@iqser/common-ui'; +import { InputWithActionComponent, LoadingService, trackByFactory } from '@iqser/common-ui'; import { firstValueFrom, Observable } from 'rxjs'; import { CommentingService } from '../../services/commenting.service'; import { tap } from 'rxjs/operators'; import { FilePreviewStateService } from '../../services/file-preview-state.service'; import { ManualRedactionService } from '../../services/manual-redaction.service'; +import { ContextComponent } from '@utils/context.component'; + +interface CommentsTemplate { + dossier: Dossier; + file: File; + hiddenComments: boolean; +} @Component({ selector: 'redaction-comments', @@ -16,7 +23,7 @@ import { ManualRedactionService } from '../../services/manual-redaction.service' styleUrls: ['./comments.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class CommentsComponent extends AutoUnsubscribe implements OnChanges { +export class CommentsComponent extends ContextComponent implements OnInit { @Input() annotation: AnnotationWrapper; readonly trackBy = trackByFactory(); readonly file$: Observable; @@ -39,12 +46,18 @@ export class CommentsComponent extends AutoUnsubscribe implements OnChanges { this.dossier$ = _stateService.dossier$; } - ngOnChanges() { + ngOnInit() { this.hiddenComments$ = this._commentingService.isActive$(this.annotation.id).pipe( tap(active => { this._hidden = !active; }), ); + + super._initContext({ + file: this.file$, + dossier: this.dossier$, + hiddenComments: this.hiddenComments$, + }); } async addComment(value: string): Promise { diff --git a/apps/red-ui/src/app/utils/context.component.ts b/apps/red-ui/src/app/utils/context.component.ts new file mode 100644 index 000000000..4adf56774 --- /dev/null +++ b/apps/red-ui/src/app/utils/context.component.ts @@ -0,0 +1,17 @@ +import { combineLatest, Observable, of } from 'rxjs'; +import { map, startWith } from 'rxjs/operators'; +import { ValuesOf } from '@iqser/common-ui'; + +export class ContextComponent { + componentContext$: Observable | null = of({} as T); + + protected _initContext(context: Record>>): void { + const observables = Object.values(context).map(obs => obs.pipe(startWith(null))); + const keys = Object.keys(context); + this.componentContext$ = combineLatest(observables).pipe(map(values => this._mapKeysToObs(keys, values))); + } + + protected _mapKeysToObs(keys: string[], observables: ValuesOf[]): T { + return keys.reduce((acc, key, index) => ({ ...acc, [key]: observables[index] }), {} as T); + } +}