Add delete task functionality (#72)

closes #62

Reviewed-on: #72
This commit is contained in:
Huffle 2025-05-19 09:43:11 +02:00
parent 5bcbde46ea
commit 93ec3cbc19
5 changed files with 30 additions and 3 deletions

View File

@ -1,7 +1,14 @@
<ion-header [translucent]="true"> <ion-header [translucent]="true">
<ion-toolbar> <ion-toolbar>
<ion-title *ngIf="isAddMode">Create Task</ion-title> <div class="toolbar">
<ion-title *ngIf="!isAddMode">Edit Task</ion-title> <ion-title *ngIf="isAddMode">Create Task</ion-title>
<ion-title *ngIf="!isAddMode">Edit Task</ion-title>
<button
*ngIf="!isAddMode"
class="remove-button"
(click)="deleteTask()"
>Delete task</button>
</div>
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>

View File

@ -1,3 +1,14 @@
.toolbar {
display: flex;
}
.remove-button {
background-color: var(--ion-color-primary);
margin-right: 15px;
width: 85px;
margin-bottom: 0;
}
form { form {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View File

@ -72,4 +72,9 @@ export class EditTaskPage implements OnInit {
this.router.navigate(['/tabs/tasks']); this.router.navigate(['/tabs/tasks']);
} }
deleteTask() {
this.taskService.deleteTask(this.id);
this.router.navigate(['/tabs/tasks']);
}
} }

View File

@ -32,7 +32,7 @@ export class TasksPage implements ViewWillEnter {
this.taskService.getTaskList().subscribe(tasks => { this.taskService.getTaskList().subscribe(tasks => {
this.tasks$.next(tasks); this.tasks$.next(tasks);
}); });
}, 1) }, 10);
} }
createTask() { createTask() {

View File

@ -30,4 +30,8 @@ export class TaskService {
completeTask(id: number) { completeTask(id: number) {
this.http.post(`${this.url}/task/${id}/complete`, {}).subscribe(); this.http.post(`${this.url}/task/${id}/complete`, {}).subscribe();
} }
deleteTask(id: number) {
this.http.delete(`${this.url}/task/${id}`).subscribe();
}
} }