{"size": 876, "ext": "js", "max_stars_repo_path": "src/localStorage.js", "max_stars_repo_name": "mariobarrioss/todo-list", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/localStorage.js", "max_issues_repo_name": "mariobarrioss/todo-list", "max_issues_repo_issues_event_min_datetime": "2020-12-19T00:31:27.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T20:24:11.000Z", "max_forks_repo_path": "src/localStorage.js", "max_forks_repo_name": "mariobarrioss/todo-list", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 20.3720930233, "max_line_length": 105, "alphanum_fraction": 0.6929223744}
import Project from './project';

const projectList = localStorage.getItem('projects') ? JSON.parse(localStorage.getItem('projects')) : [];

const storeProjectList = () => {
  localStorage.setItem('projects', JSON.stringify(projectList));
};

const addProject = project => {
  projectList.push(project);
  storeProjectList();
};

const checkDefaultProject = () => {
  if (projectList.length === 0) {
    const defaultProject = new Project('default');
    addProject(defaultProject);
  }
};

checkDefaultProject();

const retrieveProjects = () => projectList;

const updateProject = (id, project) => {
  projectList.splice(id, 1, project);
  storeProjectList();
};

const deleteProject = (id) => {
  localStorage.clear();
  projectList.splice(id, 1);
  storeProjectList();
};

export {
  addProject,
  retrieveProjects,
  updateProject,
  deleteProject,
  storeProjectList,
};
