add to library from search popup
This commit is contained in:
1 parent
2b2cc44851
commit
9d89eda74c
3 files changed
+69
-16
No files matched your search
@@ -20,25 +20,36 @@
|
||||
<hr>
|
||||
</ng-container>
|
||||
|
||||
<ng-container *ngIf="searchedEntries.length != 0">
|
||||
<p class="search-title">Movies & Tv-Series</p>
|
||||
<div class="search-list d-flex flex-column gap-0">
|
||||
<div class="search-list-item d-flex align-items-center gap-3" *ngFor="let entry of searchedEntries" (click)="lineClick(entry)">
|
||||
<div class="search-list-item d-flex align-items-center gap-3" *ngFor="let entry of searchedEntries"
|
||||
(click)="lineClick(entry)">
|
||||
<div class="memmber-img">
|
||||
<img [src]="'https://image.tmdb.org/t/p/w92/' + entry.poster_path" width="40" height="60"
|
||||
alt="">
|
||||
<img [src]="'https://image.tmdb.org/t/p/w92/' + entry.poster_path" width="40" height="60" alt="">
|
||||
</div>
|
||||
<div class="d-flex flex-column">
|
||||
<div class="d-flex align-items-center">
|
||||
<h5 class="mb-0 search-list-title">{{ entry.title }}</h5>
|
||||
<div class="circle ms-2 me-2"></div>
|
||||
<p class="mb-0 text-secondary" style="font-size: 13px; margin-top: 2px;">
|
||||
{{ entry.release_date }}
|
||||
{{ entry.release_date | dateFormat }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-primary ms-auto" *ngIf="!entry.isInLibrary"
|
||||
(click)="addToLibrary(entry.entryId.tmdb_id, entry.is_tvseries); $event.stopPropagation()">
|
||||
<i class="material-icons-outlined fs-5">add_circle</i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
<ng-container *ngIf="searchedEntries.length == 0">
|
||||
<p class="text-muted text-center mt-4">Please search for movies and TV series.</p>
|
||||
</ng-container>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<!-- <p class="search-title">Tutorials</p>
|
||||
<div class="search-list d-flex flex-column gap-2">
|
||||
@@ -72,7 +83,7 @@
|
||||
<hr> -->
|
||||
|
||||
</div>
|
||||
<div class="card-footer text-center bg-transparent">
|
||||
<a href="javascript:;" class="btn w-100">See All Search Results</a>
|
||||
<div class="card-footer text-center bg-transparent" *ngIf="searchedEntries.length != 0">
|
||||
<a href="javascript:;" class="btn w-100" (click)="doShowSearchPage()">See All Search Results</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2,7 +2,6 @@ import {
|
||||
AfterViewInit,
|
||||
Component,
|
||||
ElementRef,
|
||||
Input,
|
||||
OnInit,
|
||||
ViewChild,
|
||||
} from '@angular/core';
|
||||
@@ -26,6 +25,8 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
|
||||
searchedEntries: Entry[] = [] as Entry[];
|
||||
recentSearches: SearchItem[] = [] as SearchItem[];
|
||||
|
||||
isAddLocked: boolean = false;
|
||||
|
||||
@ViewChild('scrollContainer', { static: true }) scrollContainer!: ElementRef;
|
||||
private ps!: PerfectScrollbar;
|
||||
|
||||
@@ -37,6 +38,14 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.getSearchHisotry();
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement);
|
||||
}
|
||||
|
||||
getSearchHisotry() {
|
||||
this.historyService.getSearchHistory().subscribe({
|
||||
next: (result) => {
|
||||
this.recentSearches = [
|
||||
@@ -56,10 +65,7 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement);
|
||||
}
|
||||
|
||||
// ! search value is passed from parent by calling this function
|
||||
triggerSearch(searchTerm: string) {
|
||||
this.searchTerm = searchTerm;
|
||||
this.searchedEntries = [] as Entry[];
|
||||
@@ -93,4 +99,37 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
|
||||
error: (error) => {},
|
||||
});
|
||||
}
|
||||
|
||||
addToLibrary(tmdbId: string, isTvSerie: boolean) {
|
||||
this.isAddLocked = true;
|
||||
let obs = this.libraryService.addEntry(tmdbId, isTvSerie).subscribe({
|
||||
next: (entry) => {
|
||||
if (entry != null) {
|
||||
entry.isInLibrary = true;
|
||||
this.libraryService.refreshEntries().subscribe();
|
||||
this.searchedEntries.forEach((e) => {
|
||||
if (e.entryId.tmdb_id == entry.entryId.tmdb_id) {
|
||||
e.isInLibrary = true;
|
||||
}
|
||||
});
|
||||
this.isAddLocked = false;
|
||||
obs.unsubscribe();
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
// TODO error notification
|
||||
console.error('Error adding entry:', error);
|
||||
this.isAddLocked = false;
|
||||
obs.unsubscribe();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
doShowSearchPage() {
|
||||
if (this.searchTerm) {
|
||||
this.router.navigate(['/search'], {
|
||||
queryParams: { title: this.searchTerm },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,14 @@ export class LibraryService implements OnInit {
|
||||
private backend_apiUrl = environment.API_URL;
|
||||
private apiAction = 'entries';
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.fetchAllEntries();
|
||||
constructor(private http: HttpClient) {
|
||||
this.fetchAllEntries().subscribe(() => {
|
||||
console.log(`Library Service: Loaded ${this.entries.length} entry.`);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {}
|
||||
|
||||
getAllEntries(forceFetch: boolean = false): Observable<Entry[]> {
|
||||
if (!forceFetch && this.entriesLoaded) {
|
||||
return of(this.entries);
|
||||
@@ -169,6 +171,7 @@ export class LibraryService implements OnInit {
|
||||
// );
|
||||
// }
|
||||
public isInLibrary(tmdb_id: string): Observable<Entry | null> {
|
||||
console.log(`is in library called`);
|
||||
const existingEntry = this.entries.find(
|
||||
(entry) => entry.entryId.tmdb_id == tmdb_id
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user