add dynamic card buttons
This commit is contained in:
1 parent
2a72d32852
commit
a00463c06f
2 files changed
+46
-7
No files matched your search
@@ -7,12 +7,18 @@
|
||||
<i class='bx bx-star'></i>
|
||||
<span>{{formattedRate}}</span>
|
||||
</div>
|
||||
<div class="bookmark">
|
||||
<i class='bx bxs-bookmark' (click)="addEntry(entry.entryId.tmdb_id)"></i>
|
||||
<div class="bookmark" *ngIf="!entry.isInLibrary">
|
||||
<i class='bx bxs-add-to-queue' (click)="addEntry(entry.entryId.tmdb_id, entry.is_tvseries)"></i>
|
||||
</div>
|
||||
<div class="bookmark" *ngIf="entry.isInLibrary">
|
||||
<i class='bx bxs-trash' (click)="removeEntry(entry.id)" style="color: #d42f50;"></i>
|
||||
</div>
|
||||
|
||||
<!-- <div [ngClass]="{'info': !entry.isInLibrary, 'bookmark': entry.isInLibrary}"> -->
|
||||
<div class="info">
|
||||
<i class='bx bx-info-circle'></i>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- card body moved inside card head -->
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Entry } from '../../../shared/models/entry.model';
|
||||
import { EntryService } from '../../../core/services/entry.service';
|
||||
import { LibraryService } from '../../../core/services/library.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-main-card',
|
||||
templateUrl: './main-card.component.html',
|
||||
styleUrls: ['./main-card.component.css'],
|
||||
})
|
||||
export class MainCardComponent {
|
||||
export class MainCardComponent implements OnInit {
|
||||
@Input() entry!: Entry;
|
||||
|
||||
constructor(private entryService: EntryService) {}
|
||||
constructor(private libraryService: LibraryService) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({
|
||||
next: (e) => {
|
||||
if (e != null) {
|
||||
e.isInLibrary = true;
|
||||
this.entry = e;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
get releaseYear(): number {
|
||||
return new Date(this.entry.release_date).getFullYear();
|
||||
@@ -20,11 +32,15 @@ export class MainCardComponent {
|
||||
return this.entry.entryRating.tmdb_rating.toFixed(1);
|
||||
}
|
||||
|
||||
addEntry(tmdb_id: string) {
|
||||
addEntry(tmdb_id: string, is_tvserie: boolean) {
|
||||
console.log('Adding Entry To Library.');
|
||||
this.entryService.addEntry(tmdb_id).subscribe({
|
||||
this.libraryService.addEntry(tmdb_id, is_tvserie).subscribe({
|
||||
next: (entry) => {
|
||||
if (entry != null) {
|
||||
entry.isInLibrary = true;
|
||||
this.entry = entry;
|
||||
console.log(entry);
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error adding entry:', error);
|
||||
@@ -32,6 +48,23 @@ export class MainCardComponent {
|
||||
});
|
||||
}
|
||||
|
||||
removeEntry(id: number) {
|
||||
console.log('Deleting Entry From Library.');
|
||||
this.libraryService.deleteEntry(id).subscribe({
|
||||
next: (response) => {
|
||||
// Handle successful deletion
|
||||
console.log('Entry successfully deleted.', response);
|
||||
this.entry.id = 0;
|
||||
this.entry.isInLibrary = false;
|
||||
},
|
||||
error: (error) => {
|
||||
// Handle error scenario
|
||||
console.error('Error deleting entry:', error);
|
||||
// Optionally, display an error message to the user using a service or a component
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
logEntry() {
|
||||
console.log(this.entry);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user