feat(ui): open last project

This commit is contained in:
Guillaume Chau
2018-04-17 02:13:36 +02:00
parent 9320f5fc7f
commit f79cb6e25a
4 changed files with 25 additions and 3 deletions
@@ -13,6 +13,8 @@ const cwd = require('./cwd')
const prompts = require('./prompts')
const folders = require('./folders')
const plugins = require('./plugins')
// Context
const getContext = require('../context')
const PROGRESS_ID = 'project-create'
@@ -295,7 +297,8 @@ async function open (id, context) {
}).value()
if (!project) {
throw new Error(`Project '${id}' not found`)
console.warn(`Project '${id}' not found`)
return null
}
currentProject = project
@@ -303,6 +306,9 @@ async function open (id, context) {
// Load plugins
plugins.list(project.path, context)
// Save for next time
context.db.set('config.lastOpenProject', id).write()
return project
}
@@ -329,6 +335,15 @@ function setFavorite ({ id, favorite }, context) {
return findOne(id, context)
}
// Open last project
{
const context = getContext(null)
const id = context.db.get('config.lastOpenProject').value()
if (id) {
open(id, context)
}
}
module.exports = {
list,
getCurrent,
@@ -1,9 +1,11 @@
const { db } = require('./utils/db')
const pubsub = require('./pubsub')
// Context passed to all resolvers (third argument)
// eslint-disable-next-line no-unused-vars
module.exports = req => {
return {
db
db,
pubsub
}
}
@@ -0,0 +1,4 @@
const { PubSub } = require('graphql-subscriptions')
const pubsub = new PubSub()
module.exports = pubsub
@@ -11,7 +11,8 @@ const db = new Lowdb(new FileSync(resolve(__dirname, '../../../live/db.json')))
db.defaults({
projects: [],
foldersFavorite: [],
tasks: []
tasks: [],
config: {}
}).write()
module.exports = {