All files / app/ui-components/task-list task-list.component.ts

100% Statements 12/12
100% Branches 4/4
100% Functions 6/6
100% Lines 12/12

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                1x   4x     4x         4x         4x     1x 3x 3x   1x 3x   1x 2x        
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Task } from '../../models/task.model';
 
@Component({
  selector: 'app-task-list',
  templateUrl: './task-list.component.html',
  styleUrls: ['./task-list.component.css']
})
export class TaskListComponent {
  /** The list of tasks */
   tasksInOrder: Task[] = [];
 
  /** Checks if it's in loading state */
  @Input() loading = false;
 
  /** Event to change the task to pinned */
    // tslint:disable-next-line: no-output-on-prefix
  @Output()
  onPinTask = new EventEmitter<Event>();
 
  /** Event to change the task to archived */
    // tslint:disable-next-line: no-output-on-prefix
  @Output()
  onArchiveTask = new EventEmitter<Event>();
 
  set tasks(arr: Task[]){
    const initialTasks = [
      ...arr.filter(t=>t.state === 'TASK_PINNED'),
      ...arr.filter(t=>t.state !== 'TASK_PINNED'),
    ];
    const filteredTasks = initialTasks.filter(
      t => t.state === 'TASK_INBOX' || t.state === 'TASK_PINNED'
    );
    this.tasksInOrder = filteredTasks.filter(
      t => t.state === 'TASK_INBOX' || t.state === 'TASK_PINNED'
    )
  }
}