added entry list component
This commit is contained in:
1 parent
2e5cd93e13
commit
ba8887d948
4 files changed
+150
No files matched your search
@@ -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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<!-- <div class="movies-container">
|
||||||
|
<div class="movie-card" *ngFor="let n of [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]">
|
||||||
|
<div class="card-head">
|
||||||
|
<img class="card-img"
|
||||||
|
src="https://cdn.cinematerial.com/p/297x/4vmodacg/the-bad-guys-movie-poster-md.jpg?v=1639499851" alt="">
|
||||||
|
|
||||||
|
<div class="card-overlay">
|
||||||
|
<div class="rating">
|
||||||
|
<i class='bx bx-star'></i>
|
||||||
|
<span>6.5</span>
|
||||||
|
</div>
|
||||||
|
<div class="bookmark">
|
||||||
|
<i class='bx bxs-bookmark'></i>
|
||||||
|
</div>
|
||||||
|
<div class="info">
|
||||||
|
<i class='bx bx-info-circle'></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card-body">
|
||||||
|
|
||||||
|
<h3 class="card-title">Doctor Strange and the multiverse of madness</h3>
|
||||||
|
<div class="card-info">
|
||||||
|
<span class="Year">2021</span>
|
||||||
|
<i class="card-dot"></i>
|
||||||
|
<span class="duration">137 min</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div> -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Entries Container/Grid -->
|
||||||
|
<div class="movies-container">
|
||||||
|
<app-main-card *ngFor="let entry of entries" [entry]="entry"></app-main-card>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pagination -->
|
||||||
|
<div class="pagination-container">
|
||||||
|
<ul class="pagination pagination-sm">
|
||||||
|
<li class="page-item" [class.disabled]="currentPage === 1">
|
||||||
|
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
||||||
|
</li>
|
||||||
|
<!-- Dynamically generate page numbers -->
|
||||||
|
<li class="page-item" *ngFor="let page of pageNumbers" [class.active]="currentPage === page">
|
||||||
|
<a class="page-link" href="javascript:;" (click)="goToPage(page)">{{ page }}</a>
|
||||||
|
</li>
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage + 1)">Next</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
@@ -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<EntryListComponent>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [EntryListComponent]
|
||||||
|
});
|
||||||
|
fixture = TestBed.createComponent(EntryListComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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<number, Entry[]> = {};
|
||||||
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user