feat(ui): New sidebar & search UI (#831)
This commit is contained in:
+64
-62
@@ -47,7 +47,7 @@
|
||||
<div class="toolbar-actions">
|
||||
<div class="toolbar-icons">
|
||||
@if (isFilterActive()) {
|
||||
<a class="topbar-items topbar-item" role="button" tabindex="0" (click)="clearFilter()" (keydown.enter)="clearFilter()">
|
||||
<a class="toolbar-item" role="button" tabindex="0" (click)="clearFilter()" (keydown.enter)="clearFilter()">
|
||||
<i
|
||||
class="pi pi-filter-slash filter-clear-icon"
|
||||
[pTooltip]="t('tooltip.clearFilters')"
|
||||
@@ -58,7 +58,7 @@
|
||||
|
||||
@if (currentViewMode() === 'table') {
|
||||
<div>
|
||||
<a class="topbar-items topbar-item" role="button" tabindex="0" (click)="columnPopover.toggle($event)" (keydown.enter)="columnPopover.toggle($event)">
|
||||
<a class="toolbar-item" role="button" tabindex="0" (click)="columnPopover.toggle($event)" (keydown.enter)="columnPopover.toggle($event)">
|
||||
<i
|
||||
class="pi pi-eye"
|
||||
[pTooltip]="t('tooltip.visibleColumns')"
|
||||
@@ -90,7 +90,7 @@
|
||||
</p-popover>
|
||||
</div>
|
||||
}
|
||||
<a class="topbar-items topbar-item" role="button" tabindex="0" (click)="toggleTableGrid()" (keydown.enter)="toggleTableGrid()">
|
||||
<a class="toolbar-item" role="button" tabindex="0" (click)="toggleTableGrid()" (keydown.enter)="toggleTableGrid()">
|
||||
<i
|
||||
[class]="viewIcon()"
|
||||
[pTooltip]="t('tooltip.toggleView')"
|
||||
@@ -99,7 +99,7 @@
|
||||
</a>
|
||||
<div>
|
||||
<a
|
||||
class="topbar-items topbar-item"
|
||||
class="toolbar-item"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
(click)="seriesCollapseOverlay.toggle($event)"
|
||||
@@ -164,7 +164,7 @@
|
||||
</div>
|
||||
|
||||
<div class="sort-button-wrapper">
|
||||
<a class="topbar-items topbar-item" role="button" tabindex="0" (click)="sortPopover.toggle($event)" (keydown.enter)="sortPopover.toggle($event)">
|
||||
<a class="toolbar-item" role="button" tabindex="0" (click)="sortPopover.toggle($event)" (keydown.enter)="sortPopover.toggle($event)">
|
||||
<i
|
||||
class="pi pi-sort"
|
||||
[pTooltip]="t('tooltip.selectSorting')"
|
||||
@@ -191,7 +191,7 @@
|
||||
<div class="mobile-search-wrapper">
|
||||
<button
|
||||
type="button"
|
||||
class="topbar-items topbar-item"
|
||||
class="toolbar-item"
|
||||
(click)="searchDropdown.toggle($event)"
|
||||
[pTooltip]="t('tooltip.search')"
|
||||
tooltipPosition="top"
|
||||
@@ -243,7 +243,7 @@
|
||||
}
|
||||
</div>
|
||||
|
||||
<a class="topbar-items topbar-item" role="button" tabindex="0" (click)="toggleSidebar()" (keydown.enter)="toggleSidebar()">
|
||||
<a class="toolbar-item" role="button" tabindex="0" (click)="toggleSidebar()" (keydown.enter)="toggleSidebar()">
|
||||
<i
|
||||
[ngClass]="showFilter() ? 'pi pi-filter-fill' : 'pi pi-filter'"
|
||||
[pTooltip]="t('tooltip.toggleSidebar')"
|
||||
@@ -270,62 +270,63 @@
|
||||
</p>
|
||||
</div>
|
||||
} @else {
|
||||
@let visibleBooks = books();
|
||||
@if (visibleBooks.length === 0 && !isBooksLoading()) {
|
||||
<div class="no-books-container">
|
||||
<p class="no-books-text">
|
||||
{{ t('labels.noBooks') }}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
@if (currentViewMode() === 'table' && (visibleBooks.length > 0 || showTableLoadingPlaceholder())) {
|
||||
<app-book-table
|
||||
[books]="visibleBooks"
|
||||
[virtualRowCount]="virtualRowCount()"
|
||||
[loadedBookCount]="loadedBookCount()"
|
||||
[isFetchingNextPage]="isFetchingNextBooksPage()"
|
||||
[bookQueryToken]="bookQueryToken()"
|
||||
(selectAllRequested)="selectAllBooks()"
|
||||
(loadNextPage)="loadNextBooksPage()"
|
||||
[visibleColumns]="visibleColumns()"
|
||||
[useSquareCovers]="isAudiobookOnlyLibrary()"
|
||||
></app-book-table>
|
||||
}
|
||||
@if (currentViewMode() === 'grid') {
|
||||
<div #scrollElement class="virtual-scroller">
|
||||
<div class="virtual-content" [style.height.px]="virtualGrid.virtualizer.getTotalSize()">
|
||||
@for (virtualItem of virtualGrid.virtualizer.getVirtualItems(); track virtualItem.key) {
|
||||
@if (visibleBooks[virtualItem.index]; as book) {
|
||||
<div
|
||||
class="virtual-cell"
|
||||
[style.width.px]="virtualGrid.itemWidth()"
|
||||
[style.height.px]="virtualItem.size"
|
||||
[style.transform]="virtualGrid.itemTransform(virtualItem)">
|
||||
<app-book-card
|
||||
[index]="virtualItem.index"
|
||||
[book]="book"
|
||||
[isCheckboxEnabled]="true"
|
||||
[seriesViewEnabled]="seriesViewEnabled()"
|
||||
[onBookSelect]="onBookCardSelect"
|
||||
[isSeriesCollapsed]="seriesCollapseFilter.seriesCollapsed()"
|
||||
(checkboxClick)="onCheckboxClicked($event)"
|
||||
[isSelected]="bookSelectionService.isBookSelected(book)"
|
||||
[useSquareCovers]="isAudiobookOnlyLibrary()"
|
||||
[overlayPreferenceService]="bookCardOverlayPreferenceService">
|
||||
</app-book-card>
|
||||
</div>
|
||||
} @else {
|
||||
<div
|
||||
class="virtual-cell virtual-loader-cell"
|
||||
[style.width.px]="virtualGrid.itemWidth()"
|
||||
[style.height.px]="virtualItem.size"
|
||||
[style.transform]="virtualGrid.itemTransform(virtualItem)"></div>
|
||||
}
|
||||
}
|
||||
<div class="book-browser-content">
|
||||
@let visibleBooks = books();
|
||||
@if (visibleBooks.length === 0 && !isBooksLoading()) {
|
||||
<div class="no-books-container">
|
||||
<p class="no-books-text">
|
||||
{{ t('labels.noBooks') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (userService.currentUser(); as currentUser) {
|
||||
}
|
||||
@if (currentViewMode() === 'table' && (visibleBooks.length > 0 || showTableLoadingPlaceholder())) {
|
||||
<app-book-table
|
||||
[books]="visibleBooks"
|
||||
[virtualRowCount]="virtualRowCount()"
|
||||
[loadedBookCount]="loadedBookCount()"
|
||||
[isFetchingNextPage]="isFetchingNextBooksPage()"
|
||||
[bookQueryToken]="bookQueryToken()"
|
||||
(selectAllRequested)="selectAllBooks()"
|
||||
(loadNextPage)="loadNextBooksPage()"
|
||||
[visibleColumns]="visibleColumns()"
|
||||
[useSquareCovers]="isAudiobookOnlyLibrary()"
|
||||
></app-book-table>
|
||||
}
|
||||
@if (currentViewMode() === 'grid') {
|
||||
<div #scrollElement class="virtual-scroller">
|
||||
<div class="virtual-content" [style.height.px]="virtualGrid.virtualizer.getTotalSize()">
|
||||
@for (virtualItem of virtualGrid.virtualizer.getVirtualItems(); track virtualItem.key) {
|
||||
@if (visibleBooks[virtualItem.index]; as book) {
|
||||
<div
|
||||
class="virtual-cell"
|
||||
[style.width.px]="virtualGrid.itemWidth()"
|
||||
[style.height.px]="virtualItem.size"
|
||||
[style.transform]="virtualGrid.itemTransform(virtualItem)">
|
||||
<app-book-card
|
||||
[index]="virtualItem.index"
|
||||
[book]="book"
|
||||
[isCheckboxEnabled]="true"
|
||||
[seriesViewEnabled]="seriesViewEnabled()"
|
||||
[onBookSelect]="onBookCardSelect"
|
||||
[isSeriesCollapsed]="seriesCollapseFilter.seriesCollapsed()"
|
||||
(checkboxClick)="onCheckboxClicked($event)"
|
||||
[isSelected]="bookSelectionService.isBookSelected(book)"
|
||||
[useSquareCovers]="isAudiobookOnlyLibrary()"
|
||||
[overlayPreferenceService]="bookCardOverlayPreferenceService">
|
||||
</app-book-card>
|
||||
</div>
|
||||
} @else {
|
||||
<div
|
||||
class="virtual-cell virtual-loader-cell"
|
||||
[style.width.px]="virtualGrid.itemWidth()"
|
||||
[style.height.px]="virtualItem.size"
|
||||
[style.transform]="virtualGrid.itemTransform(virtualItem)"></div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (userService.currentUser(); as currentUser) {
|
||||
<div class="book-browser-footer" [class.footer-hidden]="selectedCount() === 0">
|
||||
<div class="footer-content">
|
||||
<div class="footer-left">
|
||||
@@ -448,6 +449,7 @@
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
+17
-13
@@ -5,6 +5,8 @@
|
||||
flex-direction: row;
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.book-browser-main {
|
||||
@@ -13,6 +15,16 @@
|
||||
flex: 1 1 0;
|
||||
min-width: 0;
|
||||
width: auto;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.book-browser-content {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex: 1 1 auto;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
// Header bar
|
||||
@@ -22,16 +34,13 @@
|
||||
justify-content: space-between;
|
||||
gap: 0.25rem;
|
||||
padding: 0.35rem;
|
||||
border-radius: 0.75rem 0.75rem 0 0;
|
||||
margin-bottom: 0.5rem;
|
||||
margin-right: 2px;
|
||||
background-color: var(--card-background);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-bottom: 1px solid var(--p-content-border-color);
|
||||
|
||||
@media (width >= 768px) {
|
||||
gap: 1rem;
|
||||
padding: 0.5rem 1rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,15 +346,10 @@
|
||||
// Virtual scroller and grid
|
||||
.virtual-scroller {
|
||||
width: 100%;
|
||||
height: calc(100dvh - 10.9rem);
|
||||
padding: 1rem 0;
|
||||
height: 100%;
|
||||
padding: 1rem;
|
||||
box-sizing: border-box;
|
||||
overflow-y: auto;
|
||||
|
||||
@media (width <= 768px) {
|
||||
height: calc(100dvh - 9rem);
|
||||
padding: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.virtual-loader-cell {
|
||||
@@ -385,8 +389,8 @@
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
// Topbar items (icon buttons)
|
||||
.topbar-item {
|
||||
// Toolbar actions (icon buttons)
|
||||
.toolbar-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
@@ -33,6 +33,8 @@ import {SortService} from '../../service/sort.service';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
import {AppBooksApiService} from '../../service/app-books-api.service';
|
||||
import {AppBookFilters, AppBookSort} from '../../model/app-book.model';
|
||||
import {LayoutService} from '../../../../shared/layout/layout.service';
|
||||
import {type VirtualGridMetrics} from '../../../../shared/util/virtual-grid.util';
|
||||
|
||||
function makeBook(id: number, libraryId: number, title: string, addedOn: string): Book {
|
||||
return {
|
||||
@@ -261,6 +263,7 @@ function createHarness(options?: {
|
||||
},
|
||||
},
|
||||
{provide: AppSettingsService, useValue: {appSettings: vi.fn(() => null)}},
|
||||
{provide: LayoutService, useValue: {sidebarTransitioning: signal(false)}},
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
@@ -470,6 +473,23 @@ describe('BookBrowserComponent', () => {
|
||||
expect(component.showTableLoadingPlaceholder()).toBe(false);
|
||||
});
|
||||
|
||||
it('sizes grid loading placeholders to fill the viewport', () => {
|
||||
const {component} = createHarness({books: [], isBooksLoading: true});
|
||||
const loadingGrid = component as unknown as {
|
||||
minimumLoadingGridItemCount(metrics: VirtualGridMetrics): number;
|
||||
};
|
||||
|
||||
component.currentViewMode.set(VIEW_MODES.GRID);
|
||||
|
||||
expect(loadingGrid.minimumLoadingGridItemCount({
|
||||
viewportWidth: 960,
|
||||
viewportHeight: 900,
|
||||
columns: 6,
|
||||
itemHeight: 200,
|
||||
gap: 20,
|
||||
})).toBe(36);
|
||||
});
|
||||
|
||||
it('calls SeriesCollapseFilter.collapseBooks when computing books', () => {
|
||||
createHarness();
|
||||
const filter = TestBed.inject(SeriesCollapseFilter);
|
||||
|
||||
@@ -54,8 +54,9 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {SortService} from '../../service/sort.service';
|
||||
import {AppBooksApiService} from '../../service/app-books-api.service';
|
||||
import {AppBookFilters} from '../../model/app-book.model';
|
||||
import {createVirtualGrid, scaleForGridColumns} from '../../../../shared/util/virtual-grid.util';
|
||||
import {createVirtualGrid, scaleForGridColumns, type VirtualGridMetrics} from '../../../../shared/util/virtual-grid.util';
|
||||
import {GridDensityButtonsComponent} from '../../../../shared/components/grid-density-buttons/grid-density-buttons.component';
|
||||
import {LayoutService} from '../../../../shared/layout/layout.service';
|
||||
|
||||
export enum EntityType {
|
||||
LIBRARY = 'Library',
|
||||
@@ -111,6 +112,7 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
private appBooksApi = inject(AppBooksApiService);
|
||||
private localStorageService = inject(LocalStorageService);
|
||||
private scrollService = inject(RouteScrollPositionService);
|
||||
private layoutService = inject(LayoutService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
@@ -322,8 +324,10 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
gap: this.virtualGridGap,
|
||||
columns: this.virtualGridColumns,
|
||||
count: this.virtualRowCount,
|
||||
minimumCount: metrics => this.minimumLoadingGridItemCount(metrics),
|
||||
initialOffset: this.initialScrollOffset,
|
||||
fillItemWidth: true,
|
||||
deferViewportUpdates: this.layoutService.sidebarTransitioning,
|
||||
estimateItemHeight: itemWidth => this.isMobile()
|
||||
? this.mobileCardSizeForWidth(itemWidth).height
|
||||
: this.cardSizeForWidth(itemWidth).height,
|
||||
@@ -515,6 +519,18 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
return renderedBookCount + 1;
|
||||
}
|
||||
|
||||
private minimumLoadingGridItemCount({viewportHeight, columns, itemHeight, gap}: VirtualGridMetrics): number {
|
||||
if (!this.showBooksLoadingPlaceholder() || this.currentViewMode() !== VIEW_MODES.GRID) {
|
||||
return 0;
|
||||
}
|
||||
if (viewportHeight <= 0 || itemHeight <= 0) {
|
||||
return INITIAL_LOADING_ROW_COUNT;
|
||||
}
|
||||
|
||||
const visibleRows = Math.ceil((viewportHeight + gap) / (itemHeight + gap));
|
||||
return Math.max(INITIAL_LOADING_ROW_COUNT, (visibleRows + 1) * columns);
|
||||
}
|
||||
|
||||
readonly viewIcon = computed(() =>
|
||||
this.currentViewMode() === VIEW_MODES.TABLE ? 'pi pi-table' : 'pi pi-objects-column'
|
||||
);
|
||||
|
||||
+12
-3
@@ -1,5 +1,14 @@
|
||||
:host ::ng-deep p-accordion-header {
|
||||
:host ::ng-deep p-accordion {
|
||||
--p-accordion-header-padding: 0.6rem 1rem;
|
||||
--p-accordion-header-background: var(--card-background);
|
||||
--p-accordion-header-active-background: var(--card-background);
|
||||
--p-accordion-header-hover-background: var(--surface-hover);
|
||||
--p-accordion-header-active-hover-background: var(--surface-hover);
|
||||
--p-accordion-content-background: var(--card-background);
|
||||
}
|
||||
|
||||
:host ::ng-deep .p-accordionpanel {
|
||||
background: var(--card-background);
|
||||
}
|
||||
|
||||
:host ::ng-deep .p-togglebutton {
|
||||
@@ -12,7 +21,7 @@
|
||||
}
|
||||
|
||||
.book-filter-container {
|
||||
height: calc(100dvh - 6.1rem);
|
||||
height: 100%;
|
||||
border-radius: 0.75rem;
|
||||
overflow: hidden;
|
||||
background: var(--card-background);
|
||||
@@ -79,7 +88,6 @@
|
||||
|
||||
.filter-row {
|
||||
cursor: pointer;
|
||||
transition: colors 200ms ease-in-out;
|
||||
height: 26px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
@@ -87,6 +95,7 @@
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
max-width: 97%;
|
||||
transition: color var(--transition-base);
|
||||
|
||||
&.active {
|
||||
color: var(--primary-color);
|
||||
|
||||
+6
-7
@@ -1,5 +1,8 @@
|
||||
:host {
|
||||
display: block;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1 1 auto;
|
||||
width: 100%;
|
||||
min-height: 0;
|
||||
|
||||
--book-table-border-color: var(--p-datatable-border-color, color-mix(in srgb, var(--p-content-border-color) 82%, black));
|
||||
@@ -28,14 +31,10 @@
|
||||
|
||||
.book-table-scroll {
|
||||
box-sizing: border-box;
|
||||
height: calc(100dvh - 150px);
|
||||
border: 1px solid var(--book-table-border-color);
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
background: var(--book-table-row-background);
|
||||
|
||||
@media (width <= 768px) {
|
||||
height: calc(100dvh - 125px);
|
||||
}
|
||||
}
|
||||
|
||||
.book-table {
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.searcher'">
|
||||
<div class="book-searcher-container">
|
||||
<p-iconfield class="search-iconfield" [class.focused]="isSearchFocused" [class.has-results]="isDropdownOpen">
|
||||
<p-inputicon class="pi pi-search"/>
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="searchQuery"
|
||||
(input)="onSearchInputChange()"
|
||||
(focus)="isSearchFocused = true"
|
||||
(keydown)="onKeydown($event)"
|
||||
[placeholder]="t('placeholder')"
|
||||
class="search-input"
|
||||
/>
|
||||
@if (searchQuery) {
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
(click)="clearSearch()"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
class="clear-search-btn"
|
||||
[attr.aria-label]="t('clearSearch')">
|
||||
</p-button>
|
||||
}
|
||||
</p-iconfield>
|
||||
|
||||
<p-popover #resultsPopover [appendTo]="'body'" [styleClass]="'search-results-popover'">
|
||||
<div
|
||||
class="search-dropdown layout-menu show"
|
||||
>
|
||||
@if (isLoading) {
|
||||
@for (i of [1,2,3]; track i) {
|
||||
<div class="search-skeleton-item">
|
||||
<p-skeleton width="50px" height="67px" borderRadius="4px"/>
|
||||
<div class="search-skeleton-details">
|
||||
<p-skeleton width="80%" height="1rem"/>
|
||||
<p-skeleton width="60%" height="0.8rem"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
} @else if (books.length > 0) {
|
||||
@for (book of books; track book; let idx = $index) {
|
||||
<div
|
||||
class="search-dropdown-item"
|
||||
[class.active]="activeIndex === idx"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
(click)="onBookClick(book)"
|
||||
(keydown.enter)="onBookClick(book)">
|
||||
<div class="search-item-content">
|
||||
@if (urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn); as coverUrl) {
|
||||
<img
|
||||
[attr.src]="coverUrl"
|
||||
[alt]="t('bookCoverAlt')"
|
||||
class="search-book-cover"
|
||||
/>
|
||||
} @else {
|
||||
<app-cover-placeholder class="search-book-cover" [title]="book.metadata?.title ?? ''" [author]="(book.metadata?.authors ?? []).join(', ')" size="sm" />
|
||||
}
|
||||
<div class="search-book-details">
|
||||
<div class="search-book-title-container">
|
||||
<p class="search-book-name">
|
||||
{{ book.metadata?.title | slice: 0:70 }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="search-book-meta-line">
|
||||
@if (book.metadata?.authors?.length ?? 0 > 0) {
|
||||
<p class="search-book-authors">{{ t('byPrefix') }} {{ getAuthorNames(book.metadata?.authors) }}</p>
|
||||
}
|
||||
@if (getPublishedYear(book.metadata?.publishedDate)) {
|
||||
<span class="metadata-badge year-badge">{{ getPublishedYear(book.metadata?.publishedDate) }}</span>
|
||||
}
|
||||
</div>
|
||||
@if (getSeriesInfo(book.metadata?.seriesName, book.metadata?.seriesNumber)) {
|
||||
<div class="search-book-series metadata-badge series-badge">
|
||||
<i class="pi pi-book"></i>
|
||||
<span>{{ getSeriesInfo(book.metadata?.seriesName, book.metadata?.seriesNumber) }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
} @else {
|
||||
<div class="search-dropdown-item no-results">
|
||||
<span>{{ t('noResults') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</p-popover>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -1,241 +0,0 @@
|
||||
.book-searcher-container {
|
||||
margin-left: 0.5rem;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
|
||||
@media (width >= 768px) {
|
||||
margin-left: 1.25rem;
|
||||
width: var(--app-search-width-desktop);
|
||||
max-width: 100%;
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Popover styles moved to global src/styles.scss due to appendTo="body"
|
||||
|
||||
.search-iconfield {
|
||||
width: 100%;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
border-radius: 8px;
|
||||
|
||||
@media (width >= 640px) {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
&.focused {
|
||||
background: color-mix(in srgb, var(--primary-color) 5%, transparent);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 20%, transparent);
|
||||
|
||||
.search-input {
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
padding-right: 2.5rem;
|
||||
height: 2.5rem;
|
||||
line-height: 2.5rem;
|
||||
font-size: 1rem;
|
||||
background: var(--surface-800) !important;
|
||||
border: 1px solid var(--surface-600);
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--surface-500);
|
||||
background: var(--surface-700) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.clear-search-btn {
|
||||
position: absolute;
|
||||
right: 0.5rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
display: none;
|
||||
|
||||
@media (width >= 640px) {
|
||||
display: inline-flex;
|
||||
}
|
||||
}
|
||||
|
||||
.search-dropdown {
|
||||
width: 100%;
|
||||
background: transparent; // Glassmorphism handled by parent .search-results-popover
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
max-height: min(70vh, calc(100dvh - 4rem));
|
||||
overflow-y: auto;
|
||||
|
||||
// Desktop width constraints moved to src/styles.scss for body-appended elements
|
||||
}
|
||||
|
||||
// .show class no longer needed as popover handles visibility
|
||||
|
||||
.search-dropdown-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease;
|
||||
border-bottom: 1px solid color-mix(in srgb, var(--border-color) 50%, transparent);
|
||||
|
||||
&:first-child {
|
||||
border-radius: 8px 8px 0 0;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
border-radius: 0 0 8px 8px;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
&:hover,
|
||||
&.active {
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
|
||||
&.no-results {
|
||||
padding: 2rem 1rem;
|
||||
text-align: center;
|
||||
color: var(--text-secondary-color);
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
|
||||
.search-item-content {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
gap: 1rem;
|
||||
width: 100%;
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.search-book-cover {
|
||||
width: 50px;
|
||||
height: 67px;
|
||||
min-width: 50px;
|
||||
object-fit: cover;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 2px 4px rgb(0 0 0 / 10%);
|
||||
background-color: var(--ground-background);
|
||||
aspect-ratio: 2/3;
|
||||
}
|
||||
|
||||
.search-book-details {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.search-book-title-container {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.search-book-name {
|
||||
font-weight: 600;
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.4;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
overflow-wrap: anywhere;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.search-book-meta-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.search-book-authors {
|
||||
font-size: 0.9rem;
|
||||
font-style: italic;
|
||||
color: var(--text-secondary-color);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
margin: 0;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.search-book-year {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary-color);
|
||||
background-color: var(--ground-background);
|
||||
padding: 0.125rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
white-space: nowrap;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.search-book-series {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--primary-color);
|
||||
padding: 0.075rem 0.125rem;
|
||||
border-radius: 4px;
|
||||
width: fit-content;
|
||||
|
||||
i {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
span {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.search-book-metadata {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.metadata-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.8rem;
|
||||
padding: 0.1rem 0.25rem;
|
||||
border-radius: 4px;
|
||||
background-color: var(--surface-hover);
|
||||
color: var(--text-secondary-color);
|
||||
white-space: nowrap;
|
||||
|
||||
i {
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
|
||||
&.series-badge {
|
||||
background-color: color-mix(in srgb, var(--p-primary-color) 10%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.search-skeleton-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 1rem;
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.search-skeleton-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
flex: 1;
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
import {describe, it} from 'vitest';
|
||||
|
||||
// NOTE(frontend-seam): Real coverage here needs seams around debounced signal-to-observable
|
||||
// search state, global document click listeners, and router navigation so search dropdown behavior
|
||||
// can be tested without a browser-event harness.
|
||||
describe.skip('BookSearcherComponent', () => {
|
||||
it('needs debounce seams to verify filtered-book output, loading state, and active-index reset behavior', () => {
|
||||
// TODO(seam): Cover the debounced search signal and filteredBooks computed state once timing concerns are extracted for direct control.
|
||||
});
|
||||
|
||||
it('needs event seams to verify keyboard navigation, outside-click clearing, and routed book selection', () => {
|
||||
// TODO(seam): Cover onKeydown and onDocumentClick after isolating host listeners and router side effects behind adapters.
|
||||
});
|
||||
});
|
||||
@@ -1,162 +0,0 @@
|
||||
import {Component, ElementRef, HostListener, computed, inject, signal, ViewChild} from '@angular/core';
|
||||
import {toObservable, toSignal} from '@angular/core/rxjs-interop';
|
||||
import {debounceTime, distinctUntilChanged} from 'rxjs/operators';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {SlicePipe} from '@angular/common';
|
||||
import {Skeleton} from 'primeng/skeleton';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component';
|
||||
import {Router} from '@angular/router';
|
||||
import {IconField} from 'primeng/iconfield';
|
||||
import {InputIcon} from 'primeng/inputicon';
|
||||
import {filterBooksBySearchTerm} from '../book-browser/filters/HeaderFilter';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {Popover} from 'primeng/popover';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-searcher',
|
||||
templateUrl: './book-searcher.component.html',
|
||||
imports: [
|
||||
FormsModule,
|
||||
InputText,
|
||||
Button,
|
||||
SlicePipe,
|
||||
Skeleton,
|
||||
IconField,
|
||||
InputIcon,
|
||||
TranslocoDirective,
|
||||
CoverPlaceholderComponent,
|
||||
Popover,
|
||||
],
|
||||
styleUrls: ['./book-searcher.component.scss'],
|
||||
standalone: true
|
||||
})
|
||||
export class BookSearcherComponent {
|
||||
searchQuery = '';
|
||||
activeIndex = -1;
|
||||
isSearchFocused = false;
|
||||
|
||||
private readonly searchTerm = signal('');
|
||||
private readonly debouncedSearchTerm = toSignal(
|
||||
toObservable(this.searchTerm).pipe(
|
||||
debounceTime(200),
|
||||
distinctUntilChanged()
|
||||
),
|
||||
{initialValue: ''}
|
||||
);
|
||||
private readonly filteredBooks = computed(() => {
|
||||
const term = this.debouncedSearchTerm().trim();
|
||||
if (term.length < 2) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return filterBooksBySearchTerm(this.bookService.books(), term).slice(0, 50);
|
||||
});
|
||||
|
||||
private bookService = inject(BookService);
|
||||
private router = inject(Router);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private elRef = inject(ElementRef);
|
||||
|
||||
@ViewChild('resultsPopover') resultsPopover?: Popover;
|
||||
|
||||
get books(): Book[] {
|
||||
return this.filteredBooks();
|
||||
}
|
||||
|
||||
get isLoading(): boolean {
|
||||
const rawTerm = this.searchTerm().trim();
|
||||
return rawTerm.length >= 2 && rawTerm !== this.debouncedSearchTerm().trim();
|
||||
}
|
||||
|
||||
getAuthorNames(authors: string[] | undefined): string {
|
||||
return authors?.join(', ') || this.t.translate('book.searcher.unknownAuthor');
|
||||
}
|
||||
|
||||
getPublishedYear(publishedDate: string | undefined): string | null {
|
||||
if (!publishedDate) return null;
|
||||
const year = publishedDate.split('-')[0];
|
||||
return year && year.length === 4 ? year : null;
|
||||
}
|
||||
|
||||
getSeriesInfo(seriesName: string | undefined, seriesNumber: number | null | undefined): string | null {
|
||||
if (!seriesName) return null;
|
||||
if (seriesNumber) {
|
||||
return `${seriesName} #${seriesNumber}`;
|
||||
}
|
||||
return seriesName;
|
||||
}
|
||||
|
||||
onSearchInputChange(): void {
|
||||
this.searchTerm.set(this.searchQuery.trim());
|
||||
this.activeIndex = -1;
|
||||
|
||||
if (this.isDropdownOpen) {
|
||||
setTimeout(() => this.showPopover());
|
||||
} else {
|
||||
this.resultsPopover?.hide();
|
||||
}
|
||||
}
|
||||
|
||||
private showPopover(): void {
|
||||
if (this.resultsPopover) {
|
||||
const inputElement = this.elRef.nativeElement.querySelector('.search-input');
|
||||
this.resultsPopover.show(null, inputElement);
|
||||
}
|
||||
}
|
||||
|
||||
onBookClick(book: Book): void {
|
||||
this.clearSearch();
|
||||
this.router.navigate(['/book', book.id], {
|
||||
queryParams: {tab: 'view'}
|
||||
});
|
||||
}
|
||||
|
||||
clearSearch(): void {
|
||||
this.searchQuery = '';
|
||||
this.searchTerm.set('');
|
||||
this.activeIndex = -1;
|
||||
this.resultsPopover?.hide();
|
||||
}
|
||||
|
||||
get isDropdownOpen(): boolean {
|
||||
return this.books.length > 0 || this.isLoading;
|
||||
}
|
||||
|
||||
@HostListener('document:click', ['$event'])
|
||||
onDocumentClick(event: Event): void {
|
||||
if (!this.elRef.nativeElement.contains(event.target)) {
|
||||
this.clearSearch();
|
||||
this.isSearchFocused = false;
|
||||
}
|
||||
}
|
||||
|
||||
onKeydown(event: KeyboardEvent): void {
|
||||
if (!this.isDropdownOpen) return;
|
||||
|
||||
switch (event.key) {
|
||||
case 'ArrowDown':
|
||||
this.activeIndex = Math.min(this.activeIndex + 1, this.books.length - 1);
|
||||
event.preventDefault();
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
this.activeIndex = Math.max(this.activeIndex - 1, 0);
|
||||
event.preventDefault();
|
||||
break;
|
||||
case 'Enter':
|
||||
if (this.activeIndex >= 0 && this.activeIndex < this.books.length) {
|
||||
this.onBookClick(this.books[this.activeIndex]);
|
||||
}
|
||||
break;
|
||||
case 'Escape':
|
||||
this.clearSearch();
|
||||
(event.target as HTMLElement).blur();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,22 @@
|
||||
.tabpanels-responsive {
|
||||
height: calc(100dvh - 9.7rem);
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
@media (width <= 768px) {
|
||||
.tabpanels-responsive {
|
||||
height: calc(100dvh - 8.5rem);
|
||||
}
|
||||
.series-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.series-wrapper {
|
||||
position: relative;
|
||||
border-radius: 0.75rem;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
.series-wrapper > p-tabs {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.series-main {
|
||||
|
||||
Reference in New Issue
Block a user