feat: pagination

This commit is contained in:
2026-02-04 20:17:04 -08:00
parent b9f33bc055
commit ca288eaac4
10 changed files with 696 additions and 30 deletions
@@ -12,12 +12,13 @@ import { AuthService } from '../../services/auth.service';
import { CommentsService } from '../../services/comments.service';
import { SanitizeService } from '../../services/sanitize.service';
import { SuggestionService } from '../../services/suggestion.service';
import { PaginationComponent } from '../shared/pagination.component';
import { Show, ShowStatus, ShowType, CreateShowDto, UpdateShowDto, Comment, SuggestionEntity, Link } from '@library/shared-types';
@Component({
selector: 'app-shows-list',
standalone: true,
imports: [CommonModule, FormsModule],
imports: [CommonModule, FormsModule, PaginationComponent],
template: `
<div class="container">
<div class="header-section">
@@ -395,8 +396,16 @@ import { Show, ShowStatus, ShowType, CreateShowDto, UpdateShowDto, Comment, Sugg
<p>No shows found in this category.</p>
</div>
} @else {
<app-pagination
[currentPage]="currentPage()"
[pageSize]="pageSize()"
[totalItems]="totalFilteredShows()"
(pageChange)="onPageChange($event)"
(pageSizeChange)="onPageSizeChange($event)"
></app-pagination>
<div class="shows-grid">
@for (show of filteredShows(); track show.id) {
@for (show of paginatedShows(); track show.id) {
<div class="show-card" [class.completed]="show.status === ShowStatus.completed">
@if (show.coverImage) {
<img [src]="show.coverImage" [alt]="show.title" class="show-cover">
@@ -532,6 +541,14 @@ import { Show, ShowStatus, ShowType, CreateShowDto, UpdateShowDto, Comment, Sugg
</div>
}
</div>
<app-pagination
[currentPage]="currentPage()"
[pageSize]="pageSize()"
[totalItems]="totalFilteredShows()"
(pageChange)="onPageChange($event)"
(pageSizeChange)="onPageSizeChange($event)"
></app-pagination>
}
</div>
`,
@@ -1029,6 +1046,10 @@ export class ShowsListComponent implements OnInit {
editingShow = signal<Show | null>(null);
statusFilter = signal<'all' | ShowStatus>('all');
// Pagination state
currentPage = signal(1);
pageSize = signal(25);
comments = signal<Record<string, Comment[]>>({});
commentsLoading = signal<Record<string, boolean>>({});
expandedComments = signal<Record<string, boolean>>({});
@@ -1066,6 +1087,15 @@ export class ShowsListComponent implements OnInit {
return this.shows().filter(show => show.status === filter);
});
paginatedShows = computed(() => {
const shows = this.filteredShows();
const start = (this.currentPage() - 1) * this.pageSize();
const end = start + this.pageSize();
return shows.slice(start, end);
});
totalFilteredShows = computed(() => this.filteredShows().length);
newShow: Partial<CreateShowDto> = {
title: '',
type: ShowType.tvSeries,
@@ -1105,6 +1135,19 @@ export class ShowsListComponent implements OnInit {
setFilter(filter: 'all' | ShowStatus) {
this.statusFilter.set(filter);
this.currentPage.set(1); // Reset to first page when filter changes
}
onPageChange(page: number) {
this.currentPage.set(page);
}
onPageSizeChange(pageSize: number) {
this.pageSize.set(pageSize);
// Calculate new current page to stay on approximately the same content
const firstItemIndex = (this.currentPage() - 1) * this.pageSize();
const newPage = Math.floor(firstItemIndex / pageSize) + 1;
this.currentPage.set(newPage);
}
getStatusLabel(status: ShowStatus): string {