add collection create button + add animation
This commit is contained in:
1 parent
dde494a11e
commit
70975f77b5
2 files changed
+61
-24
No files matched your search
+9
-6
@@ -18,20 +18,23 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="col d-flex ">
|
<div class="col d-flex ">
|
||||||
<div class="card w-100">
|
<div class="card w-100">
|
||||||
<div class="card-header border-0 p-3 border-bottom">
|
<div class="card-header border-0 p-3 border-bottom d-flex align-items-center justify-content-between">
|
||||||
<div class="position-relative">
|
<div class="position-relative flex-grow-1 align-items-center">
|
||||||
<input [formControl]="searchControl" matInput class="form-control rounded-5 px-5" type="text"
|
<input [formControl]="searchControl" matInput class="form-control rounded-5 px-5" type="text"
|
||||||
placeholder="Search">
|
placeholder="Collection name...">
|
||||||
<span class="material-icons-outlined position-absolute ms-3 translate-middle-y start-0 top-50">search</span>
|
<span class="material-icons-outlined position-absolute ms-3 translate-middle-y start-0 top-50">search</span>
|
||||||
<!-- <span class="material-icons-outlined position-absolute me-3 translate-middle-y end-0 top-50">Library</span> -->
|
|
||||||
</div>
|
</div>
|
||||||
|
<button type="button" class="btn btn-primary d-flex align-items-center m-2" *ngIf="doShowCreate()" (click)="createCollection()"><i
|
||||||
|
class="material-icons-outlined">add</i>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-body p-0">
|
<div class="card-body p-0">
|
||||||
<div class="p-3 ps ps--active-y">
|
<div class="p-3 ps ps--active-y">
|
||||||
<div class="d-flex flex-column gap-3">
|
<div class="d-flex flex-column gap-3">
|
||||||
<!-- item start -->
|
<!-- item start -->
|
||||||
<app-userCollections-list-item *ngFor="let list of listsToShow"
|
<app-userCollections-list-item *ngFor="let list of collectionsToShow"
|
||||||
[list]="list"></app-userCollections-list-item>
|
[list]="list" @animateDestroy></app-userCollections-list-item>
|
||||||
<!-- item end -->
|
<!-- item end -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+52
-18
@@ -2,35 +2,50 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
import { FormControl } from '@angular/forms';
|
import { FormControl } from '@angular/forms';
|
||||||
import { UserCollection } from '../../../../shared/models/userCollection.model';
|
import { UserCollection } from '../../../../shared/models/userCollection.model';
|
||||||
import { UserCollectionService } from '../../../../core/services/userCollection.service';
|
import { UserCollectionService } from '../../../../core/services/userCollection.service';
|
||||||
|
import {
|
||||||
|
animate,
|
||||||
|
state,
|
||||||
|
style,
|
||||||
|
transition,
|
||||||
|
trigger,
|
||||||
|
} from '@angular/animations';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-userCollections-page',
|
selector: 'app-userCollections-page',
|
||||||
templateUrl: './userCollections-page.component.html',
|
templateUrl: './userCollections-page.component.html',
|
||||||
styleUrls: ['./userCollections-page.component.css'],
|
styleUrls: ['./userCollections-page.component.css'],
|
||||||
|
animations: [
|
||||||
|
trigger('animateDestroy', [
|
||||||
|
state('void', style({ opacity: '0' })),
|
||||||
|
transition('* => void', animate('300ms ease')),
|
||||||
|
]),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class UserCollectionsPageComponent implements OnInit {
|
export class UserCollectionsPageComponent implements OnInit {
|
||||||
searchControl = new FormControl('');
|
searchControl = new FormControl('');
|
||||||
showAddButton: boolean = false;
|
showAddButton: boolean = false;
|
||||||
listsCount: number = 0;
|
collectionsCount: number = 0;
|
||||||
|
|
||||||
lists: UserCollection[] = [];
|
collections: UserCollection[] = [];
|
||||||
listsToShow: UserCollection[] = [];
|
collectionsToShow: UserCollection[] = [];
|
||||||
|
|
||||||
constructor(private listService: UserCollectionService) {}
|
lockActions: boolean = false;
|
||||||
|
|
||||||
|
constructor(private collectionsService: UserCollectionService) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.getLists();
|
this.getCollections();
|
||||||
this.searchControl.valueChanges.subscribe(() => {
|
this.searchControl.valueChanges.subscribe(() => {
|
||||||
this.applyFilter();
|
this.applyFilter();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getLists() {
|
getCollections() {
|
||||||
this.listService.getCollections().subscribe({
|
this.collectionsService.getCollections().subscribe({
|
||||||
next: (l) => {
|
next: (l) => {
|
||||||
console.log(`Loaded ${l.length} lists.`);
|
console.log(`Loaded ${l.length} lists.`);
|
||||||
this.lists = l;
|
this.collections = l;
|
||||||
this.listsToShow = this.lists;
|
this.collectionsToShow = this.collections;
|
||||||
this.applyFilter();
|
this.applyFilter();
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
@@ -42,23 +57,42 @@ export class UserCollectionsPageComponent implements OnInit {
|
|||||||
applyFilter() {
|
applyFilter() {
|
||||||
let filterValue = this.searchControl.value;
|
let filterValue = this.searchControl.value;
|
||||||
if (filterValue == null) {
|
if (filterValue == null) {
|
||||||
this.listsToShow = [...this.lists];
|
this.collectionsToShow = [...this.collections];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalizedFilter = filterValue.toLowerCase().trim();
|
const normalizedFilter = filterValue.toLowerCase().trim();
|
||||||
|
|
||||||
this.listsToShow = this.lists.filter((collection) =>
|
this.collectionsToShow = this.collections.filter((collection) =>
|
||||||
collection.name.toLowerCase().trim().includes(normalizedFilter)
|
collection.name.toLowerCase().trim().includes(normalizedFilter)
|
||||||
);
|
);
|
||||||
this.listsCount = this.listsToShow.length;
|
this.collectionsCount = this.collectionsToShow.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
createList() {
|
createCollection() {
|
||||||
// const listName = this.searchControl.value; // string
|
this.lockActions = true;
|
||||||
// let myNewList = { name: listName } as List;
|
// TODO add create collection from the collections list page
|
||||||
// this.listService.createList(myNewList).subscribe(async (list) => {
|
const listName = this.searchControl.value;
|
||||||
// await this.getLists();
|
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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user