add search popup entry line

This commit is contained in:
X4Lo committed 2025-01-14 17:55:53 +01:00
1 parent bd65181da3
commit 289dc98042
7 files changed
+187 -79

No files matched your search

@@ -0,0 +1,26 @@
<div class="search-list-item d-flex align-items-center gap-3" (click)="lineClick()">
<div class="memmber-img">
<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 | dateFormat }}
</p>
<div class="circle ms-2 me-2" *ngIf="entry.seasons"></div>
<p class="mb-0 text-secondary" style="font-size: 13px; margin-top: 2px;" *ngIf="entry.seasons">
{{ entry.seasons.length }} Seasons
</p>
</div>
</div>
<button class="btn btn-primary ms-auto" *ngIf="!entry.isInLibrary && entry.isLocked" disabled>
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<span class="visually-hidden">Loading...</span>
</button>
<button class="btn btn-primary ms-auto justify-content-center align-items-center"
*ngIf="!entry.isInLibrary && !entry.isLocked" (click)="addToLibrary(); $event.stopPropagation()">
<i class="material-icons-outlined">add_circle</i>
</button>
</div>
@@ -0,0 +1,28 @@
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { SearchPopupEntryLineComponent } from './search-popup-entry-line.component';
describe('SearchPopupEntryLineComponent', () => {
let component: SearchPopupEntryLineComponent;
let fixture: ComponentFixture<SearchPopupEntryLineComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SearchPopupEntryLineComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SearchPopupEntryLineComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,76 @@
import { Component, Input, input, OnInit } from '@angular/core';
import { Entry } from '../../../shared/models/entry.model';
import { LibraryService } from '../../services/library.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-search-popup-entry-line',
templateUrl: './search-popup-entry-line.component.html',
styleUrls: ['./search-popup-entry-line.component.css'],
})
export class SearchPopupEntryLineComponent implements OnInit {
@Input() entry!: Entry;
isAddLocked: boolean = false;
constructor(private libraryService: LibraryService, private router: Router) {}
ngOnInit() {
if (!this.entry.isInLibrary) {
this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({
next: (e) => {
if (e != null) {
e.isInLibrary = true;
this.entry = e;
}
},
error: (error) => {},
});
}
}
lineClick() {
this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({
next: (e) => {
if (e != null) {
this.router.navigate([`/entries/${e.id}`]);
} else {
let type = this.entry.is_tvseries ? 'tv' : 'movie';
window.open(
`https://www.themoviedb.org/${type}/` + this.entry.entryId.tmdb_id,
'_blank'
);
}
},
error: (error) => {},
});
}
addToLibrary() {
this.isAddLocked = true;
this.entry.isLocked = true;
const tmdbId = this.entry.entryId.tmdb_id;
const isTvSerie = this.entry.is_tvseries;
let obs = this.libraryService.addEntry(tmdbId, isTvSerie).subscribe({
next: (entry) => {
if (entry != null) {
entry.isInLibrary = true;
this.libraryService.refetchEntries().subscribe();
// this.searchedEntries.forEach((e) => {
// if (e.entryId.tmdb_id == entry.entryId.tmdb_id) {
// e.isInLibrary = true;
// }
// });
this.isAddLocked = false;
entry.isLocked = false;
obs.unsubscribe();
}
},
error: (error) => {
// TODO error notification
console.error('Error adding entry:', error);
this.isAddLocked = false;
obs.unsubscribe();
},
});
}
}
@@ -23,33 +23,8 @@
<ng-container *ngIf="searchedEntries.length != 0"> <ng-container *ngIf="searchedEntries.length != 0">
<p class="search-title">Movies & Tv-Series</p> <p class="search-title">Movies & Tv-Series</p>
<div class="search-list d-flex flex-column gap-0"> <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" <app-search-popup-entry-line *ngFor="let entry of searchedEntries"
(click)="lineClick(entry)"> [entry]="entry"></app-search-popup-entry-line>
<div class="memmber-img">
<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 | dateFormat }}
</p>
<div class="circle ms-2 me-2" *ngIf="entry.seasons"></div>
<p class="mb-0 text-secondary" style="font-size: 13px; margin-top: 2px;" *ngIf="entry.seasons">
{{ entry.seasons.length }} Seasons
</p>
</div>
</div>
<button class="btn btn-primary ms-auto" *ngIf="!entry.isInLibrary && entry.isLocked" disabled>
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<span class="visually-hidden">Loading...</span>
</button>
<button class="btn btn-primary ms-auto justify-content-center align-items-center" *ngIf="!entry.isInLibrary && !entry.isLocked"
(click)="addToLibrary(entry); $event.stopPropagation()">
<i class="material-icons-outlined">add_circle</i>
</button>
</div>
</div> </div>
</ng-container> </ng-container>
@@ -57,8 +32,6 @@
<p class="text-muted text-center mt-4">Please search for movies and TV series.</p> <p class="text-muted text-center mt-4">Please search for movies and TV series.</p>
</ng-container> </ng-container>
<!-- <p class="search-title">Tutorials</p> <!-- <p class="search-title">Tutorials</p>
<div class="search-list d-flex flex-column gap-2"> <div class="search-list d-flex flex-column gap-2">
<div class="search-list-item d-flex align-items-center gap-3"> <div class="search-list-item d-flex align-items-center gap-3">
@@ -22,10 +22,10 @@ import { Router } from '@angular/router';
export class SearchPopupComponent implements OnInit, AfterViewInit { export class SearchPopupComponent implements OnInit, AfterViewInit {
searchTerm: string = ''; searchTerm: string = '';
searchControl = new FormControl(); searchControl = new FormControl();
searchedEntries: Entry[] = [] as Entry[]; searchedEntries: Entry[] = [];
recentSearches: SearchItem[] = [] as SearchItem[]; recentSearches: SearchItem[] = [] as SearchItem[];
isAddLocked: boolean = false; // isAddLocked: boolean = false;
@ViewChild('scrollContainer', { static: true }) scrollContainer!: ElementRef; @ViewChild('scrollContainer', { static: true }) scrollContainer!: ElementRef;
private ps!: PerfectScrollbar; private ps!: PerfectScrollbar;
@@ -38,14 +38,14 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
this.getSearchHisotry(); this.getSearchHistory();
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement); this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement);
} }
getSearchHisotry() { getSearchHistory() {
this.historyService.getSearchHistory().subscribe({ this.historyService.getSearchHistory().subscribe({
next: (result) => { next: (result) => {
this.recentSearches = [ this.recentSearches = [
@@ -68,7 +68,6 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
// ! search value is passed from parent by calling this function // ! search value is passed from parent by calling this function
triggerSearch(searchTerm: string) { triggerSearch(searchTerm: string) {
this.searchTerm = searchTerm; this.searchTerm = searchTerm;
this.searchedEntries = [] as Entry[];
this.doSearch(); this.doSearch();
} }
@@ -83,51 +82,51 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
}); });
} }
lineClick(entry: Entry) { // lineClick(entry: Entry) {
this.libraryService.isInLibrary(entry.entryId.tmdb_id).subscribe({ // this.libraryService.isInLibrary(entry.entryId.tmdb_id).subscribe({
next: (e) => { // next: (e) => {
if (e != null) { // if (e != null) {
this.router.navigate([`/entries/${e.id}`]); // this.router.navigate([`/entries/${e.id}`]);
} else { // } else {
let type = entry.is_tvseries ? 'tv' : 'movie'; // let type = entry.is_tvseries ? 'tv' : 'movie';
window.open( // window.open(
`https://www.themoviedb.org/${type}/` + entry.entryId.tmdb_id, // `https://www.themoviedb.org/${type}/` + entry.entryId.tmdb_id,
'_blank' // '_blank'
); // );
} // }
}, // },
error: (error) => {}, // error: (error) => {},
}); // });
} // }
addToLibrary(entry: Entry) { // addToLibrary(entry: Entry) {
this.isAddLocked = true; // this.isAddLocked = true;
entry.isLocked = true; // entry.isLocked = true;
const tmdbId = entry.entryId.tmdb_id; // const tmdbId = entry.entryId.tmdb_id;
const isTvSerie = entry.is_tvseries; // const isTvSerie = entry.is_tvseries;
let obs = this.libraryService.addEntry(tmdbId, isTvSerie).subscribe({ // let obs = this.libraryService.addEntry(tmdbId, isTvSerie).subscribe({
next: (entry) => { // next: (entry) => {
if (entry != null) { // if (entry != null) {
entry.isInLibrary = true; // entry.isInLibrary = true;
this.libraryService.refreshEntries().subscribe(); // this.libraryService.refetchEntries().subscribe();
this.searchedEntries.forEach((e) => { // this.searchedEntries.forEach((e) => {
if (e.entryId.tmdb_id == entry.entryId.tmdb_id) { // if (e.entryId.tmdb_id == entry.entryId.tmdb_id) {
e.isInLibrary = true; // e.isInLibrary = true;
} // }
}); // });
this.isAddLocked = false; // this.isAddLocked = false;
entry.isLocked = false; // entry.isLocked = false;
obs.unsubscribe(); // obs.unsubscribe();
} // }
}, // },
error: (error) => { // error: (error) => {
// TODO error notification // // TODO error notification
console.error('Error adding entry:', error); // console.error('Error adding entry:', error);
this.isAddLocked = false; // this.isAddLocked = false;
obs.unsubscribe(); // obs.unsubscribe();
}, // },
}); // });
} // }
doShowSearchPage() { doShowSearchPage() {
if (this.searchTerm) { if (this.searchTerm) {
+7 -1
View File
@@ -17,9 +17,15 @@ import { SeasonService } from './services/season.service';
import { SearchPopupComponent } from './components/search-popup/search-popup.component'; import { SearchPopupComponent } from './components/search-popup/search-popup.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { SharedModule } from '../shared/shared.module'; import { SharedModule } from '../shared/shared.module';
import { SearchPopupEntryLineComponent } from './components/search-popup-entry-line/search-popup-entry-line.component';
@NgModule({ @NgModule({
declarations: [SidebarComponent, NavbarComponent, SearchPopupComponent], declarations: [
SidebarComponent,
NavbarComponent,
SearchPopupComponent,
SearchPopupEntryLineComponent,
],
imports: [ imports: [
CommonModule, CommonModule,
SharedModule, SharedModule,