
async function getProject ({commit, dispatch}, projectId) {
  const res = await dispatch('api', [`/project/${String(projectId).toLowerCase()}`]);
  if (res) {
    commit('setProjectName', res.name);
    commit('setProjectId', res.pid);
    commit('setProjectSchema', res.schema);
    const recentProjects = JSON.parse(localStorage.getItem("recentProjects") || "[]")
    recentProjects.unshift(res);
    localStorage.setItem("recentProjects", JSON.stringify(recentProjects.slice(0, 3)));
  } else {
    commit('setProjectName', null);
    commit('setProjectId', null);
    commit('setProjectSchema', null);
  }
}

export default { getProject };
