Add functionalty to add task

This commit is contained in:
2025-05-18 16:15:34 +02:00
parent f72cc8a802
commit 61694e340f
8 changed files with 124 additions and 35 deletions

View File

@@ -6,11 +6,9 @@ const routes: Routes = [
{
path: '',
component: TasksPage,
children: [
{ path: 'add', loadChildren: () => import('../edit-task/edit-task.module').then(m => m.EditTaskPageModule) },
{ path: 'edit/:id', loadChildren: () => import('../edit-task/edit-task.module').then(m => m.EditTaskPageModule) }
]
}
},
{ path: 'add', loadChildren: () => import('../edit-task/edit-task.module').then(m => m.EditTaskPageModule) },
{ path: 'edit/:id', loadChildren: () => import('../edit-task/edit-task.module').then(m => m.EditTaskPageModule) }
];
@NgModule({

View File

@@ -1,24 +1,28 @@
<ion-header [translucent]="true" class="ion-no-border">
<ion-toolbar>
<ion-title>
Tasks
</ion-title>
<div class="toolbar">
<ion-title>
Tasks
</ion-title>
<button class="add-button" (click)="createTask()">Add task</button>
</div>
</ion-toolbar>
</ion-header>
<ion-content>
<div class="icon">
<mat-icon>filter_alt</mat-icon>
</div>
<div class="list">
<div class="task" *ngFor="let task of tasks">
<button>Done</button>
<div class="name">{{ task.name }}</div>
<div
class="reward"
[ngClass]="{ 'negative': task.reward < 0 }"
>{{ task.reward.toFixed(2) }} SP</div>
<div class="content">
<div class="icon">
<mat-icon>filter_alt</mat-icon>
</div>
<div class="list">
<div class="task" *ngFor="let task of tasks$ | async">
<button>Done</button>
<div class="name">{{ task.name }}</div>
<div
class="reward"
[ngClass]="{ 'negative': task.reward < 0 }"
>{{ task.reward.toFixed(2) }} SP</div>
</div>
</div>
</div>
<button (click)="createTask()">ADD</button>
</ion-content>

View File

@@ -1,3 +1,13 @@
.toolbar {
display: flex;
}
.content {
display: flex;
flex-direction: column;
height: 100%;
}
.icon {
padding: 5px;
display: flex;
@@ -44,4 +54,10 @@ button {
border-radius: 10px;
color: white;
background: var(--confirm-button-color);
}
.add-button {
background-color: var(--ion-color-primary);
margin-right: 15px;
width: 75px;
}

View File

@@ -1,34 +1,39 @@
import { Component, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { TaskService } from 'src/app/services/task.service';
import { Task } from 'src/app/models/task';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject } from 'rxjs';
import { ViewWillEnter } from '@ionic/angular';
@Component({
selector: 'app-tasks',
templateUrl: 'tasks.page.html',
styleUrls: ['tasks.page.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class TasksPage implements OnInit {
public tasks: Array<Task> = [];
export class TasksPage implements ViewWillEnter {
public tasks$: BehaviorSubject<Array<Task>> = new BehaviorSubject<Array<Task>>([]);
constructor(
private taskService: TaskService,
private router: Router,
private route: ActivatedRoute
) {}
) {
this.getTasks();
}
ngOnInit(): void {
ionViewWillEnter(): void {
this.getTasks();
}
getTasks() {
this.taskService.getTaskList().subscribe(tasks => {
this.tasks = tasks;
this.tasks$.next(tasks);
});
}
createTask() {
this.router.navigate(['edit', 1], { relativeTo: this.route });
this.router.navigate(['add'], { relativeTo: this.route });
}
}