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>
|
<i class='bx bx-star'></i>
|
||||||
<span>{{formattedRate}}</span>
|
<span>{{formattedRate}}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="bookmark">
|
<div class="bookmark" *ngIf="!entry.isInLibrary">
|
||||||
<i class='bx bxs-bookmark' (click)="addEntry(entry.entryId.tmdb_id)"></i>
|
<i class='bx bxs-add-to-queue' (click)="addEntry(entry.entryId.tmdb_id, entry.is_tvseries)"></i>
|
||||||
</div>
|
</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">
|
<div class="info">
|
||||||
<i class='bx bx-info-circle'></i>
|
<i class='bx bx-info-circle'></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- card body moved inside card head -->
|
<!-- 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 { Entry } from '../../../shared/models/entry.model';
|
||||||
import { EntryService } from '../../../core/services/entry.service';
|
import { EntryService } from '../../../core/services/entry.service';
|
||||||
|
import { LibraryService } from '../../../core/services/library.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-main-card',
|
selector: 'app-main-card',
|
||||||
templateUrl: './main-card.component.html',
|
templateUrl: './main-card.component.html',
|
||||||
styleUrls: ['./main-card.component.css'],
|
styleUrls: ['./main-card.component.css'],
|
||||||
})
|
})
|
||||||
export class MainCardComponent {
|
export class MainCardComponent implements OnInit {
|
||||||
@Input() entry!: Entry;
|
@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 {
|
get releaseYear(): number {
|
||||||
return new Date(this.entry.release_date).getFullYear();
|
return new Date(this.entry.release_date).getFullYear();
|
||||||
@@ -20,11 +32,15 @@ export class MainCardComponent {
|
|||||||
return this.entry.entryRating.tmdb_rating.toFixed(1);
|
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.');
|
console.log('Adding Entry To Library.');
|
||||||
this.entryService.addEntry(tmdb_id).subscribe({
|
this.libraryService.addEntry(tmdb_id, is_tvserie).subscribe({
|
||||||
next: (entry) => {
|
next: (entry) => {
|
||||||
|
if (entry != null) {
|
||||||
|
entry.isInLibrary = true;
|
||||||
|
this.entry = entry;
|
||||||
console.log(entry);
|
console.log(entry);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
console.error('Error adding entry:', 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() {
|
logEntry() {
|
||||||
console.log(this.entry);
|
console.log(this.entry);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user