feat: add contact list

This commit is contained in:
2025-12-14 20:46:07 -03:00
parent ccde994797
commit 5f1c3062ab
4 changed files with 78 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
<div class="contact-list">
<div class="contact-list__container">
<h2>{{strings.constacts|upperfirst}}</h2>
<app-contact-search-bar (contactSearch)="filter=$event"/>
<app-counter
[count]="(this.contacts$|async)?.length ?? 0"
item="{{strings.constacts}}"
/>
<app-contact-list-table [contactList]="(this.contacts$|async)|contactsFilter:filter"/>
</div>
</div>

View File

@@ -0,0 +1,7 @@
.contact-list {
padding: 2rem;
&__container {
max-width: 800px;
margin: 4rem auto 0 auto;
}
}

View File

@@ -0,0 +1,32 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ContactList } from './contact-list';
import { ContactService } from '../../pages/main/contact.service';
import { of } from 'rxjs';
import { STRINGS_INJECTOR } from '../../app.config';
import { strings } from '../../strings';
describe('ContactList', () => {
let component: ContactList;
let fixture: ComponentFixture<ContactList>;
let contactService: jasmine.SpyObj<ContactService>;
beforeEach(async () => {
contactService = jasmine.createSpyObj(ContactService.name, ['getAll']);
await TestBed.configureTestingModule({
imports: [ContactList],
providers: [
{ provide: ContactService, useValue: contactService },
{ provide: STRINGS_INJECTOR, useValue: strings },
],
}).compileComponents();
contactService.getAll.and.returnValue(of([]));
fixture = TestBed.createComponent(ContactList);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,28 @@
import { Component, inject, OnInit } from '@angular/core';
import { STRINGS_INJECTOR } from '../../app.config';
import { UpperfirstPipe } from "../../pipes/upperfirst-pipe";
import { ContactSearchBar } from "../contact-search-bar/contact-search-bar";
import { ContactListTable } from "../contact-list-table/contact-list-table";
import { ContactService } from '../../pages/main/contact.service';
import { AsyncPipe } from '@angular/common';
import { Counter } from "../counter/counter";
import { ContactsFilterPipe } from "../../pipes/contacts-filter-pipe";
@Component({
selector: 'app-contact-list',
imports: [AsyncPipe, UpperfirstPipe, ContactSearchBar, ContactListTable, Counter, ContactsFilterPipe],
templateUrl: './contact-list.html',
styleUrl: './contact-list.scss',
})
export class ContactList implements OnInit{
private readonly contactService = inject(ContactService);
protected readonly strings = inject(STRINGS_INJECTOR);
protected contacts$ = this.contactService.contacts$;
protected filter = '';
ngOnInit(): void {
this.contactService.getAll().subscribe();
}
}