diff --git a/frontend/src/app/features/pages/search/search.component.html b/frontend/src/app/features/pages/search/search.component.html
index 2450b0a..a992c02 100644
--- a/frontend/src/app/features/pages/search/search.component.html
+++ b/frontend/src/app/features/pages/search/search.component.html
@@ -1 +1,64 @@
-
Search
+
+
+
Discover
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/frontend/src/app/features/pages/search/search.component.ts b/frontend/src/app/features/pages/search/search.component.ts
index a9a87d0..4f71763 100644
--- a/frontend/src/app/features/pages/search/search.component.ts
+++ b/frontend/src/app/features/pages/search/search.component.ts
@@ -1,10 +1,84 @@
import { Component } from '@angular/core';
+import { TmdbService } from '../../../core/services/tmdb.service';
+import { Entry } from '../../../shared/models/entry.model';
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
- styleUrls: ['./search.component.css']
+ styleUrls: ['./search.component.css'],
})
export class SearchComponent {
+ entryType: boolean = true;
+ entries: Entry[] = [];
+ isSearchLocked: boolean = false;
+ endPoint: string = '';
+ pages: Record> = {
+ true: {},
+ false: {},
+ };
+ currentPage: number = 1;
+
+ searchInput: string = '';
+
+ constructor(private tmdbService: TmdbService) {}
+
+ ngOnInit() {}
+
+ setEntryType(entryType: boolean) {
+ this.entryType = entryType;
+ this.doSearch(this.searchInput);
+ }
+
+ // ? PAGINATION
+ goToPage(page: number) {
+ this.currentPage = page;
+ this.doSearch(this.searchInput);
+ }
+
+ get pageNumbers(): number[] {
+ this.currentPage = this.currentPage <= 0 ? 1 : this.currentPage; // page <= 0 fix
+ let startPage = this.currentPage <= 3 ? 1 : this.currentPage - 2;
+ let endPage = startPage + 4;
+
+ return Array.from(
+ { length: endPage - startPage + 1 },
+ (_, i) => startPage + i
+ );
+ }
+
+ // ? EVENTS
+ onInputChange(): void {
+ const inputValue = this.searchInput;
+ this.currentPage = 1;
+
+ if (!this.isSearchLocked) {
+ console.log(this.isSearchLocked);
+ this.isSearchLocked = true;
+
+ this.doSearch(inputValue);
+
+ setTimeout(() => {
+ this.isSearchLocked = false;
+ }, 3000);
+ }
+ }
+
+ onEnterPress() {
+ this.currentPage = 1;
+ this.doSearch(this.searchInput);
+ }
+
+ // ? FUNCTIONS
+ doSearch(keyword: string) {
+ keyword = keyword.toLowerCase().trim();
+ if (keyword.length <= 0) return;
+
+ let type = this.entryType ? 'movie' : 'tv';
+ this.tmdbService
+ .getByKeyword(keyword, type, this.currentPage)
+ .subscribe((myEntries) => {
+ this.entries = myEntries;
+ });
+ }
}