diff --git a/src/app/tasks/new-task/new-task.component.ts b/src/app/tasks/new-task/new-task.component.ts index cce685c..fbf5769 100644 --- a/src/app/tasks/new-task/new-task.component.ts +++ b/src/app/tasks/new-task/new-task.component.ts @@ -1,6 +1,7 @@ -import {Component, EventEmitter, Output} from '@angular/core'; +import {Component, EventEmitter, inject, Input, Output} from '@angular/core'; import {FormsModule} from '@angular/forms'; import {NewTaskData} from '../task/task.model'; +import {TasksService} from '../tasks.service'; @Component({ selector: 'app-new-task', @@ -11,22 +12,28 @@ import {NewTaskData} from '../task/task.model'; styleUrl: './new-task.component.css' }) export class NewTaskComponent { - @Output() cancel = new EventEmitter(); - @Output() add = new EventEmitter(); + @Input({required: true}) userId!: string; + @Output() close = new EventEmitter(); + enteredTitle = ''; enteredSummary = ''; enteredDate = ''; + tasksService = inject(TasksService); + onCancel() { - this.cancel.emit(); + this.close.emit(); } onSubmit() { - let taskContent: NewTaskData = { + let taskData: NewTaskData = { title: this.enteredTitle, summary: this.enteredSummary, date: this.enteredDate, }; - this.add.emit(taskContent); + + this.tasksService.addTaskFor(this.userId, taskData); + + this.close.emit() } } diff --git a/src/app/tasks/tasks.component.html b/src/app/tasks/tasks.component.html index 7a7c1ee..20e972e 100644 --- a/src/app/tasks/tasks.component.html +++ b/src/app/tasks/tasks.component.html @@ -1,7 +1,7 @@ @if (isAddingTask) { } diff --git a/src/app/tasks/tasks.component.ts b/src/app/tasks/tasks.component.ts index 721acef..4538cbd 100644 --- a/src/app/tasks/tasks.component.ts +++ b/src/app/tasks/tasks.component.ts @@ -29,12 +29,7 @@ export class TasksComponent { this.isAddingTask = true; } - onCancelAddTask() { + onCloseAddTask() { this.isAddingTask = false; } - - onAddTask(taskData: NewTaskData) { - this.tasksService.addTaskFor(this.user.id, taskData); - this.onCancelAddTask() - } }