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 -->
<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">
<div class="readonly-editor"
[innerHTML]="(firstDescription$ | async) || t('noDescription')"></div>
</div>
@let desc = firstDescription$ | async;
@if ((desc?.length ?? 0) > 500) {
@if (isExpanded || isOverflowing) {
<p-button [label]="isExpanded ? t('showLess') : t('showMore')"
[icon]="isExpanded ? 'pi pi-chevron-up' : 'pi pi-chevron-down'" iconPos="right" size="small" text
(click)="toggleExpand()">
@@ -27,7 +27,7 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
import {Tooltip} from "primeng/tooltip";
import {Divider} from "primeng/divider";
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';
@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 bookService = inject(BookService);
@@ -88,8 +88,10 @@ export class SeriesPageComponent implements OnDestroy {
protected appSettingsService = inject(AppSettingsService);
private readonly t = inject(TranslocoService);
@ViewChild('descriptionContent') descriptionContentRef?: ElementRef<HTMLElement>;
tab: string = "view";
isExpanded = false;
isOverflowing = false;
// Selection state
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 {
this.isExpanded = !this.isExpanded;
}
@@ -670,10 +670,10 @@
<span>{{ t('synopsisTitle') }}</span>
</div>
<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>
@if (book.metadata!.description && book.metadata!.description.length > 500) {
@if (isExpanded || isOverflowing) {
<button class="expand-toggle" (click)="toggleExpand()">
{{ isExpanded ? t('showLess') : t('showMore') }}
<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 {AsyncPipe, DecimalPipe, NgClass} from '@angular/common';
import {combineLatest, Observable} from 'rxjs';
@@ -44,7 +44,7 @@ import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/tran
styleUrl: './metadata-viewer.component.scss',
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() recommendedBooks: BookRecommendation[] = [];
private originalRecommendedBooks: BookRecommendation[] = [];
@@ -70,7 +70,9 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
otherItems$!: Observable<MenuItem[]>;
downloadMenuItems$!: Observable<MenuItem[]>;
bookInSeries: Book[] = [];
@ViewChild('descriptionContent') descriptionContentRef?: ElementRef<HTMLElement>;
isExpanded = false;
isOverflowing = false;
isComicSectionExpanded = true;
isAudiobookSectionExpanded = true;
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 {
this.isExpanded = !this.isExpanded;
}