add search popup entry line
This commit is contained in:
1 parent
bd65181da3
commit
289dc98042
7 files changed
+187
-79
No files matched your search
Whitespace-only changes.
+26
@@ -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>
|
||||
+28
@@ -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();
|
||||
});
|
||||
});
|
||||
+76
@@ -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">
|
||||
<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="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>
|
||||
<app-search-popup-entry-line *ngFor="let entry of searchedEntries"
|
||||
[entry]="entry"></app-search-popup-entry-line>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
@@ -57,8 +32,6 @@
|
||||
<p class="text-muted text-center mt-4">Please search for movies and TV series.</p>
|
||||
</ng-container>
|
||||
|
||||
|
||||
|
||||
<!-- <p class="search-title">Tutorials</p>
|
||||
<div class="search-list d-flex flex-column gap-2">
|
||||
<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 {
|
||||
searchTerm: string = '';
|
||||
searchControl = new FormControl();
|
||||
searchedEntries: Entry[] = [] as Entry[];
|
||||
searchedEntries: Entry[] = [];
|
||||
recentSearches: SearchItem[] = [] as SearchItem[];
|
||||
|
||||
isAddLocked: boolean = false;
|
||||
// isAddLocked: boolean = false;
|
||||
|
||||
@ViewChild('scrollContainer', { static: true }) scrollContainer!: ElementRef;
|
||||
private ps!: PerfectScrollbar;
|
||||
@@ -38,14 +38,14 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.getSearchHisotry();
|
||||
this.getSearchHistory();
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement);
|
||||
}
|
||||
|
||||
getSearchHisotry() {
|
||||
getSearchHistory() {
|
||||
this.historyService.getSearchHistory().subscribe({
|
||||
next: (result) => {
|
||||
this.recentSearches = [
|
||||
@@ -68,7 +68,6 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
|
||||
// ! search value is passed from parent by calling this function
|
||||
triggerSearch(searchTerm: string) {
|
||||
this.searchTerm = searchTerm;
|
||||
this.searchedEntries = [] as Entry[];
|
||||
this.doSearch();
|
||||
}
|
||||
|
||||
@@ -83,51 +82,51 @@ export class SearchPopupComponent implements OnInit, AfterViewInit {
|
||||
});
|
||||
}
|
||||
|
||||
lineClick(entry: Entry) {
|
||||
this.libraryService.isInLibrary(entry.entryId.tmdb_id).subscribe({
|
||||
next: (e) => {
|
||||
if (e != null) {
|
||||
this.router.navigate([`/entries/${e.id}`]);
|
||||
} else {
|
||||
let type = entry.is_tvseries ? 'tv' : 'movie';
|
||||
window.open(
|
||||
`https://www.themoviedb.org/${type}/` + entry.entryId.tmdb_id,
|
||||
'_blank'
|
||||
);
|
||||
}
|
||||
},
|
||||
error: (error) => {},
|
||||
});
|
||||
}
|
||||
// lineClick(entry: Entry) {
|
||||
// this.libraryService.isInLibrary(entry.entryId.tmdb_id).subscribe({
|
||||
// next: (e) => {
|
||||
// if (e != null) {
|
||||
// this.router.navigate([`/entries/${e.id}`]);
|
||||
// } else {
|
||||
// let type = entry.is_tvseries ? 'tv' : 'movie';
|
||||
// window.open(
|
||||
// `https://www.themoviedb.org/${type}/` + entry.entryId.tmdb_id,
|
||||
// '_blank'
|
||||
// );
|
||||
// }
|
||||
// },
|
||||
// error: (error) => {},
|
||||
// });
|
||||
// }
|
||||
|
||||
addToLibrary(entry: Entry) {
|
||||
this.isAddLocked = true;
|
||||
entry.isLocked = true;
|
||||
const tmdbId = entry.entryId.tmdb_id;
|
||||
const isTvSerie = entry.is_tvseries;
|
||||
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;
|
||||
entry.isLocked = false;
|
||||
obs.unsubscribe();
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
// TODO error notification
|
||||
console.error('Error adding entry:', error);
|
||||
this.isAddLocked = false;
|
||||
obs.unsubscribe();
|
||||
},
|
||||
});
|
||||
}
|
||||
// addToLibrary(entry: Entry) {
|
||||
// this.isAddLocked = true;
|
||||
// entry.isLocked = true;
|
||||
// const tmdbId = entry.entryId.tmdb_id;
|
||||
// const isTvSerie = 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();
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
doShowSearchPage() {
|
||||
if (this.searchTerm) {
|
||||
|
||||
@@ -17,9 +17,15 @@ import { SeasonService } from './services/season.service';
|
||||
import { SearchPopupComponent } from './components/search-popup/search-popup.component';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
import { SearchPopupEntryLineComponent } from './components/search-popup-entry-line/search-popup-entry-line.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [SidebarComponent, NavbarComponent, SearchPopupComponent],
|
||||
declarations: [
|
||||
SidebarComponent,
|
||||
NavbarComponent,
|
||||
SearchPopupComponent,
|
||||
SearchPopupEntryLineComponent,
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
SharedModule,
|
||||
|
||||
Reference in new issue
Block a user