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

80.64% Statements 25/31
71.42% Branches 10/14
57.14% Functions 4/7
80% Lines 20/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 77 78 792x           2x 2x 2x                         3x 1x     1x   1x   1x   1x   1x   1x   1x       1x 1x     1x 1x       1x                                             1x 1x        
import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
import { MobxAngularModule } from 'mobx-angular';
import { Observable, Subject, takeUntil } 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' },
  imports: [
    CommentComponent,
    RefComponent,
    MobxAngularModule,
  ]
})
export class ThreadSummaryComponent implements OnInit, OnChanges, OnDestroy {
  private destroy$ = new Subject<void>();
 
  @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(
      takeUntil(this.destroy$),
    ).subscribe(comment => {
      if (comment) this.newRefs = [comment, ...this.newRefs];
    });
  }
 
  ngOnChanges(changes: SimpleChanges) {
    if (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(
        takeUntil(this.destroy$)
      ).subscribe(page => {
        this.list = page.content;
      });
    }
  }
 
  ngOnDestroy() {
    this.destroy$.next();
    this.destroy$.complete();
  }
 
}