From 63515a9a3941209b3a045f05df44039c660ce45e Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Thu, 6 Jun 2024 00:35:06 +0100 Subject: [PATCH] add history service& search popup component --- .../components/navbar/navbar.component.html | 104 +----------------- .../components/navbar/navbar.component.ts | 5 +- .../search-popup/search-popup.component.css | 0 .../search-popup/search-popup.component.html | 87 +++++++++++++++ .../search-popup.component.spec.ts | 23 ++++ .../search-popup/search-popup.component.ts | 57 ++++++++++ frontend/src/app/core/core.module.ts | 8 +- .../src/app/core/services/history.service.ts | 19 ++++ .../app/shared/models/search-item.model.ts | 5 + 9 files changed, 201 insertions(+), 107 deletions(-) create mode 100644 frontend/src/app/core/components/search-popup/search-popup.component.css create mode 100644 frontend/src/app/core/components/search-popup/search-popup.component.html create mode 100644 frontend/src/app/core/components/search-popup/search-popup.component.spec.ts create mode 100644 frontend/src/app/core/components/search-popup/search-popup.component.ts create mode 100644 frontend/src/app/core/services/history.service.ts create mode 100644 frontend/src/app/shared/models/search-item.model.ts diff --git a/frontend/src/app/core/components/navbar/navbar.component.html b/frontend/src/app/core/components/navbar/navbar.component.html index 0d81417..d8de4bd 100644 --- a/frontend/src/app/core/components/navbar/navbar.component.html +++ b/frontend/src/app/core/components/navbar/navbar.component.html @@ -17,113 +17,13 @@ diff --git a/frontend/src/app/core/components/navbar/navbar.component.ts b/frontend/src/app/core/components/navbar/navbar.component.ts index 0f5901d..f7fbea6 100644 --- a/frontend/src/app/core/components/navbar/navbar.component.ts +++ b/frontend/src/app/core/components/navbar/navbar.component.ts @@ -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() { diff --git a/frontend/src/app/core/components/search-popup/search-popup.component.css b/frontend/src/app/core/components/search-popup/search-popup.component.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/core/components/search-popup/search-popup.component.html b/frontend/src/app/core/components/search-popup/search-popup.component.html new file mode 100644 index 0000000..56b8c8b --- /dev/null +++ b/frontend/src/app/core/components/search-popup/search-popup.component.html @@ -0,0 +1,87 @@ +
+
+
+ + search + close +
+
+
+ +

Recent Searches

+ +
+
+

Tutorials

+
+
+
+ play_circle +
+
+
Wordpress Tutorials
+
+
+
+
+ shopping_basket +
+
+
eCommerce Website Tutorials
+
+
+ +
+
+ laptop +
+
+
Responsive Design
+
+
+
+ +
+

Members

+ +
+
+
+ +
+
+
Andrew Stark
+
+
+ +
+
+ +
+
+
Snetro Jhonia
+
+
+ +
+
+ +
+
+
Michle Clark
+
+
+ +
+
+ +
\ No newline at end of file diff --git a/frontend/src/app/core/components/search-popup/search-popup.component.spec.ts b/frontend/src/app/core/components/search-popup/search-popup.component.spec.ts new file mode 100644 index 0000000..2dbf879 --- /dev/null +++ b/frontend/src/app/core/components/search-popup/search-popup.component.spec.ts @@ -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; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [SearchPopupComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(SearchPopupComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/core/components/search-popup/search-popup.component.ts b/frontend/src/app/core/components/search-popup/search-popup.component.ts new file mode 100644 index 0000000..38686e7 --- /dev/null +++ b/frontend/src/app/core/components/search-popup/search-popup.component.ts @@ -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); + } +} diff --git a/frontend/src/app/core/core.module.ts b/frontend/src/app/core/core.module.ts index 62404ed..e11bb54 100644 --- a/frontend/src/app/core/core.module.ts +++ b/frontend/src/app/core/core.module.ts @@ -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) { diff --git a/frontend/src/app/core/services/history.service.ts b/frontend/src/app/core/services/history.service.ts new file mode 100644 index 0000000..dbd06ed --- /dev/null +++ b/frontend/src/app/core/services/history.service.ts @@ -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 { + return of([] as SearchItem[]); + } +} diff --git a/frontend/src/app/shared/models/search-item.model.ts b/frontend/src/app/shared/models/search-item.model.ts new file mode 100644 index 0000000..4a059f2 --- /dev/null +++ b/frontend/src/app/shared/models/search-item.model.ts @@ -0,0 +1,5 @@ +export interface SearchItem { + name: string; + type: string; + id: number; +}