diff --git a/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.ts b/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.ts index 40dfb41..4fe8814 100644 --- a/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.ts +++ b/frontend/src/app/features/collections/user-collection-info/collection-entry-table/collection-entry-table.component.ts @@ -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) { 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 { diff --git a/frontend/src/app/features/collections/user-collection-info/userCollection-entry-grid/userCollection-entry-grid.component.html b/frontend/src/app/features/collections/user-collection-info/userCollection-entry-grid/userCollection-entry-grid.component.html index 35aa0e9..38fa77d 100644 --- a/frontend/src/app/features/collections/user-collection-info/userCollection-entry-grid/userCollection-entry-grid.component.html +++ b/frontend/src/app/features/collections/user-collection-info/userCollection-entry-grid/userCollection-entry-grid.component.html @@ -1,5 +1,7 @@ -
- - +
+ + + +
\ No newline at end of file diff --git a/frontend/src/app/features/collections/user-collection-info/userCollection-entry-grid/userCollection-entry-grid.component.ts b/frontend/src/app/features/collections/user-collection-info/userCollection-entry-grid/userCollection-entry-grid.component.ts index aa2daee..7f2bc56 100644 --- a/frontend/src/app/features/collections/user-collection-info/userCollection-entry-grid/userCollection-entry-grid.component.ts +++ b/frontend/src/app/features/collections/user-collection-info/userCollection-entry-grid/userCollection-entry-grid.component.ts @@ -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) { - 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' - ); - } } diff --git a/frontend/src/app/features/collections/user-collection-info/userCollection-grid-card/userCollection-grid-card.component.ts b/frontend/src/app/features/collections/user-collection-info/userCollection-grid-card/userCollection-grid-card.component.ts index 8bd9931..a039d89 100644 --- a/frontend/src/app/features/collections/user-collection-info/userCollection-grid-card/userCollection-grid-card.component.ts +++ b/frontend/src/app/features/collections/user-collection-info/userCollection-grid-card/userCollection-grid-card.component.ts @@ -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 diff --git a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html index 5ced002..2ae88df 100644 --- a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html +++ b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html @@ -42,13 +42,13 @@
+ [collectionId]="getListId()">
+ [collectionId]="getListId()">
\ No newline at end of file