All files / src/app/components/themes themes.component.ts

100% Statements 18/18
75% Branches 3/4
100% Functions 10/10
100% Lines 16/16

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                          157x 47x     47x     47x   47x     47x       58x   57x     58x   58x           9x 3x 3x       2x       11x 11x      
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { TabsModule } from 'primeng/tabs';
import { ThemeBuilderComponent } from '../theme-builder/theme-builder.component';
import { GraphTheme } from '../../models/colorSetting';
import { TwinpadApiService } from '../../services/twinpad-api.service';
import { ThemesListComponent } from '../themes-list/themes-list.component';
 
@Component({
  selector: 'app-themes',
  imports: [TabsModule, ThemeBuilderComponent, ThemesListComponent, ],
  templateUrl: './themes.component.html',
  styleUrl: './themes.component.scss'
})
export class ThemesComponent implements OnInit {
  @Output() themesChangedEvent = new EventEmitter();
  libraryThemes: GraphTheme[];
  marketplaceThemes: GraphTheme[];
  selectedTab: number = 0;
 
  activeGraphTheme: GraphTheme;
  editMode: boolean = false;
 
  constructor(private twinpadApiService: TwinpadApiService) {}
 
  ngOnInit(): void {
    this.updateThemesLists();
  }
 
  updateThemesLists() {
    this.twinpadApiService.getFavoriteGraphThemes().subscribe({
      next: graphThemes => {
        this.libraryThemes = graphThemes.items;
      }
    });
    this.twinpadApiService.getGraphThemes().subscribe({
      next: graphThemes => {
        this.marketplaceThemes = graphThemes.items;
      }
    });
  }
 
  editTheme(themeId: string) {
    this.activeGraphTheme = this.libraryThemes.find(theme => theme.id === themeId) ?? new GraphTheme();
    this.editMode = true;
    this.selectedTab = 2;
  }
 
  cancelEdit() {
    this.editMode = false;
  }
 
  handleThemesChanged() {
    this.themesChangedEvent.emit();
    this.updateThemesLists();
  }
}