diff --git a/frontend/src/app/features/discover/search-page/search-page.component.css b/frontend/src/app/features/discover/search-page/search-page.component.css
index 0e15440..3922b85 100644
--- a/frontend/src/app/features/discover/search-page/search-page.component.css
+++ b/frontend/src/app/features/discover/search-page/search-page.component.css
@@ -6,4 +6,10 @@
text-align: center;
padding: 20px;
font-size: 1.2em;
+}
+
+.loading-button {
+ text-align: center;
+ padding: 20px;
+ font-size: 1.2em;
}
\ No newline at end of file
diff --git a/frontend/src/app/features/discover/search-page/search-page.component.html b/frontend/src/app/features/discover/search-page/search-page.component.html
index d86e263..1ab6274 100644
--- a/frontend/src/app/features/discover/search-page/search-page.component.html
+++ b/frontend/src/app/features/discover/search-page/search-page.component.html
@@ -31,12 +31,11 @@
-
+ -->
-
+
Loading...
-
+
-
\ No newline at end of file
+
-->
\ No newline at end of file
diff --git a/frontend/src/app/features/discover/search-page/search-page.component.ts b/frontend/src/app/features/discover/search-page/search-page.component.ts
index bde1602..e33c0cc 100644
--- a/frontend/src/app/features/discover/search-page/search-page.component.ts
+++ b/frontend/src/app/features/discover/search-page/search-page.component.ts
@@ -1,22 +1,34 @@
-import { Component, HostListener, OnInit, ViewChild } from '@angular/core';
+import {
+ Component,
+ HostListener,
+ OnDestroy,
+ OnInit,
+ ViewChild,
+} 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, forkJoin } from 'rxjs';
+import {
+ debounceTime,
+ distinctUntilChanged,
+ forkJoin,
+ Subscription,
+} from 'rxjs';
import { ActivatedRoute } from '@angular/router';
+import { ScrollService } from '../../../core/services/scroll.service';
@Component({
selector: 'app-search-page',
templateUrl: './search-page.component.html',
styleUrls: ['./search-page.component.css'],
})
-export class SearchPageComponent implements OnInit {
+export class SearchPageComponent implements OnInit, OnDestroy {
entryType: boolean = true;
entries: Entry[] = [];
isSearchLocked: boolean = false;
endPoint: string = '';
- loading: boolean = false;
+ isLoading: boolean = false;
keyword: string = '';
@@ -30,9 +42,12 @@ export class SearchPageComponent implements OnInit {
totalEntries: number = 0;
searchControl = new FormControl();
+ private scrollSubscription!: Subscription;
+
constructor(
+ private route: ActivatedRoute,
private tmdbService: TmdbService,
- private route: ActivatedRoute
+ private scrollService: ScrollService
) {}
ngOnInit() {
@@ -53,20 +68,18 @@ export class SearchPageComponent implements OnInit {
this.searchControl.setValue(title);
}
});
+
+ this.scrollSubscription = this.scrollService.scrollEnd$.subscribe(() => {
+ if (!this.isLoading) {
+ this.loadNext();
+ }
+ });
}
- // @ViewChild(PerfectScrollbarComponent) componentRef?: PerfectScrollbarComponent;
-
- @HostListener('window:scroll', ['$event'])
- onScroll(event: Event): void {
- console.log(1);
- const pos =
- (document.documentElement.scrollTop || document.body.scrollTop) +
- window.innerHeight;
- const max = document.documentElement.scrollHeight;
-
- if (pos >= max - 80 && !this.loading) {
- this.loadNext();
+ ngOnDestroy(): void {
+ // Unsubscribe to avoid memory leaks
+ if (this.scrollSubscription) {
+ this.scrollSubscription.unsubscribe();
}
}
@@ -93,28 +106,6 @@ export class SearchPageComponent implements OnInit {
}
// ? EVENTS
- // onInputChange(): void {
- // return;
- // 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);
- // }
-
// ? EVENT CATCHER
entryUpdated(event: Event) {}
@@ -153,18 +144,18 @@ export class SearchPageComponent implements OnInit {
}
loadNext() {
- this.loading = true;
+ this.isLoading = true;
this.currentPage += 1;
this.tmdbService
.getByKeywordMulti(this.keyword, this.currentPage)
.subscribe({
next: (result) => {
this.entries = this.entries.concat(result.entries as Entry[]);
- this.loading = false;
+ this.isLoading = false;
},
error: (error) => {
console.log(`Error: can't search entries...`, error);
- this.loading = false;
+ this.isLoading = false;
},
});
}