mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-06-28 12:55:36 -04:00
feat: local storage added
This commit is contained in:
parent
5a9f303e80
commit
f18b11a22b
3 changed files with 46 additions and 6 deletions
|
@ -21,10 +21,17 @@ function createProject(name) {
|
|||
|
||||
class todoHandler {
|
||||
// Create default project during construction
|
||||
constructor() {
|
||||
this.projects = [new createProject('default')];
|
||||
constructor(projects=null) {
|
||||
if (projects) {
|
||||
this.projects = projects;
|
||||
} else {
|
||||
this.projects = [new createProject('default')];
|
||||
}
|
||||
}
|
||||
|
||||
getEverything() { return this.projects }
|
||||
|
||||
|
||||
getTodos() {
|
||||
return this.projects.map(item => item.todos);
|
||||
}
|
||||
|
@ -67,7 +74,15 @@ class todoHandler {
|
|||
return todoArr.find(todo => todo.title === title);
|
||||
}
|
||||
|
||||
addProject = name => this.projects.push(createProject(name));
|
||||
addProject(name) {
|
||||
let exists = this.projects.find(x => x.name === name);
|
||||
if (!exists) {
|
||||
this.projects.push(createProject(name));
|
||||
return
|
||||
}
|
||||
console.log(`Project ${name} already exists!`);
|
||||
|
||||
}
|
||||
|
||||
getProjects () {
|
||||
return this.projects.map(item => item.name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue