All files / app/layout/right-sidebar right-sidebar.component.ts

100% Statements 23/23
80% Branches 8/10
100% Functions 9/9
100% Lines 19/19

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 453x 3x   3x                 3x 44x   44x 44x     44x 45x 45x       44x 47x 47x     44x 18x 52x       4x       2x 2x      
import { Component, ChangeDetectionStrategy, inject, signal, computed, effect } from '@angular/core';
import { SidebarService } from '@drevo-web/core';
import { SidebarAction } from '@drevo-web/shared';
import { ActionButtonComponent } from '@drevo-web/ui';
 
@Component({
    selector: 'app-right-sidebar',
    imports: [ActionButtonComponent],
    templateUrl: './right-sidebar.component.html',
    styleUrl: './right-sidebar.component.scss',
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RightSidebarComponent {
    private readonly sidebarService = inject(SidebarService);
 
    readonly actions = this.sidebarService.actions;
    readonly menuOpen = signal(false);
 
    constructor() {
        effect(() => {
            this.actions();
            this.menuOpen.set(false);
        });
    }
 
    readonly mainAction = computed<SidebarAction | undefined>(() => {
        const all = this.actions();
        return all.find(a => a.priority === 'primary') ?? all[0];
    });
 
    readonly menuActions = computed(() => {
        const main = this.mainAction();
        return main ? this.actions().filter(a => a.id !== main.id) : [];
    });
 
    toggleMenu(): void {
        this.menuOpen.update(open => !open);
    }
 
    handleSpeedDialAction(action: SidebarAction): void {
        action.action?.();
        this.menuOpen.set(false);
    }
}