All files / app/component/comment/thread-summary thread-summary.component.ts

83.33% Statements 25/30
78.57% Branches 11/14
55.55% Functions 5/9
88% Lines 22/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 7776x             76x 76x 76x                 158x         76x 2x     2x   2x   2x   2x   2x   2x   2x       2x 2x     2x 2x       2x               1x 1x 1x                            
import { DestroyRef, inject, Component, forwardRef, Input, OnChanges, OnInit, SimpleChanges, ChangeDetectionStrategy } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { MobxAngularModule } from 'mobx-angular';
import { Observable } from 'rxjs';
import { Ref } from '../../../model/ref';
import { RefService } from '../../../service/api/ref.service';
import { Store } from '../../../store/store';
import { getArgs } from '../../../util/query';
import { RefComponent } from '../../ref/ref.component';
import { CommentComponent } from '../comment.component';
 
@Component({
  selector: 'app-thread-summary',
  templateUrl: './thread-summary.component.html',
  styleUrls: ['./thread-summary.component.scss'],
  host: { 'class': 'thread-summary' },
  changeDetection: ChangeDetectionStrategy.Eager,
  imports: [
    forwardRef(() => CommentComponent),
    forwardRef(() => RefComponent),
    MobxAngularModule,
  ]
})
export class ThreadSummaryComponent implements OnInit, OnChanges {
  private destroyRef = inject(DestroyRef);
 
  @Input()
  source = '';
  @Input()
  commentView = false;
  @Input()
  query = '';
  @Input()
  depth = 1;
  @Input()
  pageSize = 5;
  @Input()
  context = 0;
  @Input()
  showLoadMore = true;
  @Input()
  newRefs$?: Observable<Ref | undefined>;
 
  newRefs: Ref[] = [];
  list: Ref[] = [];
 
  constructor(
    private refs: RefService,
    private store: Store,
  ) { }
 
  ngOnInit(): void {
    this.newRefs$?.pipe(
      takeUntilDestroyed(this.destroyRef),
    ).subscribe(comment => {
      if (comment) this.newRefs = [comment, ...this.newRefs];
    });
  }
 
  ngOnChanges(changes: SimpleChanges) {
    Eif (changes.source) {
      this.newRefs = [];
      this.refs.page({
        ...getArgs(this.query, this.store.view.sort, this.store.view.filter),
        responses: this.source,
        size: this.pageSize,
      }).pipe(
        takeUntilDestroyed(this.destroyRef)
      ).subscribe(page => {
        this.list = page.content;
      });
    }
  }
 
 
}