implemented UserCollection edit modal + custom collection poster + media access route

This commit is contained in:
X4Lo committed 2024-05-01 23:44:33 +01:00
1 parent 0ff3c49ca6
commit e8c4fba943
17 files changed
+499 -73

No files matched your search

@@ -0,0 +1,5 @@
.rating {
color: var(--shz-gold-1);
font-size: 25px;
margin: 10px 0;
}
@@ -8,7 +8,7 @@
<a href="javascript:;">
</a>
</li>
<li class="breadcrumb-item active" aria-current="page">List: {{list.name}}</li>
<li class="breadcrumb-item active" aria-current="page">Collections</li>
</ol>
</nav>
</div>
@@ -17,18 +17,24 @@
<div class="card">
<div class="card-body">
<div class="d-flex justify-content-between align-items-center mb-2">
<h5 class="mb-0">{{list.name}}</h5>
<button type="button" class="btn btn-primary btn-sm">
<h5 class="mb-0">{{collection.name}}</h5>
<button type="button" class="btn btn-primary btn-sm" (click)="openEditModal()">
<span class="material-symbols-outlined">
edit
</span>
</button>
</div>
<div>Created - {{createdAt}} | Updated - {{updatedAt}}</div>
<div *ngIf="list.description != ''">{{list.description}}</div>
<div>Created - {{createdAt}} | Updated - {{updatedAt}}
<div class="d-flex justify-content-right rating">
<rating [(ngModel)]="collection.user_rating" [max]="10" [readonly]="true">
</rating>
</div>
</div>
<div *ngIf="collection.description != ''">{{collection.description}}</div>
<hr>
<div>
<app-userCollection-entry-grid [entries]="list.entries" [listId]="getListId()"></app-userCollection-entry-grid>
<app-userCollection-entry-grid [entries]="collection.entries"
[listId]="getListId()"></app-userCollection-entry-grid>
</div>
</div>
</div>
@@ -4,6 +4,8 @@ import { UserCollectionService } from '../../../../core/services/userCollection.
import { UserCollection } from '../../../../shared/models/userCollection.model';
import { DatePipe } from '@angular/common';
import { CollectionEntry } from '../../../../shared/models/dtos/collection-entry.dto';
import { CollectionEditModalComponent } from '../collection-edit-modal/collection-edit-modal.component';
import { MatDialog } from '@angular/material/dialog';
@Component({
selector: 'app-userCollection-info-page',
@@ -12,13 +14,14 @@ import { CollectionEntry } from '../../../../shared/models/dtos/collection-entry
providers: [DatePipe],
})
export class UserCollectionInfoPageComponent implements OnInit {
list: UserCollection = {} as UserCollection;
collection: UserCollection = {} as UserCollection;
createdAt: string = '';
updatedAt: string = '';
constructor(
private route: ActivatedRoute,
private listService: UserCollectionService,
private userCollectionService: UserCollectionService,
public dialog: MatDialog,
private datePipe: DatePipe
) {}
@@ -26,14 +29,17 @@ export class UserCollectionInfoPageComponent implements OnInit {
const id = this.route.snapshot.paramMap.get('id');
if (id == null) return;
this.listService.getCollection(id.toString()).subscribe(
this.userCollectionService.getCollection(id.toString()).subscribe(
(data) => {
this.list = data as unknown as UserCollection;
this.list.entries = this.list.entries as CollectionEntry[];
this.collection = data as unknown as UserCollection;
this.collection.entries = this.collection.entries as CollectionEntry[];
this.createdAt = this.getCreatedDate()?.toString() || '';
this.updatedAt = this.getUpdatedAt()?.toString() || '';
console.log(`Collection "${this.list.name}" received:`, this.list);
console.log(
`Collection "${this.collection.name}" received:`,
this.collection
);
},
(error) => {
console.error('Error occurred:', error);
@@ -42,16 +48,16 @@ export class UserCollectionInfoPageComponent implements OnInit {
}
getListId() {
return this.list.id + '';
return this.collection.id + '';
}
getCreatedDate() {
return this.datePipe.transform(this.list.createdAt, 'dd MMMM, yyyy');
return this.datePipe.transform(this.collection.createdAt, 'dd MMMM, yyyy');
}
// TODO use a relativeDate pipe
getUpdatedAt() {
const updatedAt = this.list.updatedAt;
const updatedAt = this.collection.updatedAt;
// First, check if updatedAt is a valid date string or timestamp
const modifiedDate = new Date(updatedAt);
@@ -87,4 +93,45 @@ export class UserCollectionInfoPageComponent implements OnInit {
return this.datePipe.transform(modifiedDate, 'dd MMMM, yyyy');
}
}
openEditModal() {
if (!this.collection) return;
const dialogRef = this.dialog.open(CollectionEditModalComponent, {
width: '360px',
data: {
name: this.collection.name,
description: this.collection.description,
user_rating: this.collection.user_rating || 0,
poster: this.collection.poster_path,
},
});
console.log('Edit dialog opened');
dialogRef.afterClosed().subscribe((result) => {
if (result) {
if (result.formData == null) return;
console.log('Edit dialog closed with:', result);
this.userCollectionService
.updateCollection(this.collection.id, result.formData)
.subscribe({
next: (userCollection) => {
if (userCollection) {
// TODO show confirm notification
console.log(`User Collection updated: `, userCollection);
this.collection = userCollection;
}
},
error: (error) => {
console.error('Error updating userCollection:', error);
// TODO show notification
},
});
} else {
console.log('Edit dialog was cancelled');
}
});
}
}