All files / app/features/picture/components/pending-banner pending-banner.component.ts

100% Statements 22/22
100% Branches 3/3
100% Functions 7/7
100% Lines 18/18

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 402x   2x   2x                 2x 41x 41x 41x 41x 41x 41x   41x 41x 41x 41x 41x       41x     12x       4x      
import { PENDING_TYPE_LABELS } from '../../../../shared/constants/pending-type-labels';
import { PendingAction } from '../../models/pending.model';
import { ChangeDetectionStrategy, Component, computed, input, output } from '@angular/core';
import { PicturePending } from '@drevo-web/shared';
import { BannerComponent, ButtonComponent, IconComponent } from '@drevo-web/ui';
 
@Component({
    selector: 'app-pending-banner',
    imports: [BannerComponent, ButtonComponent, IconComponent],
    templateUrl: './pending-banner.component.html',
    styleUrl: './pending-banner.component.scss',
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PendingBannerComponent {
    readonly pending = input.required<PicturePending>();
    readonly currentUserName = input.required<string>();
    readonly canModerate = input.required<boolean>();
    readonly isBusy = input(false);
    readonly action = output<{ readonly pending: PicturePending; readonly action: PendingAction }>();
    readonly imageClick = output<PicturePending>();
 
    readonly isOwn = computed(() => this.pending().user === this.currentUserName());
    readonly pendingLabel = computed(() => PENDING_TYPE_LABELS[this.pending().pendingType]);
    readonly hasNewTitle = computed(() => {
        const pending = this.pending();
        return (
            pending.title !== undefined && (pending.pendingType === 'edit_title' || pending.pendingType === 'edit_both')
        );
    });
    readonly hasNewImage = computed(() => this.pending().pendingImageUrl !== undefined);
 
    emitAction(action: PendingAction): void {
        this.action.emit({ pending: this.pending(), action });
    }
 
    emitImageClick(): void {
        this.imageClick.emit(this.pending());
    }
}