From 9908e4f3feadf1022f3943f63babd5f100beb0b4 Mon Sep 17 00:00:00 2001 From: X4Lo Date: Tue, 2 Apr 2024 03:43:45 +0000 Subject: [PATCH] add lists page component --- .../features/pages/lists/lists.component.css | 0 .../features/pages/lists/lists.component.html | 40 ++++++++++++ .../pages/lists/lists.component.spec.ts | 21 +++++++ .../features/pages/lists/lists.component.ts | 62 +++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 frontend/src/app/features/pages/lists/lists.component.css create mode 100644 frontend/src/app/features/pages/lists/lists.component.html create mode 100644 frontend/src/app/features/pages/lists/lists.component.spec.ts create mode 100644 frontend/src/app/features/pages/lists/lists.component.ts diff --git a/frontend/src/app/features/pages/lists/lists.component.css b/frontend/src/app/features/pages/lists/lists.component.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/features/pages/lists/lists.component.html b/frontend/src/app/features/pages/lists/lists.component.html new file mode 100644 index 0000000..04b2b5c --- /dev/null +++ b/frontend/src/app/features/pages/lists/lists.component.html @@ -0,0 +1,40 @@ + + + + +
+
+
+
+
+ + search + +
+
+
+
+
+ + + +
+
+
+
+
+
\ No newline at end of file diff --git a/frontend/src/app/features/pages/lists/lists.component.spec.ts b/frontend/src/app/features/pages/lists/lists.component.spec.ts new file mode 100644 index 0000000..b4172ba --- /dev/null +++ b/frontend/src/app/features/pages/lists/lists.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ListsComponent } from './lists.component'; + +describe('ListsComponent', () => { + let component: ListsComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ListsComponent] + }); + fixture = TestBed.createComponent(ListsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/pages/lists/lists.component.ts b/frontend/src/app/features/pages/lists/lists.component.ts new file mode 100644 index 0000000..00c9fbb --- /dev/null +++ b/frontend/src/app/features/pages/lists/lists.component.ts @@ -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(); + // }); + } +}