add history service& search popup component

This commit is contained in:
X4Lo committed 2024-06-06 00:35:06 +01:00
1 parent 710ebcc934
commit 63515a9a39
9 files changed
+201 -107

No files matched your search

@@ -17,113 +17,13 @@
<div class="search-bar flex-grow-1">
<div class="position-relative">
<input class="form-control rounded-5 px-5 search-control d-lg-block d-none" type="text" placeholder="Search"
(click)="toggleSearchPopup()">
[(ngModel)]="searchTerm" (click)="toggleSearchPopup()" (keydown)="toggleSearchPopup(true)">
<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"
[ngClass]="{'d-block': showSearchPopup}" (click)="toggleSearchPopup()">close</span>
<div class="search-popup p-3" [ngClass]="{'d-block': showSearchPopup}">
<div class="card rounded-4 overflow-hidden">
<div class="card-header d-lg-none">
<div class="position-relative">
<input class="form-control rounded-5 px-5 mobile-search-control" type="text" placeholder="Search">
<span
class="material-icons-outlined position-absolute 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 mobile-search-close">close</span>
</div>
</div>
<div class="card-body search-content ps ps--active-y">
<p class="search-title">Recent Searches</p>
<div class="d-flex align-items-start flex-wrap gap-2 kewords-wrapper">
<a href="javascript:;" class="kewords"><span>Angular Template</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Dashboard</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Admin Template</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Bootstrap 5 Admin</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Html eCommerce</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>Sass</span><i
class="material-icons-outlined fs-6">search</i></a>
<a href="javascript:;" class="kewords"><span>laravel 9</span><i
class="material-icons-outlined fs-6">search</i></a>
</div>
<hr>
<p class="search-title">Tutorials</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="list-icon">
<i class="material-icons-outlined fs-5">play_circle</i>
</div>
<div class="">
<h5 class="mb-0 search-list-title ">Wordpress Tutorials</h5>
</div>
</div>
<div class="search-list-item d-flex align-items-center gap-3">
<div class="list-icon">
<i class="material-icons-outlined fs-5">shopping_basket</i>
</div>
<div class="">
<h5 class="mb-0 search-list-title">eCommerce Website Tutorials</h5>
</div>
</div>
<div class="search-list-item d-flex align-items-center gap-3">
<div class="list-icon">
<i class="material-icons-outlined fs-5">laptop</i>
</div>
<div class="">
<h5 class="mb-0 search-list-title">Responsive Design</h5>
</div>
</div>
</div>
<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 class="ps__rail-x" style="left: 0px; bottom: 0px;">
<div class="ps__thumb-x" tabindex="0" style="left: 0px; width: 0px;"></div>
</div>
<div class="ps__rail-y" style="top: 0px; right: 0px; height: 389px;">
<div class="ps__thumb-y" tabindex="0" style="top: 0px; height: 281px;"></div>
</div>
</div>
<div class="card-footer text-center bg-transparent">
<a href="javascript:;" class="btn w-100">See All Search Results</a>
</div>
</div>
<app-search-popup [searchTerm]="searchTerm"></app-search-popup>
</div>
</div>
</div>
@@ -9,6 +9,7 @@ import { Location } from '@angular/common';
})
export class NavbarComponent {
showSearchPopup: boolean = false;
searchTerm: string = '';
constructor(
private toggleService: ToggleService,
@@ -20,8 +21,8 @@ export class NavbarComponent {
this.toggleService.toggleSidebar();
}
toggleSearchPopup() {
this.showSearchPopup = !this.showSearchPopup;
toggleSearchPopup(doShow: boolean = !this.showSearchPopup) {
this.showSearchPopup = doShow;
}
closeSearchPopup() {
Whitespace-only changes.
@@ -0,0 +1,87 @@
<div class="card rounded-4 overflow-hidden">
<div class="card-header d-lg-none">
<div class="position-relative">
<input class="form-control rounded-5 px-5 mobile-search-control" type="text" placeholder="Search">
<span class="material-icons-outlined position-absolute 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 mobile-search-close">close</span>
</div>
</div>
<div class="card-body search-content" #scrollContainer>
<ng-container *ngIf="recentSearches.length > 0">
<p class="search-title">Recent Searches</p>
<div class="d-flex align-items-start flex-wrap gap-2 kewords-wrapper">
<!-- ! recent searches -->
<a class="kewords" *ngFor="let item of recentSearches">
<span>{{ item.name }}</span>
<i class="material-icons-outlined fs-6">search</i>
</a>
</div>
<hr>
</ng-container>
<p class="search-title">Tutorials</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="list-icon">
<i class="material-icons-outlined fs-5">play_circle</i>
</div>
<div class="">
<h5 class="mb-0 search-list-title ">Wordpress Tutorials</h5>
</div>
</div>
<div class="search-list-item d-flex align-items-center gap-3">
<div class="list-icon">
<i class="material-icons-outlined fs-5">shopping_basket</i>
</div>
<div class="">
<h5 class="mb-0 search-list-title">eCommerce Website Tutorials</h5>
</div>
</div>
<div class="search-list-item d-flex align-items-center gap-3">
<div class="list-icon">
<i class="material-icons-outlined fs-5">laptop</i>
</div>
<div class="">
<h5 class="mb-0 search-list-title">Responsive Design</h5>
</div>
</div>
</div>
<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 class="card-footer text-center bg-transparent">
<a href="javascript:;" class="btn w-100">See All Search Results</a>
</div>
</div>
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SearchPopupComponent } from './search-popup.component';
describe('SearchPopupComponent', () => {
let component: SearchPopupComponent;
let fixture: ComponentFixture<SearchPopupComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SearchPopupComponent]
})
.compileComponents();
fixture = TestBed.createComponent(SearchPopupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,57 @@
import {
AfterViewInit,
Component,
ElementRef,
Input,
OnInit,
ViewChild,
} from '@angular/core';
import { LibraryService } from '../../services/library.service';
import { TmdbService } from '../../services/tmdb.service';
import PerfectScrollbar from 'perfect-scrollbar';
import { HistoryService } from '../../services/history.service';
import { SearchItem } from '../../../shared/models/search-item.model';
@Component({
selector: 'app-search-popup',
templateUrl: './search-popup.component.html',
styleUrl: './search-popup.component.css',
})
export class SearchPopupComponent implements OnInit, AfterViewInit {
@Input() searchTerm: string = '';
recentSearches: SearchItem[] = [] as SearchItem[];
@ViewChild('scrollContainer', { static: true }) scrollContainer!: ElementRef;
private ps!: PerfectScrollbar;
constructor(
private libraryService: LibraryService,
private historyService: HistoryService,
private tmdbService: TmdbService
) {}
ngOnInit(): void {
this.historyService.getSearchHistory().subscribe({
next: (result) => {
this.recentSearches = [
{ name: 'Avengers Endgame', type: 'entry', id: 3 },
{ name: 'Christofer Nolan', type: 'entry', id: 3 },
{ name: 'John Wick', type: 'entry', id: 3 },
{ name: 'The Hobbit: Battle of five armies', type: 'entry', id: 3 },
{ name: 'The Hobbit: Battle of five armies', type: 'entry', id: 3 },
{ name: 'The Hobbit: Battle of five armies', type: 'entry', id: 3 },
{ name: 'The Hobbit: Battle of five armies', type: 'entry', id: 3 },
{ name: 'The Hobbit: Battle of five armies', type: 'entry', id: 3 },
];
},
error: (error) => {
console.log(`Error getting search history: `, error);
},
});
}
ngAfterViewInit(): void {
this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement);
}
}
+5 -3
View File
@@ -14,10 +14,12 @@ import { EpisodeService } from './services/episode.service';
import { EpisodeSeenService } from './services/episode-seen.service';
import { ThemeService } from './services/theme.service';
import { SeasonService } from './services/season.service';
import { SearchPopupComponent } from './components/search-popup/search-popup.component';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [SidebarComponent, NavbarComponent],
imports: [CommonModule, RouterModule],
declarations: [SidebarComponent, NavbarComponent, SearchPopupComponent],
imports: [CommonModule, RouterModule, FormsModule],
providers: [
TmdbService,
LibraryService,
@@ -32,7 +34,7 @@ import { SeasonService } from './services/season.service';
ToggleService,
ThemeService,
],
exports: [SidebarComponent, NavbarComponent],
exports: [SidebarComponent, NavbarComponent, SearchPopupComponent],
})
export class CoreModule {
constructor(@Optional() @SkipSelf() parentModule?: CoreModule) {
@@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment.prod';
import { SearchItem } from '../../shared/models/search-item.model';
import { Observable, of } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class HistoryService {
private backend_apiUrl = environment.API_URL;
private apiAction = 'history';
constructor(private http: HttpClient) {}
getSearchHistory(): Observable<SearchItem[]> {
return of([] as SearchItem[]);
}
}
@@ -0,0 +1,5 @@
export interface SearchItem {
name: string;
type: string;
id: number;
}