implemented search page
This commit is contained in:
1 parent
c84ee2c5eb
commit
b8e8a9a581
2 files changed
+139
-2
No files matched your search
@@ -1 +1,64 @@
|
|||||||
<H1>Search</H1>
|
<!--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>
|
||||||
@@ -1,10 +1,84 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { TmdbService } from '../../../core/services/tmdb.service';
|
||||||
|
import { Entry } from '../../../shared/models/entry.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-search',
|
selector: 'app-search',
|
||||||
templateUrl: './search.component.html',
|
templateUrl: './search.component.html',
|
||||||
styleUrls: ['./search.component.css']
|
styleUrls: ['./search.component.css'],
|
||||||
})
|
})
|
||||||
export class SearchComponent {
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user