fix: hide show-more button when description fits without truncation (#2766)

This commit is contained in:
ACX
2026-02-15 11:57:56 -07:00
committed by GitHub
parent 2c391cb1f4
commit 1cc30af7d9
4 changed files with 26 additions and 9 deletions
@@ -77,13 +77,12 @@
<!-- DESCRIPTION --> <!-- DESCRIPTION -->
<div class="description-box"> <div class="description-box">
<div [ngClass]="{ 'line-clamp-5': !isExpanded, 'line-clamp-none': isExpanded }" <div #descriptionContent [ngClass]="{ 'line-clamp-5': !isExpanded, 'line-clamp-none': isExpanded }"
class="description-container"> class="description-container">
<div class="readonly-editor" <div class="readonly-editor"
[innerHTML]="(firstDescription$ | async) || t('noDescription')"></div> [innerHTML]="(firstDescription$ | async) || t('noDescription')"></div>
</div> </div>
@let desc = firstDescription$ | async; @if (isExpanded || isOverflowing) {
@if ((desc?.length ?? 0) > 500) {
<p-button [label]="isExpanded ? t('showLess') : t('showMore')" <p-button [label]="isExpanded ? t('showLess') : t('showMore')"
[icon]="isExpanded ? 'pi pi-chevron-up' : 'pi pi-chevron-down'" iconPos="right" size="small" text [icon]="isExpanded ? 'pi pi-chevron-up' : 'pi pi-chevron-down'" iconPos="right" size="small" text
(click)="toggleExpand()"> (click)="toggleExpand()">
@@ -27,7 +27,7 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
import {Tooltip} from "primeng/tooltip"; import {Tooltip} from "primeng/tooltip";
import {Divider} from "primeng/divider"; import {Divider} from "primeng/divider";
import {animate, style, transition, trigger} from "@angular/animations"; import {animate, style, transition, trigger} from "@angular/animations";
import {Component, inject, OnDestroy} from '@angular/core'; import {AfterViewChecked, Component, ElementRef, inject, OnDestroy, ViewChild} from '@angular/core';
import {BookCardOverlayPreferenceService} from '../book-browser/book-card-overlay-preference.service'; import {BookCardOverlayPreferenceService} from '../book-browser/book-card-overlay-preference.service';
@Component({ @Component({
@@ -68,7 +68,7 @@ import {BookCardOverlayPreferenceService} from '../book-browser/book-card-overla
]) ])
] ]
}) })
export class SeriesPageComponent implements OnDestroy { export class SeriesPageComponent implements OnDestroy, AfterViewChecked {
private route = inject(ActivatedRoute); private route = inject(ActivatedRoute);
private bookService = inject(BookService); private bookService = inject(BookService);
@@ -88,8 +88,10 @@ export class SeriesPageComponent implements OnDestroy {
protected appSettingsService = inject(AppSettingsService); protected appSettingsService = inject(AppSettingsService);
private readonly t = inject(TranslocoService); private readonly t = inject(TranslocoService);
@ViewChild('descriptionContent') descriptionContentRef?: ElementRef<HTMLElement>;
tab: string = "view"; tab: string = "view";
isExpanded = false; isExpanded = false;
isOverflowing = false;
// Selection state // Selection state
selectedBooks = new Set<number>(); selectedBooks = new Set<number>();
@@ -268,6 +270,13 @@ export class SeriesPageComponent implements OnDestroy {
} }
} }
ngAfterViewChecked(): void {
if (!this.isExpanded && this.descriptionContentRef) {
const el = this.descriptionContentRef.nativeElement;
this.isOverflowing = el.scrollHeight > el.clientHeight;
}
}
toggleExpand(): void { toggleExpand(): void {
this.isExpanded = !this.isExpanded; this.isExpanded = !this.isExpanded;
} }
@@ -670,10 +670,10 @@
<span>{{ t('synopsisTitle') }}</span> <span>{{ t('synopsisTitle') }}</span>
</div> </div>
<div class="description-body"> <div class="description-body">
<div [ngClass]="{ 'line-clamp-7': !isExpanded }" class="description-content"> <div #descriptionContent [ngClass]="{ 'line-clamp-7': !isExpanded }" class="description-content">
<div class="description-html" [innerHTML]="book.metadata!.description"></div> <div class="description-html" [innerHTML]="book.metadata!.description"></div>
</div> </div>
@if (book.metadata!.description && book.metadata!.description.length > 500) { @if (isExpanded || isOverflowing) {
<button class="expand-toggle" (click)="toggleExpand()"> <button class="expand-toggle" (click)="toggleExpand()">
{{ isExpanded ? t('showLess') : t('showMore') }} {{ isExpanded ? t('showLess') : t('showMore') }}
<i class="pi" [ngClass]="isExpanded ? 'pi-chevron-up' : 'pi-chevron-down'"></i> <i class="pi" [ngClass]="isExpanded ? 'pi-chevron-up' : 'pi-chevron-down'"></i>
@@ -1,4 +1,4 @@
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core'; import {AfterViewChecked, Component, DestroyRef, ElementRef, inject, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from '@angular/core';
import {Button} from 'primeng/button'; import {Button} from 'primeng/button';
import {AsyncPipe, DecimalPipe, NgClass} from '@angular/common'; import {AsyncPipe, DecimalPipe, NgClass} from '@angular/common';
import {combineLatest, Observable} from 'rxjs'; import {combineLatest, Observable} from 'rxjs';
@@ -44,7 +44,7 @@ import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/tran
styleUrl: './metadata-viewer.component.scss', styleUrl: './metadata-viewer.component.scss',
imports: [Button, AsyncPipe, Rating, FormsModule, SplitButton, NgClass, Tooltip, DecimalPipe, ProgressBar, Menu, DatePicker, ProgressSpinner, TieredMenu, Image, TagComponent, MetadataTabsComponent, TranslocoDirective, TranslocoPipe] imports: [Button, AsyncPipe, Rating, FormsModule, SplitButton, NgClass, Tooltip, DecimalPipe, ProgressBar, Menu, DatePicker, ProgressSpinner, TieredMenu, Image, TagComponent, MetadataTabsComponent, TranslocoDirective, TranslocoPipe]
}) })
export class MetadataViewerComponent implements OnInit, OnChanges { export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChecked {
@Input() book$!: Observable<Book | null>; @Input() book$!: Observable<Book | null>;
@Input() recommendedBooks: BookRecommendation[] = []; @Input() recommendedBooks: BookRecommendation[] = [];
private originalRecommendedBooks: BookRecommendation[] = []; private originalRecommendedBooks: BookRecommendation[] = [];
@@ -70,7 +70,9 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
otherItems$!: Observable<MenuItem[]>; otherItems$!: Observable<MenuItem[]>;
downloadMenuItems$!: Observable<MenuItem[]>; downloadMenuItems$!: Observable<MenuItem[]>;
bookInSeries: Book[] = []; bookInSeries: Book[] = [];
@ViewChild('descriptionContent') descriptionContentRef?: ElementRef<HTMLElement>;
isExpanded = false; isExpanded = false;
isOverflowing = false;
isComicSectionExpanded = true; isComicSectionExpanded = true;
isAudiobookSectionExpanded = true; isAudiobookSectionExpanded = true;
showFilePath = false; showFilePath = false;
@@ -460,6 +462,13 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
); );
} }
ngAfterViewChecked(): void {
if (!this.isExpanded && this.descriptionContentRef) {
const el = this.descriptionContentRef.nativeElement;
this.isOverflowing = el.scrollHeight > el.clientHeight;
}
}
toggleExpand(): void { toggleExpand(): void {
this.isExpanded = !this.isExpanded; this.isExpanded = !this.isExpanded;
} }