implemented collection entries reorder (for table view)

This commit is contained in:
X4Lo committed 2024-05-17 19:40:40 +01:00
1 parent ec45cd342f
commit 78399912f7
5 files changed
+44 -54

No files matched your search

@@ -13,6 +13,7 @@ import {
transition,
trigger,
} from '@angular/animations';
import { UserCollectionService } from '../../../../core/services/userCollection.service';
@Component({
selector: 'app-collection-entry-table',
@@ -27,7 +28,9 @@ import {
})
export class CollectionEntryTableComponent {
@Input() entries: Entry[] = [];
@Input() listId: string = '';
@Input() collectionId: string = '';
constructor(private userCollectionService: UserCollectionService) {}
refrechEventReceiver() {
console.log('event recieved');
@@ -35,6 +38,21 @@ export class CollectionEntryTableComponent {
drop(event: CdkDragDrop<any[]>) {
moveItemInArray(this.entries, event.previousIndex, event.currentIndex);
if (event.previousIndex != event.currentIndex) {
this.userCollectionService
.updateEntryOrder(
this.collectionId,
this.entries[event.currentIndex].id,
event.currentIndex
)
.subscribe({
next: () => {},
error: (error) => {
console.log(`Error changing order of entries!`);
},
});
}
}
dragStart(event: CdkDragStart): void {
@@ -1,5 +1,7 @@
<div class="movies-container" cdkDropList [cdkDropListData]="entries" (cdkDropListDropped)="drop($any($event))">
<app-userCollection-grid-card cdkDrag *ngFor="let entry of entries" [entry]="entry" [listId]="listId"
(refrechEvent)="refrechEventReceiver()">
<div class="movies-container">
<ng-container *ngFor="let entry of entries">
<app-userCollection-grid-card [entry]="entry" [collectionId]="collectionId" (refrechEvent)="refrechEventReceiver()"
@animateDestroy>
</app-userCollection-grid-card>
</ng-container>
</div>
@@ -1,36 +1,30 @@
import { Component, Input } from '@angular/core';
import { Entry } from '../../../../shared/models/entry.model';
import {
CdkDragDrop,
CdkDragEnd,
CdkDragStart,
moveItemInArray,
} from '@angular/cdk/drag-drop';
animate,
state,
style,
transition,
trigger,
} from '@angular/animations';
@Component({
selector: 'app-userCollection-entry-grid',
templateUrl: './userCollection-entry-grid.component.html',
styleUrls: ['./userCollection-entry-grid.component.css'],
animations: [
trigger('animateDestroy', [
state('void', style({ opacity: '0' })),
transition('* => void', animate('300ms ease')),
]),
],
})
export class UserCollectionEntryGridComponent {
@Input() entries: Entry[] = [];
@Input() listId: string = '';
@Input() collectionId: string = '';
refrechEventReceiver() {
console.log('event recieved');
}
drop(event: CdkDragDrop<any[]>) {
moveItemInArray(this.entries, event.previousIndex, event.currentIndex);
}
dragStart(event: CdkDragStart): void {
event.source.element.nativeElement.classList.add('custom-dragging-class');
}
dragEnd(event: CdkDragEnd): void {
event.source.element.nativeElement.classList.remove(
'custom-dragging-class'
);
}
}
@@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { LibraryService } from '../../../../core/services/library.service';
import { Entry } from '../../../../shared/models/entry.model';
@@ -21,9 +21,9 @@ import { ConfirmModalComponent } from '../../../../shared/components/modals/conf
]),
],
})
export class UserCollectionGridCardComponent {
export class UserCollectionGridCardComponent implements OnInit {
@Input() entry!: Entry;
@Input() listId: string = '';
@Input() collectionId: string = '';
@Output() refrechEvent = new EventEmitter();
constructor(
@@ -34,15 +34,6 @@ export class UserCollectionGridCardComponent {
) {}
ngOnInit(): void {
this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({
next: (e) => {
if (e != null) {
e.isInLibrary = true;
this.entry = e;
}
},
error: (error) => {},
});
}
get releaseYear(): number {
@@ -64,21 +55,6 @@ export class UserCollectionGridCardComponent {
return `https://image.tmdb.org/t/p/w500` + this.entry.poster_path;
}
addEntry(tmdb_id: string, is_tvserie: boolean) {
console.log('Adding Entry To Library.');
this.libraryService.addEntry(tmdb_id, is_tvserie).subscribe({
next: (entry) => {
if (entry != null) {
entry.isInLibrary = true;
this.entry = entry;
this.libraryService.getAllEntries(true);
}
},
error: (error) => {
console.error('Error adding entry:', error);
},
});
}
removeEntryFromList() {
const dialogRef = this.dialog.open(ConfirmModalComponent, {
@@ -95,7 +71,7 @@ export class UserCollectionGridCardComponent {
if (result.confirmed != true) return;
this.userCollectionService
.removeEntryFromCollection(this.listId, this.entry.id)
.removeEntryFromCollection(this.collectionId, this.entry.id)
.subscribe({
next: (response) => {
// TODO confirm notification
@@ -42,13 +42,13 @@
<!-- ! grid -->
<div *ngIf="viewMode == 'grid'">
<app-userCollection-entry-grid [entries]="collection.entries"
[listId]="getListId()"></app-userCollection-entry-grid>
[collectionId]="getListId()"></app-userCollection-entry-grid>
</div>
<!-- ! table -->
<div *ngIf="viewMode == 'table'">
<app-collection-entry-table [entries]="collection.entries"
[listId]="getListId()"></app-collection-entry-table>
[collectionId]="getListId()"></app-collection-entry-table>
</div>
</div>
</div>