improved search component
This commit is contained in:
1 parent
60faa34363
commit
ff76e3900b
6 files changed
+64
-43
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
.ms-auto.d-flex .btn-group button {
|
||||||
|
min-width: 100px;
|
||||||
|
}
|
||||||
@@ -12,25 +12,26 @@
|
|||||||
</ol>
|
</ol>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</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"
|
<div class="ms-auto d-flex align-items-center">
|
||||||
(click)="setEntryType(false)">TV-Series</button>
|
<div class="input-group me-3">
|
||||||
</div>
|
<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 w-100" [class.active]="entryType === false"
|
||||||
|
(click)="setEntryType(false)">TV-Series</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--end breadcrumb-->
|
<!--end breadcrumb-->
|
||||||
|
|
||||||
<!-- Pagination -->
|
<!-- 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">
|
<ul class="pagination pagination-sm">
|
||||||
<li class="page-item" [class.disabled]="currentPage === 1">
|
<li class="page-item" [class.disabled]="currentPage === 1">
|
||||||
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
<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>
|
<app-dynamic-entry-list [entries]="entries"></app-dynamic-entry-list>
|
||||||
|
|
||||||
<!-- Pagination -->
|
<!-- 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">
|
<ul class="pagination pagination-sm">
|
||||||
<li class="page-item" [class.disabled]="currentPage === 1">
|
<li class="page-item" [class.disabled]="currentPage === 1">
|
||||||
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
<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 { Entry } from '../../../shared/models/entry.model';
|
||||||
import { TmdbService } from '../../../core/services/tmdb.service';
|
import { TmdbService } from '../../../core/services/tmdb.service';
|
||||||
|
import { FormControl } from '@angular/forms';
|
||||||
|
import { debounceTime, distinctUntilChanged } from 'rxjs';
|
||||||
|
|
||||||
@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 implements OnInit {
|
||||||
entryType: boolean = true;
|
entryType: boolean = true;
|
||||||
entries: Entry[] = [];
|
entries: Entry[] = [];
|
||||||
isSearchLocked: boolean = false;
|
isSearchLocked: boolean = false;
|
||||||
@@ -17,23 +19,36 @@ export class SearchComponent {
|
|||||||
true: {},
|
true: {},
|
||||||
false: {},
|
false: {},
|
||||||
};
|
};
|
||||||
currentPage: number = 1;
|
|
||||||
|
|
||||||
searchInput: string = '';
|
currentPage: number = 1;
|
||||||
|
maxPage: number = 0;
|
||||||
|
totalEntries: number = 0;
|
||||||
|
searchControl = new FormControl();
|
||||||
|
|
||||||
constructor(private tmdbService: TmdbService) {}
|
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) {
|
setEntryType(entryType: boolean) {
|
||||||
this.entryType = entryType;
|
this.entryType = entryType;
|
||||||
this.doSearch(this.searchInput);
|
this.doSearch(this.searchControl.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ? PAGINATION
|
// ? PAGINATION
|
||||||
goToPage(page: number) {
|
goToPage(page: number) {
|
||||||
this.currentPage = page;
|
this.currentPage = page;
|
||||||
this.doSearch(this.searchInput);
|
this.doSearch(this.searchControl.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get pageNumbers(): number[] {
|
get pageNumbers(): number[] {
|
||||||
@@ -48,26 +63,27 @@ export class SearchComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ? EVENTS
|
// ? EVENTS
|
||||||
onInputChange(): void {
|
// onInputChange(): void {
|
||||||
const inputValue = this.searchInput;
|
// return;
|
||||||
this.currentPage = 1;
|
// const inputValue = this.searchInput;
|
||||||
|
// this.currentPage = 1;
|
||||||
|
|
||||||
if (!this.isSearchLocked) {
|
// if (!this.isSearchLocked) {
|
||||||
console.log(this.isSearchLocked);
|
// console.log(this.isSearchLocked);
|
||||||
this.isSearchLocked = true;
|
// this.isSearchLocked = true;
|
||||||
|
|
||||||
this.doSearch(inputValue);
|
// this.doSearch(inputValue);
|
||||||
|
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
this.isSearchLocked = false;
|
// this.isSearchLocked = false;
|
||||||
}, 3000);
|
// }, 3000);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
onEnterPress() {
|
// onEnterPress() {
|
||||||
this.currentPage = 1;
|
// this.currentPage = 1;
|
||||||
this.doSearch(this.searchInput);
|
// this.doSearch(this.searchInput);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// ? FUNCTIONS
|
// ? FUNCTIONS
|
||||||
doSearch(keyword: string) {
|
doSearch(keyword: string) {
|
||||||
@@ -77,8 +93,10 @@ export class SearchComponent {
|
|||||||
let type = this.entryType ? 'movie' : 'tv';
|
let type = this.entryType ? 'movie' : 'tv';
|
||||||
this.tmdbService
|
this.tmdbService
|
||||||
.getByKeyword(keyword, type, this.currentPage)
|
.getByKeyword(keyword, type, this.currentPage)
|
||||||
.subscribe((myEntries) => {
|
.subscribe((result) => {
|
||||||
this.entries = myEntries;
|
this.entries = result.entries as Entry[];
|
||||||
|
this.maxPage = result.total_pages;
|
||||||
|
this.totalEntries = result.total_results;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -16,7 +16,7 @@ import {
|
|||||||
animations: [
|
animations: [
|
||||||
trigger('animateDestroy', [
|
trigger('animateDestroy', [
|
||||||
state('void', style({ opacity: '0' })),
|
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 {
|
ngOnInit(): void {
|
||||||
if (this.data == null) {
|
if (this.data == null) {
|
||||||
// ? no initial data was passed: populate date field with current date
|
// ? 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 {
|
} else {
|
||||||
// ? if data is passed, populate fields
|
// ? 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');
|
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" />
|
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/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 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@4.1.0-rc.0/dist/css/select2.min.css"> -->
|
||||||
<link rel="stylesheet"
|
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css"> -->
|
||||||
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'>
|
<link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user