From ba8887d948626c54c00a864b1f69f1f5a9314cfa Mon Sep 17 00:00:00 2001 From: X4Lo Date: Sun, 31 Mar 2024 04:13:43 +0000 Subject: [PATCH] added entry list component --- .../lists/entry-list/entry-list.component.css | 16 +++++ .../entry-list/entry-list.component.html | 54 +++++++++++++++++ .../entry-list/entry-list.component.spec.ts | 21 +++++++ .../lists/entry-list/entry-list.component.ts | 59 +++++++++++++++++++ 4 files changed, 150 insertions(+) create mode 100644 frontend/src/app/features/lists/entry-list/entry-list.component.css create mode 100644 frontend/src/app/features/lists/entry-list/entry-list.component.html create mode 100644 frontend/src/app/features/lists/entry-list/entry-list.component.spec.ts create mode 100644 frontend/src/app/features/lists/entry-list/entry-list.component.ts diff --git a/frontend/src/app/features/lists/entry-list/entry-list.component.css b/frontend/src/app/features/lists/entry-list/entry-list.component.css new file mode 100644 index 0000000..e7caa47 --- /dev/null +++ b/frontend/src/app/features/lists/entry-list/entry-list.component.css @@ -0,0 +1,16 @@ + +.movies-container { + display: grid; + grid-template-columns: repeat( + auto-fill, + minmax(200px, 1fr) + ); /* Creates a responsive grid */ + gap: 20px; /* Space between items */ + /* padding: 20px;Padding around the grid */ +} + +.pagination-container { + display: flex; + justify-content: center; + align-items: center; +} \ No newline at end of file diff --git a/frontend/src/app/features/lists/entry-list/entry-list.component.html b/frontend/src/app/features/lists/entry-list/entry-list.component.html new file mode 100644 index 0000000..8f3e892 --- /dev/null +++ b/frontend/src/app/features/lists/entry-list/entry-list.component.html @@ -0,0 +1,54 @@ + + + + +
+ +
+ + +
+ +
\ No newline at end of file diff --git a/frontend/src/app/features/lists/entry-list/entry-list.component.spec.ts b/frontend/src/app/features/lists/entry-list/entry-list.component.spec.ts new file mode 100644 index 0000000..400167d --- /dev/null +++ b/frontend/src/app/features/lists/entry-list/entry-list.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EntryListComponent } from './entry-list.component'; + +describe('EntryListComponent', () => { + let component: EntryListComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [EntryListComponent] + }); + fixture = TestBed.createComponent(EntryListComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/lists/entry-list/entry-list.component.ts b/frontend/src/app/features/lists/entry-list/entry-list.component.ts new file mode 100644 index 0000000..e8869fb --- /dev/null +++ b/frontend/src/app/features/lists/entry-list/entry-list.component.ts @@ -0,0 +1,59 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { TmdbService } from '../../../core/services/tmdb.service'; +import { Entry } from '../../../shared/models/entry.model'; + +@Component({ + selector: 'app-entry-list', + templateUrl: './entry-list.component.html', + styleUrls: ['./entry-list.component.css'], +}) +export class EntryListComponent implements OnInit { + @Input() isMovies: boolean = true; + @Input() type: string = ''; + entries: Entry[] = []; + pages: Record = {}; + currentPage: number = 1; + + constructor(private tmdbService: TmdbService) {} + + ngOnInit() { + this.fetchMovies(); + } + + fetchMovies() { + if (this.type == 'popular') { + if (this.pages[this.currentPage]) { + console.log('page existe deja'); + this.entries = this.pages[this.currentPage]; + } else { + console.log("page n'existe pas"); + this.tmdbService + .getPopularMovies(this.currentPage, this.isMovies) + .subscribe((myEntries) => { + this.pages[this.currentPage] = myEntries + this.entries = this.pages[this.currentPage]; + }); + } + } else if (this.type == 'trending') { + this.tmdbService + .getTrendingMovies(this.currentPage, this.isMovies) + .subscribe((myEntries) => (this.entries = myEntries)); + } + } + + goToPage(page: number) { + this.currentPage = page; + this.fetchMovies(); + } + + get pageNumbers(): number[] { + this.currentPage = this.currentPage <= 0 ? 1 : this.currentPage; // page <= 0 fix + let startPage = this.currentPage <= 3 ? 1 : this.currentPage - 2; + let endPage = startPage + 4; + + return Array.from( + { length: endPage - startPage + 1 }, + (_, i) => startPage + i + ); + } +}