Front: renamed most collection related files

This commit is contained in:
X4Lo committed 2024-09-13 22:23:41 +01:00
1 parent 75de013f82
commit 8724a96b81
55 files changed
+294 -394

No files matched your search

@@ -11,7 +11,7 @@
<input type="text" class="form-control" id="listNameInput" [formControl]="searchControl"
placeholder="Collection name..." @scaleInOut>
<button class="btn btn-success growing-width-element" type="button" *ngIf="doShowAddButton()"
(click)="createList()" @scaleInOut>Create
(click)="createCollection()" @scaleInOut>Create
Collection</button>
</div>
@@ -20,7 +20,7 @@
<div data-simplebar class="simplebar-content-wrapper">
<div class="list-group">
<label *ngFor="let list of userCollectionsToShow" class="list-group-item">
<label *ngFor="let list of collectionsToShow" class="list-group-item">
<input class="form-check-input me-1" type="checkbox" [value]="list.id"
(change)="onSelectionChange(list, $event)" [checked]="list.isChecked">
{{ list.name }}
@@ -1,10 +1,10 @@
import { Component, Inject, Input, OnInit, ViewChild } from '@angular/core';
import { FormControl } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { CollectionService } from '../../../../core/services/userCollection.service';
import { CollectionService } from '../../../../core/services/collection.service';
import { NotificationPopupComponent } from '../../notification-popup/notification-popup.component';
import { NotificationService } from '../../../services/notification.service';
import { UserCollection } from '../../../models/userCollection.model';
import { Collection } from '../../../models/collection.model';
import {
trigger,
@@ -43,74 +43,73 @@ export class UserCollectionsModalComponent implements OnInit {
searchControl = new FormControl('');
showAddButton: boolean = false;
userCollections: UserCollection[] = [];
userCollectionsToShow: UserCollection[] = [];
collections: Collection[] = [];
collectionsToShow: Collection[] = [];
constructor(
public dialogRef: MatDialogRef<UserCollectionsModalComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private listService: CollectionService,
private collectionService: CollectionService,
private notificationService: NotificationService
) {}
ngOnInit() {
this.entryId = this.data.entryId;
this.getLists();
this.getCollections();
this.searchControl.valueChanges.subscribe((value) => {
this.applyFilter(value);
});
}
getLists() {
this.listService.getCollections().subscribe({
getCollections() {
this.collectionService.getCollections().subscribe({
next: (result) => {
result.forEach((collection) => {
if (
collection.entries.some(
(entry) => entry.id == this.entryId
)
) {
if (collection.entries.some((entry) => entry.id == this.entryId)) {
collection.isChecked = true;
}
});
this.userCollections = result;
this.userCollections = this.userCollections.filter(
(c) => c.isUserCollection
);
this.userCollectionsToShow = this.userCollections;
this.collections = result;
this.collections = this.collections.filter((c) => c.isUserCollection);
this.collectionsToShow = this.collections;
this.applyFilter(this.searchControl.value);
},
error: (error) => {
console.log("Counldn't get lists from backend.");
console.log("Counldn't get collections from backend.");
},
});
}
applyFilter(filterValue: string | null) {
if (filterValue == null) {
this.userCollectionsToShow = [...this.userCollections];
this.collectionsToShow = [...this.collections];
this.showAddButton = false;
return;
}
const normalizedFilter = filterValue.toLowerCase().trim();
this.userCollectionsToShow = this.userCollections.filter((list) =>
list.name.toLowerCase().trim().includes(normalizedFilter)
this.collectionsToShow = this.collections.filter((c) =>
c.name.toLowerCase().trim().includes(normalizedFilter)
);
this.showAddButton = this.userCollectionsToShow.length === 0;
this.showAddButton = this.collectionsToShow.length === 0;
}
createList() {
const listName = this.searchControl.value?.toString().trim(); // string
createCollection() {
const name = this.searchControl.value?.toString().trim(); // string
let myNewList = { name: listName } as UserCollection;
let collectionData = { name: name } as Collection;
this.listService.createCollection(myNewList).subscribe(async (list) => {
await this.getLists();
this.collectionService.createCollection(collectionData).subscribe({
next: (result) => {
this.getCollections();
},
error: (error) => {
console.log(`error creating new collection: `, error);
},
});
}
@@ -118,44 +117,44 @@ export class UserCollectionsModalComponent implements OnInit {
return this.showAddButton;
}
onSelectionChange(userCollection: UserCollection, event: Event): void {
onSelectionChange(collection: Collection, event: Event): void {
const inputElement = event.target as HTMLInputElement;
const isChecked = inputElement.checked;
if (isChecked || isChecked == null) {
console.log(
`Adding Entry ${this.entryId} to list: ${userCollection.name}`
);
this.listService
.addEntryToCollection(userCollection.id, this.entryId)
// console.log(`Adding Entry ${this.entryId} to collection: ${collection.name}`);
this.collectionService
.addEntryToCollection(collection.id, this.entryId)
.subscribe({
next: (response) => {
console.log('Successfuly added Entry To Collection:', response);
this.getLists();
// TODO TOAST entry added to collection
this.showNotification(
'Entry Added',
'Entry added successfully',
'success'
);
// console.log('Successfuly added Entry To Collection:', response);
this.getCollections();
},
error: (error) => {
console.error('Error:', error);
this.showNotification('Error', 'Failed to add entry', 'error');
// this.showNotification('Error', 'Failed to add entry', 'error');
},
});
} else {
console.log(
`Removing Entry ${this.entryId} from list: ${userCollection.name}`
);
this.listService
.removeEntryFromCollection(userCollection.id.toString(), this.entryId)
// console.log(
// `Removing Entry ${this.entryId} from collection: ${collection.name}`
// );
this.collectionService
.removeEntryFromCollection(collection.id, this.entryId)
.subscribe({
next: (_) => {
next: (result) => {
this.showNotification(
'Entry Removed',
'Entry removed successfully',
'success'
);
// TODO TOAST ENTRY REMOVE FROM COLLECTION
},
error: (error) => {
console.error('Error removing entry:', error);
-2
View File
@@ -11,7 +11,6 @@ import { DateFormatPipe } from './pipes/date-format/date-format.pipe';
// * other
import { RatingModule } from 'ngx-bootstrap/rating';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CollectionEditModalComponent } from '../features/collections/user-collection-info/collection-edit-modal/collection-edit-modal.component';
import { FloatFormatPipe } from './pipes/float-format/float-format.pipe';
import { EpisodeSeenModalComponent } from './components/modals/episode-seen-modal/episode-seen-modal.component';
import { MainCardComponent } from './components/cards/main-card/main-card.component';
@@ -41,7 +40,6 @@ import { StopScrollDirective } from './directives/stop-scroll.directive';
// ? modals
SeenModalComponent,
CollectionEditModalComponent,
ConfirmModalComponent,
EpisodeSeenModalComponent,