diff --git a/frontend/src/app/features/discover/search/search.component.css b/frontend/src/app/features/discover/search/search.component.css index e69de29..f87c161 100644 --- a/frontend/src/app/features/discover/search/search.component.css +++ b/frontend/src/app/features/discover/search/search.component.css @@ -0,0 +1,3 @@ +.ms-auto.d-flex .btn-group button { + min-width: 100px; +} \ No newline at end of file diff --git a/frontend/src/app/features/discover/search/search.component.html b/frontend/src/app/features/discover/search/search.component.html index a992c02..2f9cfce 100644 --- a/frontend/src/app/features/discover/search/search.component.html +++ b/frontend/src/app/features/discover/search/search.component.html @@ -12,25 +12,26 @@ -
-
- -
- - -
+
+
+ Search + +
+ +
+ +
-
+
  • Previous @@ -48,7 +49,7 @@ -
    +
    • Previous diff --git a/frontend/src/app/features/discover/search/search.component.ts b/frontend/src/app/features/discover/search/search.component.ts index 0985336..7a2628e 100644 --- a/frontend/src/app/features/discover/search/search.component.ts +++ b/frontend/src/app/features/discover/search/search.component.ts @@ -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; }); } } diff --git a/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.ts b/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.ts index efc6916..145f536 100644 --- a/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.ts +++ b/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.ts @@ -16,7 +16,7 @@ import { animations: [ trigger('animateDestroy', [ state('void', style({ opacity: '0' })), - transition('* => void', animate('500ms ease')), + transition('* => void', animate('300ms ease')), ]), ], }) diff --git a/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts b/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts index 4be94e5..0711366 100644 --- a/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts +++ b/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts @@ -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'); } diff --git a/frontend/src/index.html b/frontend/src/index.html index a84925c..a88c5cf 100644 --- a/frontend/src/index.html +++ b/frontend/src/index.html @@ -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" /> - - + +