All files / app/components/image-gallery image-gallery.component.ts

64.28% Statements 9/14
100% Branches 0/0
44.44% Functions 4/9
69.23% Lines 9/13

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                        1x 4x 4x   4x     4x       2x 2x     2x           4x                      
import { Component, inject, OnInit } from '@angular/core';
import { ImageService } from '../../services/image.service';
import { ImageMetadata } from '../../models/image-metadata.model';
import { CommonModule } from '@angular/common';
import { ImageStateService } from '../../services/image-state.service';
 
@Component({
  selector: 'app-image-gallery',
  templateUrl: './image-gallery.component.html',
  styleUrls: ['./image-gallery.component.scss'],
  imports: [CommonModule]
})
export class ImageGalleryComponent implements OnInit {
  private imageService = inject(ImageService);
  private imageState = inject(ImageStateService);
 
  images: ImageMetadata[] = [];
 
  constructor() {
    this.loadImages();
  }
 
   ngOnInit(): void {
    this.imageState.images$.subscribe(images => {
      this.images = images;
    });
 
    this.imageService.getAllImages().subscribe(images => {
      this.imageState.setImages(images);
    });
  }
 
  loadImages(): void {
    this.imageService.getAllImages().subscribe((data: ImageMetadata[]) => {
      this.images = data;
    });
  }
 
  deleteImage(id: number): void {
    this.imageService.deleteImage(id).subscribe(() => {
      this.images = this.images.filter(image => image.id !== id);
    });
  }
}