improved search component
This commit is contained in:
1 parent
60faa34363
commit
ff76e3900b
6 files changed
+62
-41
No files matched your search
@@ -0,0 +1,3 @@
|
||||
.ms-auto.d-flex .btn-group button {
|
||||
min-width: 100px;
|
||||
}
|
||||
@@ -12,25 +12,26 @@
|
||||
</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">
|
||||
|
||||
<div class="ms-auto d-flex align-items-center">
|
||||
<div class="input-group me-3">
|
||||
<span class="input-group-text">Search</span>
|
||||
<input class="form-control" type="search" placeholder="Title..." [formControl]="searchControl">
|
||||
</div>
|
||||
|
||||
<div class="btn-group" role="group" style="align-self: center;">
|
||||
<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"
|
||||
<button type="button" class="btn btn-outline-dark right-btn w-100" [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">
|
||||
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage > 1">
|
||||
<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>
|
||||
@@ -48,7 +49,7 @@
|
||||
<app-dynamic-entry-list [entries]="entries"></app-dynamic-entry-list>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="pagination-container d-flex justify-content-end">
|
||||
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage > 1">
|
||||
<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>
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Entry } from '../../../shared/models/entry.model';
|
||||
import { TmdbService } from '../../../core/services/tmdb.service';
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { debounceTime, distinctUntilChanged } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-search',
|
||||
templateUrl: './search.component.html',
|
||||
styleUrls: ['./search.component.css'],
|
||||
})
|
||||
export class SearchComponent {
|
||||
export class SearchComponent implements OnInit {
|
||||
entryType: boolean = true;
|
||||
entries: Entry[] = [];
|
||||
isSearchLocked: boolean = false;
|
||||
@@ -17,23 +19,36 @@ export class SearchComponent {
|
||||
true: {},
|
||||
false: {},
|
||||
};
|
||||
currentPage: number = 1;
|
||||
|
||||
searchInput: string = '';
|
||||
currentPage: number = 1;
|
||||
maxPage: number = 0;
|
||||
totalEntries: number = 0;
|
||||
searchControl = new FormControl();
|
||||
|
||||
constructor(private tmdbService: TmdbService) {}
|
||||
|
||||
ngOnInit() {}
|
||||
ngOnInit() {
|
||||
this.searchControl.valueChanges
|
||||
.pipe(
|
||||
debounceTime(300), // Delay the API call by 300 milliseconds
|
||||
distinctUntilChanged() // Only emit when the current value is different from the last
|
||||
)
|
||||
.subscribe((value) => {
|
||||
this.currentPage = 1;
|
||||
this.doSearch(value);
|
||||
// this.search(value); // Call your API search function here
|
||||
});
|
||||
}
|
||||
|
||||
setEntryType(entryType: boolean) {
|
||||
this.entryType = entryType;
|
||||
this.doSearch(this.searchInput);
|
||||
this.doSearch(this.searchControl.value);
|
||||
}
|
||||
|
||||
// ? PAGINATION
|
||||
goToPage(page: number) {
|
||||
this.currentPage = page;
|
||||
this.doSearch(this.searchInput);
|
||||
this.doSearch(this.searchControl.value);
|
||||
}
|
||||
|
||||
get pageNumbers(): number[] {
|
||||
@@ -48,26 +63,27 @@ export class SearchComponent {
|
||||
}
|
||||
|
||||
// ? EVENTS
|
||||
onInputChange(): void {
|
||||
const inputValue = this.searchInput;
|
||||
this.currentPage = 1;
|
||||
// onInputChange(): void {
|
||||
// return;
|
||||
// const inputValue = this.searchInput;
|
||||
// this.currentPage = 1;
|
||||
|
||||
if (!this.isSearchLocked) {
|
||||
console.log(this.isSearchLocked);
|
||||
this.isSearchLocked = true;
|
||||
// if (!this.isSearchLocked) {
|
||||
// console.log(this.isSearchLocked);
|
||||
// this.isSearchLocked = true;
|
||||
|
||||
this.doSearch(inputValue);
|
||||
// this.doSearch(inputValue);
|
||||
|
||||
setTimeout(() => {
|
||||
this.isSearchLocked = false;
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
// setTimeout(() => {
|
||||
// this.isSearchLocked = false;
|
||||
// }, 3000);
|
||||
// }
|
||||
// }
|
||||
|
||||
onEnterPress() {
|
||||
this.currentPage = 1;
|
||||
this.doSearch(this.searchInput);
|
||||
}
|
||||
// onEnterPress() {
|
||||
// this.currentPage = 1;
|
||||
// this.doSearch(this.searchInput);
|
||||
// }
|
||||
|
||||
// ? FUNCTIONS
|
||||
doSearch(keyword: string) {
|
||||
@@ -77,8 +93,10 @@ export class SearchComponent {
|
||||
let type = this.entryType ? 'movie' : 'tv';
|
||||
this.tmdbService
|
||||
.getByKeyword(keyword, type, this.currentPage)
|
||||
.subscribe((myEntries) => {
|
||||
this.entries = myEntries;
|
||||
.subscribe((result) => {
|
||||
this.entries = result.entries as Entry[];
|
||||
this.maxPage = result.total_pages;
|
||||
this.totalEntries = result.total_results;
|
||||
});
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ import {
|
||||
animations: [
|
||||
trigger('animateDestroy', [
|
||||
state('void', style({ opacity: '0' })),
|
||||
transition('* => void', animate('500ms ease')),
|
||||
transition('* => void', animate('300ms ease')),
|
||||
]),
|
||||
],
|
||||
})
|
||||
|
||||
@@ -45,10 +45,10 @@ export class SeenModalComponent implements OnInit {
|
||||
ngOnInit(): void {
|
||||
if (this.data == null) {
|
||||
// ? no initial data was passed: populate date field with current date
|
||||
this.watchDate = formatDate(new Date(), 'MMM dd, yyyy', 'en-US');
|
||||
this.watchDate = formatDate(new Date(), 'yyyy-MM-dd', 'en-US');
|
||||
} else {
|
||||
// ? if data is passed, populate fields
|
||||
this.watchDate = this.data.watchDate.dateFormat('yyyy-MM-dd');
|
||||
this.watchDate = formatDate(new Date(this.data.watchDate), 'yyyy-MM-dd', 'en-US');
|
||||
this.watchedWith = this.data.watchedWith.split(', ').join('\n');
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,8 @@
|
||||
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css?family=Material+Icons+Outlined" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css">
|
||||
<link rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css">
|
||||
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css"> -->
|
||||
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css"> -->
|
||||
|
||||
<link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'>
|
||||
|
||||
|
||||
Reference in new issue
Block a user