Add localStorage for tasks.
All checks were successful
Deploying Website / build (push) Successful in 1m8s

This commit is contained in:
Maxime Delporte 2025-04-27 08:29:57 -03:00
parent dcae538e49
commit 697e95f700

View File

@ -5,6 +5,14 @@ import {Injectable} from '@angular/core';
export class TasksService {
private tasks: Task[] = [];
constructor() {
const tasks = localStorage.getItem('tasks');
if (tasks) {
this.tasks = JSON.parse(tasks);
}
}
getUserTasks(userId: string) {
return this.tasks.filter((task) => task.userId === userId);
}
@ -20,9 +28,17 @@ export class TasksService {
summary: taskData.summary,
dueDate: taskData.date,
});
this.saveTasks()
}
removeTask(taskId: string) {
this.tasks = this.tasks.filter((task) => task.id !== taskId);
this.saveTasks()
}
private saveTasks() {
localStorage.setItem('tasks', JSON.stringify(this.tasks));
}
}