Renamed many components + started implementing lazy loading
This commit is contained in:
1 parent
c8578ccf77
commit
60b517500f
80 files changed
+274
-242
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,59 @@
|
||||
<!--breadcrumb-->
|
||||
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
|
||||
<div class="breadcrumb-title pe-3">Discover</div>
|
||||
<div class="ps-3">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb mb-0 p-0">
|
||||
<li class="breadcrumb-item">
|
||||
<a href="javascript:;">
|
||||
</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Trending</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="ms-auto">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-outline-dark" [class.active]="entryType === true"
|
||||
(click)="setEntryType(true)">Movies</button>
|
||||
|
||||
<button type="button" class="btn btn-outline-dark" [class.active]="entryType === false"
|
||||
(click)="setEntryType(false)">TV-Series</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--end breadcrumb-->
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="pagination-container d-flex justify-content-end">
|
||||
<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>
|
||||
|
||||
<app-dynamic-entry-list [entries]="entries"></app-dynamic-entry-list>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="pagination-container d-flex justify-content-end">
|
||||
<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 { PopularComponent } from './popular.component';
|
||||
|
||||
describe('PopularComponent', () => {
|
||||
let component: PopularComponent;
|
||||
let fixture: ComponentFixture<PopularComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [PopularComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(PopularComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { TmdbService } from '../../../core/services/tmdb.service';
|
||||
import { Entry } from '../../../shared/models/entry.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-popular',
|
||||
templateUrl: './popular.component.html',
|
||||
styleUrls: ['./popular.component.css'],
|
||||
})
|
||||
export class PopularComponent {
|
||||
entryType: boolean = true;
|
||||
entries: Entry[] = [];
|
||||
|
||||
// * old local cach
|
||||
// pages: Record<string, Record<number, Entry[]>> = {
|
||||
// true: {},
|
||||
// false: {},
|
||||
// };
|
||||
currentPage: number = 1;
|
||||
|
||||
constructor(private tmdbService: TmdbService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.fetchEntries();
|
||||
}
|
||||
|
||||
setEntryType(entryType: boolean) {
|
||||
this.entryType = entryType;
|
||||
this.fetchEntries();
|
||||
}
|
||||
|
||||
// * old methode using local cach
|
||||
// fetchEntries() {
|
||||
// if (this.pages[this.entryType.toString()][this.currentPage]) {
|
||||
// // ? not in cash > fetch entries from TMDB
|
||||
// this.entries = this.pages[this.entryType.toString()][this.currentPage];
|
||||
// } else {
|
||||
// // ? in cash > use cash entries
|
||||
// this.tmdbService
|
||||
// .getPopular(this.currentPage, this.entryType)
|
||||
// .subscribe((myEntries) => {
|
||||
// // * add fetched entries to the cash
|
||||
// this.pages[this.entryType.toString()][this.currentPage] = myEntries;
|
||||
|
||||
// // * add fetched entries to the display list
|
||||
// this.entries =
|
||||
// this.pages[this.entryType.toString()][this.currentPage];
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
fetchEntries() {
|
||||
this.tmdbService
|
||||
.getPopular(this.currentPage, this.entryType)
|
||||
.subscribe((myEntries) => {
|
||||
this.entries = myEntries;
|
||||
});
|
||||
}
|
||||
|
||||
goToPage(page: number) {
|
||||
this.currentPage = page;
|
||||
this.fetchEntries();
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,64 @@
|
||||
<!--breadcrumb-->
|
||||
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
|
||||
<div class="breadcrumb-title pe-3">Discover</div>
|
||||
<div class="ps-3">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb mb-0 p-0">
|
||||
<li class="breadcrumb-item">
|
||||
<a href="javascript:;">
|
||||
</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Search</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="ms-auto">
|
||||
<div class="input-group custom-group">
|
||||
<input type="text" placeholder="Name..." [(ngModel)]="searchInput" (ngModelChange)="onInputChange()"
|
||||
(keydown.enter)="onEnterPress()">
|
||||
|
||||
<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 right-btn" [class.active]="entryType === false"
|
||||
(click)="setEntryType(false)">TV-Series</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--end breadcrumb-->
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="pagination-container d-flex justify-content-end">
|
||||
<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>
|
||||
|
||||
<app-dynamic-entry-list [entries]="entries"></app-dynamic-entry-list>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="pagination-container d-flex justify-content-end">
|
||||
<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 { SearchComponent } from './search.component';
|
||||
|
||||
describe('SearchComponent', () => {
|
||||
let component: SearchComponent;
|
||||
let fixture: ComponentFixture<SearchComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [SearchComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(SearchComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,84 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Entry } from '../../../shared/models/entry.model';
|
||||
import { TmdbService } from '../../../core/services/tmdb.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-search',
|
||||
templateUrl: './search.component.html',
|
||||
styleUrls: ['./search.component.css'],
|
||||
})
|
||||
export class SearchComponent {
|
||||
entryType: boolean = true;
|
||||
entries: Entry[] = [];
|
||||
isSearchLocked: boolean = false;
|
||||
endPoint: string = '';
|
||||
|
||||
pages: Record<string, Record<number, Entry[]>> = {
|
||||
true: {},
|
||||
false: {},
|
||||
};
|
||||
currentPage: number = 1;
|
||||
|
||||
searchInput: string = '';
|
||||
|
||||
constructor(private tmdbService: TmdbService) {}
|
||||
|
||||
ngOnInit() {}
|
||||
|
||||
setEntryType(entryType: boolean) {
|
||||
this.entryType = entryType;
|
||||
this.doSearch(this.searchInput);
|
||||
}
|
||||
|
||||
// ? PAGINATION
|
||||
goToPage(page: number) {
|
||||
this.currentPage = page;
|
||||
this.doSearch(this.searchInput);
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
// ? EVENTS
|
||||
onInputChange(): void {
|
||||
const inputValue = this.searchInput;
|
||||
this.currentPage = 1;
|
||||
|
||||
if (!this.isSearchLocked) {
|
||||
console.log(this.isSearchLocked);
|
||||
this.isSearchLocked = true;
|
||||
|
||||
this.doSearch(inputValue);
|
||||
|
||||
setTimeout(() => {
|
||||
this.isSearchLocked = false;
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
onEnterPress() {
|
||||
this.currentPage = 1;
|
||||
this.doSearch(this.searchInput);
|
||||
}
|
||||
|
||||
// ? FUNCTIONS
|
||||
doSearch(keyword: string) {
|
||||
keyword = keyword.toLowerCase().trim();
|
||||
if (keyword.length <= 0) return;
|
||||
|
||||
let type = this.entryType ? 'movie' : 'tv';
|
||||
this.tmdbService
|
||||
.getByKeyword(keyword, type, this.currentPage)
|
||||
.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;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<!--breadcrumb-->
|
||||
<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">
|
||||
<ol class="breadcrumb mb-0 p-0">
|
||||
<li class="breadcrumb-item">
|
||||
<a href="javascript:;">
|
||||
</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Trending</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="ms-auto">
|
||||
<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 right-btn" [class.active]="entryType === false"
|
||||
(click)="setEntryType(false)">TV-Series</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--end breadcrumb-->
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="pagination-container d-flex justify-content-end">
|
||||
<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>
|
||||
|
||||
<app-dynamic-entry-list [entries]="entries"></app-dynamic-entry-list>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="pagination-container d-flex justify-content-end">
|
||||
<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>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
Select2.init(document.querySelector('#single-select-field'));
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,21 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TrendingComponent } from './trending.component';
|
||||
|
||||
describe('TrendingComponent', () => {
|
||||
let component: TrendingComponent;
|
||||
let fixture: ComponentFixture<TrendingComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [TrendingComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TrendingComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Entry } from '../../../shared/models/entry.model';
|
||||
import { TmdbService } from '../../../core/services/tmdb.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-trending',
|
||||
templateUrl: './trending.component.html',
|
||||
styleUrls: ['./trending.component.css'],
|
||||
})
|
||||
export class TrendingComponent {
|
||||
entryType: boolean = true;
|
||||
entries: Entry[] = [];
|
||||
|
||||
currentPage: number = 1;
|
||||
|
||||
period: string = 'day';
|
||||
|
||||
constructor(private tmdbService: TmdbService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.fetchEntries();
|
||||
}
|
||||
|
||||
setEntryType(entryType: boolean) {
|
||||
this.entryType = entryType;
|
||||
this.fetchEntries();
|
||||
}
|
||||
|
||||
updatePeriod(event: any) {
|
||||
this.period = event.target.value;
|
||||
this.fetchEntries();
|
||||
}
|
||||
|
||||
fetchEntries() {
|
||||
this.tmdbService
|
||||
.getPopular(this.currentPage, this.entryType)
|
||||
.subscribe((myEntries) => {
|
||||
this.entries = myEntries;
|
||||
});
|
||||
}
|
||||
|
||||
setRange(period: string) {
|
||||
this.period = period;
|
||||
}
|
||||
|
||||
goToPage(page: number) {
|
||||
this.currentPage = page;
|
||||
this.fetchEntries();
|
||||
}
|
||||
|
||||
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