Kavita/UI/Web/src/app/_pipes/read-time.pipe.ts
Joe Milazzo 3d8aa2ad24
UX Overhaul Part 2 (#3112)
Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
2024-08-16 17:37:12 -07:00

21 lines
891 B
TypeScript

import { Pipe, PipeTransform } from '@angular/core';
import {IHasReadingTime} from "../_models/common/i-has-reading-time";
import {TranslocoService} from "@jsverse/transloco";
@Pipe({
name: 'readTime',
standalone: true
})
export class ReadTimePipe implements PipeTransform {
constructor(private translocoService: TranslocoService) {}
transform(readingTime: IHasReadingTime): string {
if (readingTime.maxHoursToRead === 0 || readingTime.minHoursToRead === 0) {
return this.translocoService.translate('read-time-pipe.less-than-hour');
} else {
return `${readingTime.minHoursToRead}${readingTime.maxHoursToRead !== readingTime.minHoursToRead ? ('-' + readingTime.maxHoursToRead) : ''}` +
` ${readingTime.minHoursToRead > 1 ? this.translocoService.translate('read-time-pipe.hours') : this.translocoService.translate('read-time-pipe.hour')}`;
}
}
}