add lists page component
This commit is contained in:
1 parent
c36149eb74
commit
9908e4f3fe
4 files changed
+123
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,40 @@
|
|||||||
|
<!--breadcrumb-->
|
||||||
|
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
|
||||||
|
<div class="breadcrumb-title pe-3">Library</div>
|
||||||
|
<div class="ps-3">
|
||||||
|
<nav aria-label="breadcrumb">
|
||||||
|
<ol class="breadcrumb mb-0 p-0">
|
||||||
|
<li class="breadcrumb-item">
|
||||||
|
<a href="javascript:;">
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="breadcrumb-item active" aria-current="page">Lists</li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--end breadcrumb-->
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="col d-flex ">
|
||||||
|
<div class="card w-100">
|
||||||
|
<div class="card-header border-0 p-3 border-bottom">
|
||||||
|
<div class="position-relative">
|
||||||
|
<input [formControl]="searchControl" matInput class="form-control rounded-5 px-5" type="text"
|
||||||
|
placeholder="Search">
|
||||||
|
<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>
|
||||||
|
<div class="card-body p-0">
|
||||||
|
<div class="p-3 ps ps--active-y">
|
||||||
|
<div class="d-flex flex-column gap-3">
|
||||||
|
<!-- item start -->
|
||||||
|
<app-user-list-item *ngFor="let list of listsToShow" [list]="list"></app-user-list-item>
|
||||||
|
<!-- item end -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ListsComponent } from './lists.component';
|
||||||
|
|
||||||
|
describe('ListsComponent', () => {
|
||||||
|
let component: ListsComponent;
|
||||||
|
let fixture: ComponentFixture<ListsComponent>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ListsComponent]
|
||||||
|
});
|
||||||
|
fixture = TestBed.createComponent(ListsComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormControl } from '@angular/forms';
|
||||||
|
import { List } from '../../../shared/models/list.model';
|
||||||
|
import { ListService } from '../../../core/services/list.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-lists',
|
||||||
|
templateUrl: './lists.component.html',
|
||||||
|
styleUrls: ['./lists.component.css'],
|
||||||
|
})
|
||||||
|
export class ListsComponent implements OnInit {
|
||||||
|
searchControl = new FormControl('');
|
||||||
|
showAddButton: boolean = false;
|
||||||
|
|
||||||
|
lists: List[] = [];
|
||||||
|
listsToShow: List[] = [];
|
||||||
|
|
||||||
|
constructor(private listService: ListService) {}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.getLists();
|
||||||
|
this.searchControl.valueChanges.subscribe(() => {
|
||||||
|
this.applyFilter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getLists() {
|
||||||
|
this.listService.getLists().subscribe({
|
||||||
|
next: (l) => {
|
||||||
|
this.lists = l;
|
||||||
|
console.log(this.lists);
|
||||||
|
this.listsToShow = this.lists;
|
||||||
|
this.applyFilter();
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.log("Counldn't get lists from backend.");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
applyFilter() {
|
||||||
|
let filterValue = this.searchControl.value;
|
||||||
|
if (filterValue == null) {
|
||||||
|
this.listsToShow = [...this.lists];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizedFilter = filterValue.toLowerCase().trim();
|
||||||
|
|
||||||
|
this.listsToShow = this.lists.filter((collection) =>
|
||||||
|
collection.name.toLowerCase().trim().includes(normalizedFilter)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
createList() {
|
||||||
|
// const listName = this.searchControl.value; // string
|
||||||
|
// let myNewList = { name: listName } as List;
|
||||||
|
// this.listService.createList(myNewList).subscribe(async (list) => {
|
||||||
|
// await this.getLists();
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user