Add localStorage for tasks.
All checks were successful
Deploying Website / build (push) Successful in 1m8s
All checks were successful
Deploying Website / build (push) Successful in 1m8s
This commit is contained in:
parent
dcae538e49
commit
697e95f700
@ -5,6 +5,14 @@ import {Injectable} from '@angular/core';
|
|||||||
export class TasksService {
|
export class TasksService {
|
||||||
private tasks: Task[] = [];
|
private tasks: Task[] = [];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
const tasks = localStorage.getItem('tasks');
|
||||||
|
|
||||||
|
if (tasks) {
|
||||||
|
this.tasks = JSON.parse(tasks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getUserTasks(userId: string) {
|
getUserTasks(userId: string) {
|
||||||
return this.tasks.filter((task) => task.userId === userId);
|
return this.tasks.filter((task) => task.userId === userId);
|
||||||
}
|
}
|
||||||
@ -20,9 +28,17 @@ export class TasksService {
|
|||||||
summary: taskData.summary,
|
summary: taskData.summary,
|
||||||
dueDate: taskData.date,
|
dueDate: taskData.date,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.saveTasks()
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTask(taskId: string) {
|
removeTask(taskId: string) {
|
||||||
this.tasks = this.tasks.filter((task) => task.id !== taskId);
|
this.tasks = this.tasks.filter((task) => task.id !== taskId);
|
||||||
|
|
||||||
|
this.saveTasks()
|
||||||
|
}
|
||||||
|
|
||||||
|
private saveTasks() {
|
||||||
|
localStorage.setItem('tasks', JSON.stringify(this.tasks));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user