fix pagination + add range (day week)
This commit is contained in:
1 parent
e0d9fa44b6
commit
1556924a76
4 files changed
+69
-13
No files matched your search
@@ -36,7 +36,7 @@ export class EntryListComponent implements OnInit {
|
||||
}
|
||||
} else if (this.type == 'trending') {
|
||||
this.tmdbService
|
||||
.getTrending(this.currentPage, this.isMovies)
|
||||
.getTrending(this.currentPage, this.isMovies, 'day')
|
||||
.subscribe((myEntries) => (this.entries = myEntries));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/* Custom CSS to visually connect the elements */
|
||||
.custom-group .form-select {
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
}
|
||||
|
||||
.custom-group .btn-group .btn {
|
||||
border-radius: 0; /* Remove rounding from buttons inside the group */
|
||||
}
|
||||
|
||||
.custom-group .btn-group .left-btn {
|
||||
border-top-left-radius: 0.25rem; /* Reapply rounding to the left-most button */
|
||||
border-bottom-left-radius: 0.25rem;
|
||||
}
|
||||
|
||||
.custom-group .btn-group .right-btn {
|
||||
border-top-right-radius: 0.25rem; /* Reapply rounding to the right-most button */
|
||||
border-bottom-right-radius: 0.25rem;
|
||||
}
|
||||
|
||||
.custom-group .form-select, .custom-group .btn-outline-dark {
|
||||
margin-right: -1px; /* Overlap borders */
|
||||
}
|
||||
|
||||
/* Adjust the select width as needed */
|
||||
#single-select-field {
|
||||
max-width: 120px;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<!--breadcrumb-->
|
||||
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
|
||||
<div class="page-breadcrumb d-sm-flex align-items-center mb-3">
|
||||
<div class="breadcrumb-title pe-3">Discover</div>
|
||||
<div class="ps-3">
|
||||
<nav aria-label="breadcrumb">
|
||||
@@ -13,15 +13,23 @@
|
||||
</nav>
|
||||
</div>
|
||||
<div class="ms-auto">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-outline-dark" [class.active]="entryType === true"
|
||||
<div class="input-group custom-group">
|
||||
<select class="form-select" id="single-select-field" data-placeholder="Choose one thing" style="max-width: 150px;"
|
||||
[(ngModel)]="period" (change)="updatePeriod($event)">
|
||||
<option value="day">Daily</option>
|
||||
<option value="week">Weekly</option>
|
||||
</select>
|
||||
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-outline-dark left-btn" [class.active]="entryType === true"
|
||||
(click)="setEntryType(true)">Movies</button>
|
||||
|
||||
<button type="button" class="btn btn-outline-dark" [class.active]="entryType === false"
|
||||
<button type="button" class="btn btn-outline-dark right-btn" [class.active]="entryType === false"
|
||||
(click)="setEntryType(false)">TV-Series</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--end breadcrumb-->
|
||||
|
||||
<!-- Pagination -->
|
||||
@@ -57,3 +65,9 @@
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
Select2.init(document.querySelector('#single-select-field'));
|
||||
});
|
||||
</script>
|
||||
@@ -12,11 +12,15 @@ export class TrendingComponent {
|
||||
entries: Entry[] = [];
|
||||
|
||||
pages: Record<string, Record<number, Entry[]>> = {
|
||||
true: {},
|
||||
false: {},
|
||||
movieday: {},
|
||||
dayweek: {},
|
||||
tvday: {},
|
||||
tvweek: {},
|
||||
};
|
||||
currentPage: number = 1;
|
||||
|
||||
period: string = 'day';
|
||||
|
||||
constructor(private tmdbService: TmdbService) {}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -28,25 +32,35 @@ export class TrendingComponent {
|
||||
this.fetchEntries();
|
||||
}
|
||||
|
||||
updatePeriod(event: any) {
|
||||
this.period = event.target.value;
|
||||
this.fetchEntries();
|
||||
}
|
||||
|
||||
fetchEntries() {
|
||||
if (this.pages[this.entryType.toString()][this.currentPage]) {
|
||||
const cachKey = (this.entryType ? 'movie' : 'tv') + this.period; // ex: movieday, movieweek, tvday, tvweek
|
||||
|
||||
if (this.pages[cachKey][this.currentPage]) {
|
||||
// ? not in cash > fetch entries from TMDB
|
||||
this.entries = this.pages[this.entryType.toString()][this.currentPage];
|
||||
this.entries = this.pages[cachKey][this.currentPage];
|
||||
} else {
|
||||
// ? in cash > use cash entries
|
||||
this.tmdbService
|
||||
.getTrending(this.currentPage, this.entryType)
|
||||
.getTrending(this.currentPage, this.entryType, this.period)
|
||||
.subscribe((myEntries) => {
|
||||
// * add fetched entries to the cash
|
||||
this.pages[this.entryType.toString()][this.currentPage] = myEntries;
|
||||
this.pages[cachKey][this.currentPage] = myEntries;
|
||||
|
||||
// * add fetched entries to the display list
|
||||
this.entries =
|
||||
this.pages[this.entryType.toString()][this.currentPage];
|
||||
this.entries = this.pages[cachKey][this.currentPage];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setRange(period: string) {
|
||||
this.period = period;
|
||||
}
|
||||
|
||||
goToPage(page: number) {
|
||||
this.currentPage = page;
|
||||
this.fetchEntries();
|
||||
|
||||
Reference in new issue
Block a user