diff --git a/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.html b/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.html index f6293da..b6bd068 100644 --- a/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.html +++ b/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.html @@ -18,20 +18,23 @@
-
-
+
+
+ placeholder="Collection name..."> search -
+
+
- +
diff --git a/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.ts b/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.ts index cd20008..63fb949 100644 --- a/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.ts +++ b/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.ts @@ -2,35 +2,50 @@ import { Component, OnInit } from '@angular/core'; import { FormControl } from '@angular/forms'; import { UserCollection } from '../../../../shared/models/userCollection.model'; import { UserCollectionService } from '../../../../core/services/userCollection.service'; +import { + animate, + state, + style, + transition, + trigger, +} from '@angular/animations'; @Component({ selector: 'app-userCollections-page', templateUrl: './userCollections-page.component.html', styleUrls: ['./userCollections-page.component.css'], + animations: [ + trigger('animateDestroy', [ + state('void', style({ opacity: '0' })), + transition('* => void', animate('300ms ease')), + ]), + ], }) export class UserCollectionsPageComponent implements OnInit { searchControl = new FormControl(''); showAddButton: boolean = false; - listsCount: number = 0; + collectionsCount: number = 0; - lists: UserCollection[] = []; - listsToShow: UserCollection[] = []; + collections: UserCollection[] = []; + collectionsToShow: UserCollection[] = []; - constructor(private listService: UserCollectionService) {} + lockActions: boolean = false; + + constructor(private collectionsService: UserCollectionService) {} ngOnInit() { - this.getLists(); + this.getCollections(); this.searchControl.valueChanges.subscribe(() => { this.applyFilter(); }); } - getLists() { - this.listService.getCollections().subscribe({ + getCollections() { + this.collectionsService.getCollections().subscribe({ next: (l) => { console.log(`Loaded ${l.length} lists.`); - this.lists = l; - this.listsToShow = this.lists; + this.collections = l; + this.collectionsToShow = this.collections; this.applyFilter(); }, error: (error) => { @@ -42,23 +57,42 @@ export class UserCollectionsPageComponent implements OnInit { applyFilter() { let filterValue = this.searchControl.value; if (filterValue == null) { - this.listsToShow = [...this.lists]; + this.collectionsToShow = [...this.collections]; return; } const normalizedFilter = filterValue.toLowerCase().trim(); - this.listsToShow = this.lists.filter((collection) => + this.collectionsToShow = this.collections.filter((collection) => collection.name.toLowerCase().trim().includes(normalizedFilter) ); - this.listsCount = this.listsToShow.length; + this.collectionsCount = this.collectionsToShow.length; } - createList() { - // const listName = this.searchControl.value; // string - // let myNewList = { name: listName } as List; - // this.listService.createList(myNewList).subscribe(async (list) => { - // await this.getLists(); - // }); + createCollection() { + this.lockActions = true; + // TODO add create collection from the collections list page + const listName = this.searchControl.value; + let myNewList = { name: listName } as UserCollection; + this.collectionsService.createCollection(myNewList).subscribe({ + next: (collection) => { + this.collections.push(collection); + this.applyFilter(); + }, + error: (error) => { + // TODO show error notification + console.log(`Error creating new collection: `, error); + }, + complete: () => { + this.lockActions = false; + }, + }); + } + + doShowCreate() { + return ( + this.searchControl.value?.trim() != '' && + this.collectionsToShow.length == 0 + ); } }