search using search popup
This commit is contained in:
1 parent
28f304faa2
commit
58edac7259
5 files changed
+107
-40
No files matched your search
@@ -17,13 +17,14 @@
|
|||||||
<div class="search-bar flex-grow-1">
|
<div class="search-bar flex-grow-1">
|
||||||
<div class="position-relative">
|
<div class="position-relative">
|
||||||
<input class="form-control rounded-5 px-5 search-control d-lg-block d-none" type="text" placeholder="Search"
|
<input class="form-control rounded-5 px-5 search-control d-lg-block d-none" type="text" placeholder="Search"
|
||||||
[(ngModel)]="searchTerm" (click)="toggleSearchPopup()" (keydown)="toggleSearchPopup(true)">
|
[formControl]="searchControl" (click)="toggleSearchPopup()" (keydown)="toggleSearchPopup(true)"
|
||||||
|
(keyup.enter)="doShowSearchPage()">
|
||||||
<span
|
<span
|
||||||
class="material-icons-outlined position-absolute d-lg-block d-none ms-3 translate-middle-y start-0 top-50">search</span>
|
class="material-icons-outlined position-absolute d-lg-block d-none ms-3 translate-middle-y start-0 top-50">search</span>
|
||||||
<span class="material-icons-outlined position-absolute me-3 translate-middle-y end-0 top-50 search-close"
|
<span class="material-icons-outlined position-absolute me-3 translate-middle-y end-0 top-50 search-close"
|
||||||
[ngClass]="{'d-block': showSearchPopup}" (click)="toggleSearchPopup()">close</span>
|
[ngClass]="{'d-block': showSearchPopup}" (click)="toggleSearchPopup()">close</span>
|
||||||
<div class="search-popup p-3" [ngClass]="{'d-block': showSearchPopup}">
|
<div class="search-popup p-3" [ngClass]="{'d-block': showSearchPopup}">
|
||||||
<app-search-popup [searchTerm]="searchTerm"></app-search-popup>
|
<app-search-popup></app-search-popup>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,22 +1,42 @@
|
|||||||
import { Component, ElementRef, HostListener } from '@angular/core';
|
import { Component, ElementRef, HostListener, OnInit, ViewChild } from '@angular/core';
|
||||||
import { ToggleService } from '../../services/toggle.service';
|
import { ToggleService } from '../../services/toggle.service';
|
||||||
import { Location } from '@angular/common';
|
import { Location } from '@angular/common';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { FormControl } from '@angular/forms';
|
||||||
|
import { debounceTime, distinctUntilChanged } from 'rxjs';
|
||||||
|
import { SearchPopupComponent } from '../search-popup/search-popup.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-navbar',
|
selector: 'app-navbar',
|
||||||
templateUrl: './navbar.component.html',
|
templateUrl: './navbar.component.html',
|
||||||
styleUrls: ['./navbar.component.css'],
|
styleUrls: ['./navbar.component.css'],
|
||||||
})
|
})
|
||||||
export class NavbarComponent {
|
export class NavbarComponent implements OnInit {
|
||||||
showSearchPopup: boolean = false;
|
showSearchPopup: boolean = false;
|
||||||
searchTerm: string = '';
|
searchTerm: string = '';
|
||||||
|
|
||||||
|
searchControl = new FormControl();
|
||||||
|
@ViewChild(SearchPopupComponent) searchPopupComponent!: SearchPopupComponent;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private toggleService: ToggleService,
|
private toggleService: ToggleService,
|
||||||
private eRef: ElementRef,
|
private eRef: ElementRef,
|
||||||
private location: Location
|
private location: Location,
|
||||||
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
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.searchTerm = value;
|
||||||
|
this.searchPopupComponent.triggerSearch(value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
toggleSidebar() {
|
toggleSidebar() {
|
||||||
this.toggleService.toggleSidebar();
|
this.toggleService.toggleSidebar();
|
||||||
}
|
}
|
||||||
@@ -29,6 +49,15 @@ export class NavbarComponent {
|
|||||||
// if (this.showSearchPopup) this.showSearchPopup = !this.showSearchPopup;
|
// if (this.showSearchPopup) this.showSearchPopup = !this.showSearchPopup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doShowSearchPage() {
|
||||||
|
const searchTerm = this.searchControl.value.trim();
|
||||||
|
if (searchTerm) {
|
||||||
|
this.router.navigate(['/search'], {
|
||||||
|
queryParams: { title: searchTerm },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@HostListener('document:click', ['$event'])
|
@HostListener('document:click', ['$event'])
|
||||||
clickout(event: { target: any }) {
|
clickout(event: { target: any }) {
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
.circle {
|
||||||
|
width: 5px;
|
||||||
|
height: 5px;
|
||||||
|
background-color: #6c757d;
|
||||||
|
border-radius: 50%;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
@@ -19,7 +19,28 @@
|
|||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<p class="search-title">Tutorials</p>
|
|
||||||
|
<p class="search-title">Movies & Tv-Series</p>
|
||||||
|
<div class="search-list d-flex flex-column gap-0">
|
||||||
|
<div class="search-list-item d-flex align-items-center gap-3" *ngFor="let entry of searchedEntries" (click)="lineClick(entry)">
|
||||||
|
<div class="memmber-img">
|
||||||
|
<img [src]="'https://image.tmdb.org/t/p/w92/' + entry.poster_path" width="40" height="60"
|
||||||
|
alt="">
|
||||||
|
</div>
|
||||||
|
<div class="d-flex flex-column">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<h5 class="mb-0 search-list-title">{{ entry.title }}</h5>
|
||||||
|
<div class="circle ms-2 me-2"></div>
|
||||||
|
<p class="mb-0 text-secondary" style="font-size: 13px; margin-top: 2px;">
|
||||||
|
{{ entry.release_date }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- <p class="search-title">Tutorials</p>
|
||||||
<div class="search-list d-flex flex-column gap-2">
|
<div class="search-list d-flex flex-column gap-2">
|
||||||
<div class="search-list-item d-flex align-items-center gap-3">
|
<div class="search-list-item d-flex align-items-center gap-3">
|
||||||
<div class="list-icon">
|
<div class="list-icon">
|
||||||
@@ -48,38 +69,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr> -->
|
||||||
<p class="search-title">Members</p>
|
|
||||||
|
|
||||||
<div class="search-list d-flex flex-column gap-2">
|
|
||||||
<div class="search-list-item d-flex align-items-center gap-3">
|
|
||||||
<div class="memmber-img">
|
|
||||||
<img src="assets/images/logo3.png" width="32" height="32" class="rounded-circle" alt="">
|
|
||||||
</div>
|
|
||||||
<div class="">
|
|
||||||
<h5 class="mb-0 search-list-title ">Andrew Stark</h5>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="search-list-item d-flex align-items-center gap-3">
|
|
||||||
<div class="memmber-img">
|
|
||||||
<img src="assets/images/logo3.png" width="32" height="32" class="rounded-circle" alt="">
|
|
||||||
</div>
|
|
||||||
<div class="">
|
|
||||||
<h5 class="mb-0 search-list-title ">Snetro Jhonia</h5>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="search-list-item d-flex align-items-center gap-3">
|
|
||||||
<div class="memmber-img">
|
|
||||||
<img src="assets/images/logo3.png" width="32" height="32" class="rounded-circle" alt="">
|
|
||||||
</div>
|
|
||||||
<div class="">
|
|
||||||
<h5 class="mb-0 search-list-title">Michle Clark</h5>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer text-center bg-transparent">
|
<div class="card-footer text-center bg-transparent">
|
||||||
<a href="javascript:;" class="btn w-100">See All Search Results</a>
|
<a href="javascript:;" class="btn w-100">See All Search Results</a>
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import { TmdbService } from '../../services/tmdb.service';
|
|||||||
import PerfectScrollbar from 'perfect-scrollbar';
|
import PerfectScrollbar from 'perfect-scrollbar';
|
||||||
import { HistoryService } from '../../services/history.service';
|
import { HistoryService } from '../../services/history.service';
|
||||||
import { SearchItem } from '../../../shared/models/search-item.model';
|
import { SearchItem } from '../../../shared/models/search-item.model';
|
||||||
|
import { FormControl } from '@angular/forms';
|
||||||
|
import { Entry } from '../../../shared/models/entry.model';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-search-popup',
|
selector: 'app-search-popup',
|
||||||
@@ -18,8 +21,9 @@ import { SearchItem } from '../../../shared/models/search-item.model';
|
|||||||
styleUrl: './search-popup.component.css',
|
styleUrl: './search-popup.component.css',
|
||||||
})
|
})
|
||||||
export class SearchPopupComponent implements OnInit, AfterViewInit {
|
export class SearchPopupComponent implements OnInit, AfterViewInit {
|
||||||
@Input() searchTerm: string = '';
|
searchTerm: string = '';
|
||||||
|
searchControl = new FormControl();
|
||||||
|
searchedEntries: Entry[] = [] as Entry[];
|
||||||
recentSearches: SearchItem[] = [] as SearchItem[];
|
recentSearches: SearchItem[] = [] as SearchItem[];
|
||||||
|
|
||||||
@ViewChild('scrollContainer', { static: true }) scrollContainer!: ElementRef;
|
@ViewChild('scrollContainer', { static: true }) scrollContainer!: ElementRef;
|
||||||
@@ -28,7 +32,8 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
|
|||||||
constructor(
|
constructor(
|
||||||
private libraryService: LibraryService,
|
private libraryService: LibraryService,
|
||||||
private historyService: HistoryService,
|
private historyService: HistoryService,
|
||||||
private tmdbService: TmdbService
|
private tmdbService: TmdbService,
|
||||||
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@@ -54,4 +59,38 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
|
|||||||
ngAfterViewInit(): void {
|
ngAfterViewInit(): void {
|
||||||
this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement);
|
this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
triggerSearch(searchTerm: string) {
|
||||||
|
this.searchTerm = searchTerm;
|
||||||
|
this.searchedEntries = [] as Entry[];
|
||||||
|
this.doSearch();
|
||||||
|
}
|
||||||
|
|
||||||
|
doSearch() {
|
||||||
|
this.tmdbService.getByKeywordMulti(this.searchTerm, 1).subscribe({
|
||||||
|
next: (result) => {
|
||||||
|
this.searchedEntries = result.entries;
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.log(`Couldn't fetch entries from tmdb, `, error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
lineClick(entry: Entry) {
|
||||||
|
this.libraryService.isInLibrary(entry.entryId.tmdb_id).subscribe({
|
||||||
|
next: (e) => {
|
||||||
|
if (e != null) {
|
||||||
|
this.router.navigate([`/entries/${e.id}`]);
|
||||||
|
} else {
|
||||||
|
let type = entry.is_tvseries ? 'tv' : 'movie';
|
||||||
|
window.open(
|
||||||
|
`https://www.themoviedb.org/${type}/` + entry.entryId.tmdb_id,
|
||||||
|
'_blank'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: (error) => {},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user