diff --git a/frontend/src/app/list-selection-modal/list-selection-modal.component.css b/frontend/src/app/list-selection-modal/list-selection-modal.component.css new file mode 100644 index 0000000..53a4bc5 --- /dev/null +++ b/frontend/src/app/list-selection-modal/list-selection-modal.component.css @@ -0,0 +1,3 @@ +mat-form-field { + width: 100%; +} \ No newline at end of file diff --git a/frontend/src/app/list-selection-modal/list-selection-modal.component.html b/frontend/src/app/list-selection-modal/list-selection-modal.component.html new file mode 100644 index 0000000..a436eb4 --- /dev/null +++ b/frontend/src/app/list-selection-modal/list-selection-modal.component.html @@ -0,0 +1,19 @@ +

Choose a list

+ + + List Name + + + + + + + + {{list.name}} + + + + + + + \ No newline at end of file diff --git a/frontend/src/app/list-selection-modal/list-selection-modal.component.spec.ts b/frontend/src/app/list-selection-modal/list-selection-modal.component.spec.ts new file mode 100644 index 0000000..8cd84ea --- /dev/null +++ b/frontend/src/app/list-selection-modal/list-selection-modal.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ListSelectionModalComponent } from './list-selection-modal.component'; + +describe('ListSelectionModalComponent', () => { + let component: ListSelectionModalComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ListSelectionModalComponent] + }); + fixture = TestBed.createComponent(ListSelectionModalComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/list-selection-modal/list-selection-modal.component.ts b/frontend/src/app/list-selection-modal/list-selection-modal.component.ts new file mode 100644 index 0000000..afb5f53 --- /dev/null +++ b/frontend/src/app/list-selection-modal/list-selection-modal.component.ts @@ -0,0 +1,77 @@ +import { Component, Inject, OnInit } from '@angular/core'; +import { FormControl } from '@angular/forms'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { ListService } from '../core/services/list.service'; +import { List } from '../shared/models/list.model'; + +@Component({ + selector: 'app-list-selection-modal', + templateUrl: './list-selection-modal.component.html', + styleUrls: ['./list-selection-modal.component.css'], +}) +export class ListSelectionModalComponent implements OnInit { + searchControl = new FormControl(''); + showAddButton: boolean = false; + + lists: List[] = []; + listsToShow: List[] = []; + + constructor( + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any, + private listService: ListService + ) {} + + ngOnInit() { + this.getLists(); + + this.searchControl.valueChanges.subscribe((value) => { + this.applyFilter(value); + }); + } + + getLists() { + this.listService.getLists().subscribe({ + next: (l) => { + this.lists = l; + this.listsToShow = this.lists; + this.applyFilter(this.searchControl.value); + + }, + error: (error) => { + console.log("Counldn't get lists from backend."); + }, + }); + } + + applyFilter(filterValue: string | null) { + if (filterValue == null) { + this.listsToShow = [...this.lists]; // Show all lists if filter is cleared or null + this.showAddButton = false; // Assuming you want to hide the button when there's no filter + return; + } + + const normalizedFilter = filterValue.toLowerCase().trim(); + + this.listsToShow = this.lists.filter((collection) => + collection.name.toLowerCase().trim().includes(normalizedFilter) + ); + + this.showAddButton = this.listsToShow.length === 0; + } + + createList() { + const listName = this.searchControl.value; // string + + let myNewList = { name: listName } as List; + + this.listService.createList(myNewList).subscribe(async (list) => { + await this.getLists(); + console.log(this.searchControl.value); + }); + } + + doShowAddButton(): boolean { + return this.showAddButton; + } +}