Front: fix entry removed from collection not updating UI
This commit is contained in:
1 parent
302f2830ff
commit
1e1384d777
10 files changed
+170
-73
No files matched your search
@@ -23,7 +23,7 @@ export class CollectionService {
|
||||
}
|
||||
|
||||
// get a list by id
|
||||
getCollection(collectionId: string) {
|
||||
getCollection(collectionId: number): Observable<Collection> {
|
||||
return this.http.get<Collection>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}`
|
||||
);
|
||||
|
||||
+5
-5
@@ -94,15 +94,15 @@ export class CollectionEntryCardComponent implements OnInit {
|
||||
.removeEntryFromCollection(this.collectionId, this.entry.id)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
// TODO confirm notification
|
||||
|
||||
console.log('Entry successfully removed from list.', response);
|
||||
// TODO toast: entry removed from collection
|
||||
// console.log('Entry successfully removed from collection.', response);
|
||||
this.emitRefrechEvent();
|
||||
this.entry.id = 0;
|
||||
this.entry.isInLibrary = false;
|
||||
},
|
||||
error: (error) => {
|
||||
// TODO error notification
|
||||
console.error('Error removing entry from list:', error);
|
||||
console.error('Error removing entry from collection:', error);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -116,6 +116,6 @@ export class CollectionEntryCardComponent implements OnInit {
|
||||
|
||||
// ? EVENT EMITTER
|
||||
emitRefrechEvent() {
|
||||
this.refrechEvent.emit();
|
||||
this.refrechEvent.emit({ type: 'delete', id: this.entry.id });
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<div class="movies-container">
|
||||
<ng-container *ngFor="let entry of entries">
|
||||
<app-collection-entry-card [entry]="entry" [collectionId]="collectionId" (refrechEvent)="refrechEventReceiver()"
|
||||
<app-collection-entry-card [entry]="entry" [collectionId]="collectionId" (refrechEvent)="onRefrechEvent($event)"
|
||||
@animateDestroy>
|
||||
</app-collection-entry-card>
|
||||
</ng-container>
|
||||
|
||||
+4
-3
@@ -1,4 +1,4 @@
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||
import { Entry } from '../../../../shared/models/entry.model';
|
||||
|
||||
import {
|
||||
@@ -23,8 +23,9 @@ import {
|
||||
export class CollectionEntryGridComponent {
|
||||
@Input() entries: Entry[] = [];
|
||||
@Input() collectionId!: number;
|
||||
@Output() refrechEvent = new EventEmitter();
|
||||
|
||||
refrechEventReceiver() {
|
||||
console.log('event recieved');
|
||||
onRefrechEvent(eventData: any) {
|
||||
this.refrechEvent.emit(eventData);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
<div class="product-table">
|
||||
<div class="table-responsive white-space-nowrap">
|
||||
<table class="table align-middle">
|
||||
<thead class="table-light">
|
||||
<thead class="">
|
||||
<!-- * table head start -->
|
||||
<tr>
|
||||
<th>
|
||||
|
||||
+6
-2
@@ -14,6 +14,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<!--end breadcrumb-->
|
||||
|
||||
<!-- <div class="card w-100" [ngStyle]="{'background-image': 'url(' + getCollectionBackdropPath(collection) + ')', 'background-size': 'cover', 'background-position': 'center'}"> -->
|
||||
<!-- <div class="card-body p-0" style="background: rgba(0, 0, 0, 0.5);"> -->
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
@@ -58,8 +62,8 @@
|
||||
<!-- ! grid -->
|
||||
<div id="gridDiv" *ngIf="viewMode == 'grid'">
|
||||
<h1 *ngIf="screenMode">{{collection.name}}</h1>
|
||||
<app-collection-entry-grid [entries]="collection.entries"
|
||||
[collectionId]="this.collection.id"></app-collection-entry-grid>
|
||||
<app-collection-entry-grid [entries]="collection.entries" [collectionId]="this.collection.id"
|
||||
(refrechEvent)="onRefrechEvent($event)"></app-collection-entry-grid>
|
||||
</div>
|
||||
|
||||
<!-- ! table -->
|
||||
|
||||
+134
-38
@@ -8,6 +8,7 @@ import { MatDialog } from '@angular/material/dialog';
|
||||
import { ConfirmModalComponent } from '../../../../shared/components/modals/confirm-modal/confirm-modal.component';
|
||||
import { ScreenshotService } from '../../../../core/services/screenshot.service';
|
||||
import { CollectionEntryDTO } from '../../../../shared/models/dtos/collection-entry-dto.model';
|
||||
import { environment } from '../../../../../environments/environment.prod';
|
||||
|
||||
@Component({
|
||||
selector: 'app-collection-info-page',
|
||||
@@ -35,11 +36,18 @@ export class CollectionInfoPageComponent implements OnInit {
|
||||
ngOnInit(): void {
|
||||
const id = this.route.snapshot.paramMap.get('id');
|
||||
if (id == null) return; // todo redirect if no id is provided
|
||||
this.collection.id = parseInt(id);
|
||||
|
||||
this.collectionService.getCollection(id.toString()).subscribe({
|
||||
next: (data) => {
|
||||
this.collection = data as unknown as Collection;
|
||||
this.collection.entries = this.collection.entries as CollectionEntryDTO[];
|
||||
this.fetchCollection();
|
||||
}
|
||||
|
||||
fetchCollection() {
|
||||
this.collectionService.getCollection(this.collection.id).subscribe({
|
||||
next: (result) => {
|
||||
this.collection = result;
|
||||
|
||||
if (!this.collection.isUserCollection)
|
||||
this.collection.entries = this.sortEntries(this.collection.entries);
|
||||
|
||||
this.createdAt = this.getCreatedDate()?.toString() || '';
|
||||
this.updatedAt = this.getUpdatedAt()?.toString() || '';
|
||||
@@ -54,6 +62,13 @@ export class CollectionInfoPageComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
sortEntries(entries: CollectionEntryDTO[]) {
|
||||
return entries.sort(
|
||||
(a, b) =>
|
||||
new Date(a.release_date).getTime() - new Date(b.release_date).getTime()
|
||||
);
|
||||
}
|
||||
|
||||
getListId() {
|
||||
return this.collection.id + '';
|
||||
}
|
||||
@@ -105,13 +120,13 @@ export class CollectionInfoPageComponent implements OnInit {
|
||||
if (!this.collection) return;
|
||||
|
||||
const dialogRef = this.dialog.open(CollectionEditModalComponent, {
|
||||
width: '360px',
|
||||
width: '50%',
|
||||
data: {
|
||||
name: this.collection.name,
|
||||
description: this.collection.description,
|
||||
userRating: this.collection.userRating || 0,
|
||||
poster: this.collection.posterPath,
|
||||
backdrop: this.collection.backdropPath,
|
||||
poster: this.getCollectionPosterPath(this.collection),
|
||||
backdrop: this.getCollectionBackdropPath(this.collection),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -158,18 +173,16 @@ export class CollectionInfoPageComponent implements OnInit {
|
||||
if (result) {
|
||||
if (result.confirmed != true) return;
|
||||
|
||||
this.collectionService
|
||||
.deleteCollection(this.collection.id)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
// TODO confirm notification
|
||||
this.router.navigate(['/collections']);
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error updating collection:', error);
|
||||
// TODO error notification
|
||||
},
|
||||
});
|
||||
this.collectionService.deleteCollection(this.collection.id).subscribe({
|
||||
next: () => {
|
||||
// TODO confirm notification
|
||||
this.router.navigate(['/collections']);
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error updating collection:', error);
|
||||
// TODO error notification
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -212,7 +225,8 @@ export class CollectionInfoPageComponent implements OnInit {
|
||||
this.collectionService.refreshCollection(this.collection.id).subscribe({
|
||||
next: (data) => {
|
||||
this.collection = data as unknown as Collection;
|
||||
this.collection.entries = this.collection.entries as CollectionEntryDTO[];
|
||||
this.collection.entries = this.collection
|
||||
.entries as CollectionEntryDTO[];
|
||||
|
||||
this.createdAt = this.getCreatedDate()?.toString() || '';
|
||||
this.updatedAt = this.getUpdatedAt()?.toString() || '';
|
||||
@@ -228,25 +242,23 @@ export class CollectionInfoPageComponent implements OnInit {
|
||||
}
|
||||
|
||||
getCollectionParts() {
|
||||
this.collectionService
|
||||
.getCollectionParts(this.collection.id)
|
||||
.subscribe({
|
||||
next: (data) => {
|
||||
this.collection = data as unknown as Collection;
|
||||
this.collection.entries = this.collection
|
||||
.entries as CollectionEntryDTO[];
|
||||
this.collectionService.getCollectionParts(this.collection.id).subscribe({
|
||||
next: (data) => {
|
||||
this.collection = data as unknown as Collection;
|
||||
this.collection.entries = this.collection
|
||||
.entries as CollectionEntryDTO[];
|
||||
|
||||
this.createdAt = this.getCreatedDate()?.toString() || '';
|
||||
this.updatedAt = this.getUpdatedAt()?.toString() || '';
|
||||
// console.log(
|
||||
// `Collection "${this.collection.name}" received:`,
|
||||
// this.collection
|
||||
// );
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error occurred:', error);
|
||||
},
|
||||
});
|
||||
this.createdAt = this.getCreatedDate()?.toString() || '';
|
||||
this.updatedAt = this.getUpdatedAt()?.toString() || '';
|
||||
// console.log(
|
||||
// `Collection "${this.collection.name}" received:`,
|
||||
// this.collection
|
||||
// );
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error occurred:', error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
redirectToTMDB() {
|
||||
@@ -255,4 +267,88 @@ export class CollectionInfoPageComponent implements OnInit {
|
||||
'_blank'
|
||||
);
|
||||
}
|
||||
|
||||
getCollectionPosterPath(collection: Collection) {
|
||||
// console.log(`collection media:`, collection.medias);
|
||||
if (collection.medias && collection.medias.length != 0) {
|
||||
const posters = collection.medias.filter((m) => m.type == 'poster');
|
||||
if (posters.length != 0) {
|
||||
const selectedPosters = posters.filter((m) => m.isSelected);
|
||||
|
||||
// console.log(selectedPosters);
|
||||
let selectedPoster;
|
||||
if (selectedPosters.length != 0) {
|
||||
selectedPoster = selectedPosters[0].path;
|
||||
} else {
|
||||
selectedPoster = posters[0].path;
|
||||
}
|
||||
|
||||
return (
|
||||
environment.API_URL +
|
||||
`/media/collections/posters/preview/${selectedPoster}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// if (collection.entries && collection.entries.length != 0) {
|
||||
// // * use the poster of the first entry in the collection
|
||||
// // * if the collection is empty
|
||||
// return this.getEntryBackdropPath(collection.entries[0]);
|
||||
// } else
|
||||
if (collection.posterPath) {
|
||||
// * use first remote tmdb poster
|
||||
// * if collection has none and has no entry
|
||||
return `https://image.tmdb.org/t/p/w1280/${collection.posterPath}`;
|
||||
} else {
|
||||
// * use default poster
|
||||
// * if collection has totaly no poster
|
||||
return 'assets/images/default/default-poster.png';
|
||||
}
|
||||
}
|
||||
|
||||
getCollectionBackdropPath(collection: Collection) {
|
||||
// console.log(`collection media:`, collection.medias);
|
||||
if (collection.medias && collection.medias.length != 0) {
|
||||
const backdrops = collection.medias.filter((m) => m.type == 'backdrop');
|
||||
if (backdrops.length != 0) {
|
||||
const selectedBackdrops = backdrops.filter((m) => m.isSelected);
|
||||
|
||||
// console.log(selectedBackdrops);
|
||||
let selectedBackdrop;
|
||||
if (selectedBackdrops.length != 0) {
|
||||
selectedBackdrop = selectedBackdrops[0].path;
|
||||
} else {
|
||||
selectedBackdrop = backdrops[0].path;
|
||||
}
|
||||
|
||||
return (
|
||||
environment.API_URL +
|
||||
`/media/collections/backdrops/preview/${selectedBackdrop}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// if (collection.entries && collection.entries.length != 0) {
|
||||
// // * use the poster of the first entry in the collection
|
||||
// // * if the collection is empty
|
||||
// return this.getEntryBackdropPath(collection.entries[0]);
|
||||
// } else
|
||||
if (collection.backdropPath) {
|
||||
// * use first remote tmdb poster
|
||||
// * if collection has none and has no entry
|
||||
return `https://image.tmdb.org/t/p/w1280/${collection.backdropPath}`;
|
||||
} else {
|
||||
// * use default poster
|
||||
// * if collection has totaly no poster
|
||||
return 'assets/images/default/default-backdrop.png';
|
||||
}
|
||||
}
|
||||
|
||||
onRefrechEvent(eventData: any) {
|
||||
if (eventData.type == 'delete') {
|
||||
this.collection.entries = this.collection.entries.filter(
|
||||
(e) => e.id != eventData.id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -3,8 +3,6 @@ import { Collection } from '../../../../shared/models/collection.model';
|
||||
import { CollectionService } from '../../../../core/services/collection.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { trigger, transition, style, animate } from '@angular/animations';
|
||||
import { environment } from '../../../../../environments/environment.prod';
|
||||
import { Entry } from '../../../../shared/models/entry.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-collection-card',
|
||||
@@ -27,7 +25,7 @@ import { Entry } from '../../../../shared/models/entry.model';
|
||||
export class CollectionCardComponent {
|
||||
@Input() collection!: Collection;
|
||||
|
||||
constructor(private listService: CollectionService, private router: Router) {}
|
||||
constructor(private collectionService: CollectionService, private router: Router) {}
|
||||
|
||||
getCreatedDate(): string {
|
||||
if (this.collection.createdAt == null) return '';
|
||||
@@ -40,6 +38,6 @@ export class CollectionCardComponent {
|
||||
}
|
||||
|
||||
deleteList() {
|
||||
this.listService.deleteCollection(this.collection.id);
|
||||
this.collectionService.deleteCollection(this.collection.id);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -3,7 +3,7 @@ import { FormControl } from '@angular/forms';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { CollectionService } from '../../../../core/services/collection.service';
|
||||
import { NotificationPopupComponent } from '../../notification-popup/notification-popup.component';
|
||||
import { NotificationService } from '../../../services/notification.service';
|
||||
import { ToastService } from '../../../services/toast.service';
|
||||
import { Collection } from '../../../models/collection.model';
|
||||
|
||||
import {
|
||||
@@ -50,7 +50,7 @@ export class UserCollectionsModalComponent implements OnInit {
|
||||
public dialogRef: MatDialogRef<UserCollectionsModalComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
private collectionService: CollectionService,
|
||||
private notificationService: NotificationService
|
||||
private toastService: ToastService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -174,6 +174,6 @@ export class UserCollectionsModalComponent implements OnInit {
|
||||
|
||||
showNotification(title: string, message: string, type: string): void {
|
||||
// this.notificationComponent.showNotification(message, type);
|
||||
this.notificationService.showNotification(title, message, type);
|
||||
this.toastService.show(title, message, type);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user