This commit is contained in:
2026-08-27 19:59:17 +03:00
parent 139e898e35
commit 435ae2e594
21 changed files with 451 additions and 382 deletions
+59
View File
@@ -0,0 +1,59 @@
import { Component, computed, inject, signal } from '@angular/core';
import { TaskItem } from './task-item';
import { Task } from './task';
import { TaskService } from './task-service';
import { RouterLink } from '@angular/router';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'app-home-page',
imports: [TaskItem, RouterLink, FormsModule],
template: `
<section>
<a [routerLink]="['/new']">Добавить</a><br>
<input [(ngModel)]="searchInput" type="text" />
</section>
<section class="result">
@for (task of filteredTasks(); track $index) {
<app-task-item [task]="task" />
}
</section>
`,
styles: `
input {
outline: none;
padding: 5px;
}
button {
cursor: pointer;
padding: 5px;
}
.result {
margin-top: 20px;
}
`,
})
export class TaskList {
tasks: Task[] = [];
taskService: TaskService = inject(TaskService);
searchInput = signal('');
filteredTasks = computed<Task[]>(() => {
const s = this.searchInput();
if (s === '') return this.tasks;
return this.tasks.filter(
(task) =>
task.name.includes(s) ||
task.city.includes(s) ||
task.streetAddress.includes(s) ||
task.numberPhone.includes(s),
);
});
constructor() {
this.taskService.getAllTasks().then(tasks => {
this.tasks = tasks;
this.searchInput.update(_ => " ")
this.searchInput.update(_ => '');
});
}
}